@minar-kotonoha/yeoman-test

2.7.1 • Public • Published

yeoman-test

NPM version NPM Test Integration Build Dependency Status Coverage percentage

Test utilities for Yeoman generators

Installation

$ npm install --save-dev yeoman-test

Usage

Usage:

describe('generator test', () => {
  let mockedCreateEnv;
  before(() => {
   [mockedCreateEnv = sinon
        .stub(helpers, 'createEnv')
        .returns(Environment.createEnv);] // uses the dependent Environment version or a custom builder
  });
  after(() => {
    [mockedCreateEnv.restore();] // switch cwd back to the pre-build cwd
    [mockedCreateEnv.cleanup();] // switch cwd back to the pre-build cwd and delete the test directory
  });
  describe('test', () => {
    let runResult;
    beforeEach(() => 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
      .then(result => {
        runResult = result;
        [result.create().run()] // instantiates a new RunContext at the same directory
      });
    );
    afterEach(() => {
      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 documentation for yeoman-test 2.x.

License

MIT © The Yeoman Team

Readme

Keywords

Package Sidebar

Install

npm i @minar-kotonoha/yeoman-test

Weekly Downloads

0

Version

2.7.1

License

MIT

Unpacked Size

39 kB

Total Files

7

Last publish

Collaborators

  • chengzhuo5