new RunContext(Generator, settingsopt, envOptionsopt) → {this}
This class provide a run context object to façade the complexity involved in setting up a generator for testing
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Generator |
String | function |
Namespace or generator constructor. If the later is provided, then namespace is assumed to be 'gen:test' in all cases |
||||||||||||||||||||||||||
settings |
Object | <optional> |
Properties
|
|||||||||||||||||||||||||
envOptions |
Object | <optional> |
Options to be passed to environment. |
Returns:
thisMethods
-
async() → {function}
-
Hold the execution until the returned callback is triggered
Returns:
function -Callback to notify the normal execution can resume
-
build() → {RunContext}
-
Build the generator and the environment.
-
catch() → {Promise}
-
Promise
.catch()
duck typingReturns:
Promise -
cd(dirPath) → {this}
-
Change directory without deleting directory content.
Parameters:
Name Type Description dirPath
String Directory path (relative to CWD). Prefer passing an absolute file path for predictable results
Returns:
this -run context instance
-
cleanTestDirectory()
-
Clean the directory used for tests inside inDir/inTmpDir
-
doInDir(cbopt) → {this}
-
Register an callback to prepare the destination folder.
Parameters:
Name Type Attributes Description cb
function <optional> callback who'll receive the folder path as argument
Returns:
this -run context instance
-
inDir(dirPath, cbopt) → {this}
-
Clean the provided directory, then change directory into it
Parameters:
Name Type Attributes Description dirPath
String Directory path (relative to CWD). Prefer passing an absolute file path for predictable results
cb
function <optional> callback who'll receive the folder path as argument
Returns:
this -run context instance
-
inTmpDir(cbopt) → {this}
-
Cleanup a temporary directy 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.
Parameters:
Name Type Attributes Description cb
function <optional> callback who'll receive the folder path as argument
Returns:
this -run context instance
-
run() → {Promise}
-
Run the generator on the environment and returns the promise.
Returns:
Promise -Promise
-
then() → {Promise}
-
Promise
.then()
duck typingReturns:
Promise -
toPromise() → {Promise}
-
Return a promise representing the generator run process
Returns:
Promise -Promise resolved on end or rejected on error
-
withArguments(args) → {this}
-
Provide arguments to the run context
Parameters:
Name Type Description args
String | Array command line arguments as Array or space separated string
Returns:
this -
withEnvironment(cbopt) → {this}
-
Create an environment
This method is called automatically when creating a RunContext. Only use it if you need to use the callback.
Parameters:
Name Type Attributes Description cb
function <optional> callback who'll receive the folder path as argument
Returns:
this -run context instance
-
withGenerators(dependencies) → {this}
-
Provide dependent generators
Parameters:
Name Type Description dependencies
Array paths to the generators dependencies
Returns:
thisExample
var angular = new RunContext('../../app'); angular.withGenerators([ '../../common', '../../controller', '../../main', [helpers.createDummyGenerator(), 'testacular:app'] ]); angular.on('end', function () { // assert something });
-
withLocalConfig(localConfig) → {this}
-
Mock the local configuration with the provided config
Parameters:
Name Type Description localConfig
Object should look just like if called config.getAll()
Returns:
this -
withLookups(lookupsopt) → {this}
-
Run lookup on the environment.
Parameters:
Name Type Attributes Description lookups
Object | Array <optional> lookup to run.
Returns:
this -run context instance.
-
withOptions(options) → {this}
-
Provide options to the run context
Parameters:
Name Type Description options
Object command line options (e.g.
--opt-one=foo
)Returns:
this -
withPrompts(answers) → {this}
-
Mock the prompt with dummy answers
Parameters:
Name Type Description answers
Object Answers to the prompt questions
Returns:
this