@types/yeoman-test
- Version 4.0.6
- Published
- 19.1 kB
- 4 dependencies
- MIT license
Install
npm i @types/yeoman-test
yarn add @types/yeoman-test
pnpm add @types/yeoman-test
Overview
TypeScript definitions for yeoman-test
Index
Functions
Interfaces
Type Aliases
Functions
function create
create: ( GeneratorOrNamespace: string | Constructor<Generator>, settings?: RunContextSettings, envOptions?: Environment.Options) => RunContext;
Create a RunContext
Parameter GeneratorOrNamespace
Generator constructor or namespace
Parameter settings
Generator settings
Parameter envOptions
Environment options
function createDummyGenerator
createDummyGenerator: () => Generator;
Create a simple, dummy generator
function createGenerator
createGenerator: ( name: string, dependencies: Dependency[], args?: string | string[], options?: Dictionary<any>) => Generator;
Create a generator, using the given dependencies and controller arguments Dependencies can be path (autodiscovery) or an array [, ]
Parameter name
the name of the generator
Parameter dependencies
paths to the generators dependencies
Parameter args
arguments to the generator; if String, will be split on spaces to create an Array
Parameter options
configuration for the generator
Example 1
var deps = ['../../app', '../../common', '../../controller', '../../main', [createDummyGenerator(), 'testacular:app'] ]; var angular = createGenerator('angular:app', deps);
function gruntfile
gruntfile: (options: Dictionary<any>, done?: (...args: any[]) => void) => void;
Generates a new Gruntfile.js in the current working directory based on options hash passed in.
Parameter options
Grunt configuration
Parameter done
callback to call on completion
function mockLocalConfig
mockLocalConfig: (generator: Generator, localConfig: Dictionary<any>) => void;
Provide mocked values to the config
Parameter generator
a Yeoman generator
Parameter localConfig
localConfig - should look just like if called config.getAll()
function mockPrompt
mockPrompt: (generator: Generator, answers: Generator.Answers) => void;
Answer prompt questions for the passed-in generator
Parameter generator
a Yeoman generator
Parameter answers
an object where keys are the generators prompt names and values are the answers to the prompt questions
Example 1
mockPrompt(angular, {'bootstrap': 'Y', 'compassBoostrap': 'Y'});
function registerDependencies
registerDependencies: (env: Env, dependencies: Dependency[]) => void;
Register a list of dependent generators into the provided env. Dependencies can be path (autodiscovery) or an array [, ]
Parameter dependencies
paths to the generators dependencies
function restorePrompt
restorePrompt: (generator: Generator) => void;
Restore defaults prompts on a generator.
function run
run: ( GeneratorOrNamespace: string | Constructor<Generator>, settings?: RunContextSettings) => RunContext;
Run the provided Generator
Parameter GeneratorOrNamespace
Generator constructor or namespace
function setUpTestDirectory
setUpTestDirectory: (dir: string) => (done: (...args: any[]) => void) => void;
Create a function that will clean up the test directory, cd into it, and create a dummy gruntfile inside. Intended for use as a callback for the mocha
before
hook.Parameter dir
path to the test directory
Returns
mocha callback
function testDirectory
testDirectory: (dir: string, cb?: (error?: any) => void) => void;
Clean-up the test directory and cd into it. Call given callback after entering the test directory.
Parameter dir
path to the test directory
Parameter cb
callback executed after setting working directory to dir
Example 1
testDirectory(path.join(__dirname, './temp'), function () { fs.writeFileSync('testfile', 'Roses are red.'); });
Interfaces
interface Constructor
interface Constructor<T> {}
Represents a constructor.
construct signature
new (...args: any[]): T;
interface Dictionary
interface Dictionary<T> {}
Represents a dictionary.
index signature
[key: string]: T;
interface Env
interface Env extends Environment {}
Represents an environment for running yeoman-generators.
property queues
queues: string[];
interface RunContext
interface RunContext extends RunContextConstructor, EventEmitter, Promise<RunResult> {}
Represents the context of a running generator.
property answers
answers: Generator.Answers;
The mocked
inquirer
-answers.
property args
args: string[];
The arguments that are passed to the generator.
property dependencies
dependencies: Dependency[];
A set of generators this generator depends on.
property inDirSet
inDirSet: boolean;
A value indicating whether a current directory has been set.
property localConfig
localConfig: {};
The mocked configuration.
property mockedGenerators
mockedGenerators: Dictionary<Generator>;
A set of mocked generators.
property options
options: {};
The options that are passed to the generator.
property ran
ran: boolean;
A value indicating whether the generator ran through.
method async
async: () => () => void;
Hold the execution until the returned callback is triggered Callback to notify the normal execution can resume
method cd
cd: (dirPath: string) => this;
Change directory without deleting directory content.
Parameter dirPath
Directory path (relative to CWD). Prefer passing an absolute file path for predictable results run context instance
method cleanTestDirectory
cleanTestDirectory: () => void;
Clean the directory used for tests inside inDir/inTmpDir
method doInDir
doInDir: (cb: (folderPath: string) => void) => this;
Register an callback to prepare the destination folder.
Parameter cb
callback who'll receive the folder path as argument this - run context instance
method inDir
inDir: (dirPath: string, cb?: (folderPath: string) => void) => this;
Clean the provided directory, then change directory into it
Parameter dirPath
Directory path (relative to CWD). Prefer passing an absolute file path for predictable results
Parameter cb
callback who'll receive the folder path as argument run context instance
method inTmpDir
inTmpDir: (cb: (folderPath: string) => void) => this;
Cleanup a temporary directory and change the CWD into it
This method is called automatically when creating a RunContext. Only use it if you need to use the callback.
Parameter cb
callback who'll receive the folder path as argument this - run context instance
method run
run: () => Promise<RunResult>;
Run the generator on the environment and returns the promise. Promise
method toPromise
toPromise: () => Promise<RunResult>;
Return a promise representing the generator run process Promise resolved on end or rejected on error
method withArguments
withArguments: (args: string | string[]) => this;
Provide arguments to the run context
Parameter args
command line arguments as Array or space separated string
method withGenerators
withGenerators: (dependencies: Dependency[]) => this;
Provide dependent generators
Parameter dependencies
paths to the generators dependencies
Example 1
var angular = new RunContext('../../app'); angular.withGenerators([ '../../common', '../../controller', '../../main', [helpers.createDummyGenerator(), 'testacular:app'] ]); angular.on('end', function () { // assert something });
method withLocalConfig
withLocalConfig: (localConfig: Dictionary<any>) => this;
Mock the local configuration with the provided config
Parameter localConfig
should look just like if called config.getAll()
method withMockedGenerators
withMockedGenerators: (namespaces: string[]) => this;
Creates mocked generators.
Parameter namespaces
The namespaces of the mocked generators.
method withOptions
withOptions: (options: Dictionary<any>) => this;
Provide options to the run context
Parameter options
command line options (e.g.
--opt-one=foo
)
method withPrompts
withPrompts: (answers: Generator.Answers) => this;
Mock the prompt with dummy answers
Parameter answers
Answers to the prompt questions
interface RunContextConstructor
interface RunContextConstructor {}
Provides the functionality to initialize new
RunContext
s.
construct signature
new ( Generator: string | Constructor<Generator>, settings?: RunContextSettings): RunContext;
This class provide a run context object to façade the complexity involved in setting up a generator for testing
Parameter Generator
Namespace or generator constructor. If the later is provided, then namespace is assumed to be 'gen:test' in all cases
interface RunContextSettings
interface RunContextSettings {}
Provides settings for creating a
RunContext
.
property namespace
namespace?: string | undefined;
Namespace (only used if Generator is a constructor) 'gen:test'
property resolved
resolved?: string | undefined;
File path to the generator (only used if Generator is a constructor)
property tmpdir
tmpdir?: boolean | undefined;
Automatically run this generator in a tmp dir true
interface RunResult
interface RunResult extends RunResultOptions {}
property options
options: RunResultOptions;
The options of this result.
method assertEqualsFileContent
assertEqualsFileContent: { (file: string, expectedContent: string): void; (pairs: [string, string][]): void;};
Assert that a file's content is the same as the given string
Parameter file
path to a file
Parameter expectedContent
the expected content of the file
Parameter pairs
an array of arrays, where each subarray is a [String, String] pair
Example 1
result.assertEqualsFileContent( 'data.js', 'const greeting = "Hello";\nexport default { greeting }' );
Assert that each file in an array of file-string pairs equals its corresponding string
Example 2
result.assertEqualsFileContent([ ['data.js', 'const greeting = "Hello";\nexport default { greeting }'], ['user.js', 'export default {\n name: 'Coleman',\n age: 0\n}'] ]);
method assertFile
assertFile: (path: string | string[]) => void;
Assert that a file exists
Parameter path
path to a file
Parameter paths
an array of paths to files
Example 1
result.assertFile('templates/user.hbs');
Assert that each files in the array exists
Example 2
result.assertFile(['templates/user.hbs', 'templates/user/edit.hbs']);
method assertFileContent
assertFileContent: { (file: string, reg: string | RegExp): void; (pairs: [string, string | RegExp][]): void;};
Assert that a file's content matches a regex or string
Parameter file
path to a file
Parameter reg
regex / string that will be used to search the file
Parameter pairs
an array of arrays, where each subarray is a [String, RegExp] pair
Example 1
result.assertFileContent('models/user.js', /App.User = DS.Model.extend/); result.assertFileContent('models/user.js', 'App.User = DS.Model.extend');
Assert that each file in an array of file-regex pairs matches its corresponding regex
Example 2
var arg = [ [ 'models/user.js', /App.User = DS.Model.extend/ ], [ 'controllers/user.js', /App.UserController = Ember.ObjectController.extend/ ] ] result.assertFileContent(arg);
method assertJsonFileContent
assertJsonFileContent: ( filename: string, content: { [key: string]: any }) => void;
Assert a JSON file contains the provided keys
Parameter filename
Parameter content
An object of key/values the file should contains
method assertNoFile
assertNoFile: (file: string | string[]) => void;
Assert that a file doesn't exist
Parameter file
path to a file
Parameter pairs
an array of paths to files
Example 1
result.assertNoFile('templates/user.hbs');
Assert that each of an array of files doesn't exist
Example 2
result.assertNoFile(['templates/user.hbs', 'templates/user/edit.hbs']);
method assertNoFileContent
assertNoFileContent: { (file: string, reg: RegExp | string): void; (pairs: [string, string | RegExp][]): void;};
Assert that a file's content does not match a regex / string
Parameter file
path to a file
Parameter reg
regex / string that will be used to search the file
Parameter pairs
an array of arrays, where each subarray is a [String, RegExp] pair var arg = [ [ 'models/user.js', /App.User \ DS.Model.extend/ ], [ 'controllers/user.js', /App.UserController = Ember.ObjectController.extend/ ] ] result.assertNoFileContent(arg);
Example 1
result.assertNoFileContent('models/user.js', /App.User = DS.Model.extend/); result.assertNoFileContent('models/user.js', 'App.User = DS.Model.extend');
Assert that each file in an array of file-regex pairs does not match its corresponding regex
method assertNoJsonFileContent
assertNoJsonFileContent: ( filename: string, content: { [key: string]: any }) => void;
Assert a JSON file does not contain the provided keys
Parameter filename
Parameter content
An object of key/values the file should not contain
method assertNoObjectContent
assertNoObjectContent: (obj: object, content: { [key: string]: any }) => void;
Assert an object does not contain the provided keys
Parameter obj
Object that should not match the given pattern
Parameter content
An object of key/values the object should not contain
method assertObjectContent
assertObjectContent: (obj: object, content: { [key: string]: any }) => void;
Assert an object contains the provided keys
Parameter obj
Object that should match the given pattern
Parameter content
An object of key/values the object should contains
method assertTextEqual
assertTextEqual: (value: string, expected: string) => void;
Assert that two strings are equal after standardization of newlines
Parameter value
a string
Parameter expected
the expected value of the string
Example 1
result.assertTextEqual('I have a yellow cat', 'I have a yellow cat');
method dumpFilenames
dumpFilenames: () => void;
Dumps the name of each file to the console.
method dumpFiles
dumpFiles: (...files: string[]) => void;
Either dumps the contents of the specified files or the name and the contents of each file to the console.
method restore
restore: () => this;
Reverts to old cwd.
Returns
this
interface RunResultOptions
interface RunResultOptions {}
Provides options for
RunResult
s.
property cwd
cwd: string;
The working directory after running the generator.
property env
env: Environment;
The environment of the generator.
property fs
fs: Editor;
The file-system editor of the generator.
property memFs
memFs: Store;
The file-system of the generator.
property mockedGenerators
mockedGenerators: Dictionary<Generator>;
The mocked generators of the context.
property oldCwd
oldCwd: string;
The working directory before on running the generator.
Type Aliases
type Dependency
type Dependency = string | [Generator, string];
Dependencies can be path (autodiscovery) or an array [, ]
Package Files (1)
Dependencies (4)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/yeoman-test
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/yeoman-test)
- HTML<a href="https://www.jsdocs.io/package/@types/yeoman-test"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4726 ms. - Missing or incorrect documentation? Open an issue for this package.