RunContext(Generator, settingsopt, envOptionsopt) → {this}

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
Name Type Attributes Default Description
tmpdir Boolean <optional>

Automatically run this generator in a tmp dir

resolved String <optional>

File path to the generator (only used if Generator is a constructor)

namespace String <optional>
'gen:test'

Namespace (only used if Generator is a constructor)

runEnvironment String <optional>
false

Require the run context to call run.

envOptions Object <optional>

Options to be passed to environment.

Returns:
this

Methods

async() → {function}

Hold the execution until the returned callback is triggered

Returns:
function -

Callback to notify the normal execution can resume

build() → {RunContext|false}

Build the generator and the environment.

Returns:
RunContext | false -

this

catch() → {Promise}

Promise .catch() duck typing

Returns:
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(force)

Clean the directory used for tests inside inDir/inTmpDir

Parameters:
Name Type Description
force Boolean

force directory cleanup for not tmpdir

cleanup(force)

Clean the directory used for tests inside inDir/inTmpDir

Parameters:
Name Type Description
force Boolean

force directory cleanup for not tmpdir

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}

Creates 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.

Parameters:
Name Type Attributes Description
cb function <optional>

callback who'll receive the folder path as argument

Returns:
this -

run context instance

restore() → {this}

Restore cwd to initial cwd.

Returns:
this -

run context instance

run() → {Promise.<RunResult>}

Run the generator on the environment and promises a RunResult instance.

Returns:
Promise.<RunResult> -

Promise a RunResult instance.

then() → {Promise}

Promise .then() duck typing

Returns:
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:
this
Example
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.

withMockedGenerators(namespaces) → {this}

Create mocked generators

Parameters:
Name Type Description
namespaces Array

namespaces of mocked generators

Returns:
this
Example
var angular = helpers
  .create('../../app')
  .withMockedGenerators([
    'foo:app',
    'foo:bar',
  ])
  .run()
  .then(runResult => assert(runResult
    .mockedGenerators['foo:app']
 .calledOnce));

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, optionsopt) → {this}

Mock the prompt with dummy answers

Parameters:
Name Type Attributes Description
answers Object

Answers to the prompt questions

options Object | function <optional>

Options or callback.

Properties
Name Type Attributes Description
callback function <optional>

Callback.

throwOnMissingAnswer Boolean <optional>

Throw if a answer is missing.

Returns:
this