yeoman-test

NPM version NPM Test Integration Build Dependency Status Coverage percentage

Test utilities for Yeoman generators

Installation

$ npm install --save-dev yeoman-test

Install target environment and generator:

$ npm install --save-dev yeoman-generator@xxx yeoman-environment@xxx

Usage

Usage:

describe('generator test', () => {
  describe('test', () => {
    let runResult;
    beforeEach(async () => {
      runResult = await helpers
        .create(                   // instantiates RunContext
          'namespace',             // namespace or generator
          {},                      // test options
          {}                       // environment options
        )
        [.cd(dir)]                  // runs the test inside a non temporary dir
        [.doInDir(dir => {})        // prepares the test dir
        [.withGenerators([])]       // registers additional generators
        [.withLookups({})]          // runs Environment lookups
        [.withOptions({})]          // passes options to the generator
        [.withLocalConfig({})]      // sets the generator config as soon as it is instantiated
        [.withPrompts()]            // simulates the prompt answers
        [.build(runContext => {     // instantiates Environment/Generator
          [runContext.env...]       // does something with the environment
          [runContext.generator...] // does something with the generator
        })]
        .run();                     // runs the environment, promises a RunResult
      [result.create().run()] // instantiates a new RunContext at the same directory
    );
    afterEach(() => {
      if (runResult) {
        runResult.restore();
      }
    });
    it('runs correctly', () => {
      // runs assertions using mem-fs.
      [runResult.assertFile('file.txt');]
      [runResult.assertNoFile('file.txt');]
      [runResult.assertFileContent('file.txt', 'content');]
      [runResult.assertEqualsFileContent('file.txt', 'content');]
      [runResult.assertNoFileContent('file.txt', 'content');]
      [runResult.assertJsonFileContent('file.txt', {});]
      [runResult.assertNoJsonFileContent('file.txt', {});]
    });
  });
});

See our api documentation See our api documentation for yeoman-test 2.x.

See our documentation for yeoman-test 2.x.

License

MIT © The Yeoman Team