8.2.0 • Published 5 months ago

yeoman-test v8.2.0

Weekly downloads
57,279
License
MIT
Repository
github
Last release
5 months ago

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:

import helpers from 'yeoman-test';

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
        [.onTargetDirectory(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
        [.withAnswers()]            // simulates the prompt answers
        [.withMockedGenerators(['namespace', ...])]      // adds a mocked generator to the namespaces
        [.withFiles({
          'foo.txt': 'bar',
          'test.json', { content: true },
        })]                         // add files to mem-fs
        [.withYoRc({ 'generator-foo': { bar: {} } })]    // add config to .yo-rc.json
        [.withYoRcConfig('generator-foo.bar', { : {} })] // same as above
        [.commitFiles()]            // commit mem-fs files to disk
        [.onGenerator(gen => {})]   // do something with the generator
        [.onEnvironment(env => {})] // do something with the environment
        [.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) {
        // Optional if context is executed at a temporary folder
        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', {});]
    });
  });
});

Convenience last RunResult instance:

import helpers, { result } from 'yeoman-test';

describe('generator test', () => {
  before(() => helpers.run('namespace'));
  it('test', () => {
    result.assert...;
  });
});

Generator compose:

import assert from 'assert';
import helpers, { result } from 'yeoman-test';

describe('my-gen', () => {
  before(() => helpers.run('my-gen').withMockedGenerator(['composed-gen']));
  it('should compose with composed-gen', () => {
    assert(result.mockedGenerators['composed-gen'].calledOnce);
  });
});

Generic test folder:

import helpers, { result } from 'yeoman-test';

describe('generic test', () => {
  before(() => helpers.prepareTemporaryDir());
  it('test', () => {
    result.assert...;
  });
});

See our api documentation for latest yeoman-test release.

See our api documentation for yeoman-test 5.0.1. Use 5.x for yeoman-environment 2.x support.

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

See our documentation for yeoman-test 2.x.

License

MIT © The Yeoman Team

generator-metalsmith-project@microsoft/generator-microsoft-bot-multibotgenerator-empty-botgenerator-conversational-coregenerator-conversational-core2generator-p2h@standardlabs-test/generator-microsoft-bot-conversational-core@standardlabs-test/generator-microsoft-bot-emptygenerator-xhgenerator-limelight@everything-registry/sub-chunk-3202@wingsuit-designsystem/cli@wingsuit-designsystem/generator-new-component@winkler13/generator-next-typescript-scss@winkler13/generator-rollup-typescript-scss@alchmy/generator-alchmycommon-codegen-tests@billogram/generator-app@bolt/generator-boltreact-native-fireyeoman-test-helpersyeoman-generator-aheadyo-unityo-inceptionsf-tooling1000-packages@gnodi/generator-lib@microsoft/generator-microsoft-bot-calendar@microsoft/generator-microsoft-bot-calendar-assistant@microsoft/generator-microsoft-bot-conversational-core@microsoft/generator-microsoft-bot-empty@microsoft/generator-bot-assistant-core@microsoft/generator-bot-calendar@microsoft/generator-bot-conversational-core@microsoft/generator-bot-core-assistant@microsoft/generator-bot-core-language@microsoft/generator-bot-core-qna@microsoft/generator-bot-empty@microsoft/generator-bot-enterprise-assistant@microsoft/generator-bot-enterprise-calendar@microsoft/generator-bot-enterprise-people@microsoft/generator-bot-people@microsoft/generator-bot-qna-makergenerator-trailpackgenerator-treefroggenerator-tradgenerator-yyipgenerator-zengenerator-liveblog-themegenerator-lean-jsxgenerator-naujsgenerator-new-componentgenerator-babel7-with-mochagenerator-ddiygenerator-czdockergenerator-dgp-api-aspnetcoregenerator-patrick-bot-conversational-coregenerator-patrick-bot-emptygenerator-lambda-functiongenerator-mpnodemodulegenerator-angular-gulp-browserifygenerator-angular-jasmine-squelettegenerator-dotnetsolutiongenerator-karma-requiregenerator-joi-swaggergenerator-meshblu-core-taskgenerator-meshblu-core-task-check-whitelistgenerator-nodejsgenerator-abvcssgenerator-abvcss-reactgenerator-camel-projectgenerator-angular-devstackgenerator-bot-core-assistant-pavolum-1generator-brei-appgenerator-brei-nextgenerator-boltgenerator-blueriq-themegenerator-ethereum-clientgenerator-es6-graphqlgenerator-gulp-plugingenerator-chrome-extension-kickstartgenerator-chrome-extension-kickstart-typescriptgenerator-chrome-extension-kickstart-typescript-preactgenerator-angular2-application-scaffoldergenerator-appkitgenerator-composer-ionicgenerator-condensationgenerator-googilyboogily-projectgenerator-atomicgenerator-eipgenerator-backstagegenerator-drupal-modulegenerator-durandal2generator-fragmentgenerator-foregroundgenerator-alchmygenerator-aip-science-appgenerator-blip-plugingenerator-cucumber-capybaragenerator-create-lean-jsx-app
8.1.0

6 months ago

8.1.1

5 months ago

8.2.0

5 months ago

8.0.0-rc.1

10 months ago

8.0.0-rc.2

6 months ago

8.0.0

6 months ago

8.1.0-beta.0

6 months ago

8.0.0-alpha.0

11 months ago

8.0.0-alpha.3

11 months ago

8.0.0-alpha.1

11 months ago

8.0.0-alpha.2

11 months ago

7.3.0

1 year ago

8.0.0-beta.6

10 months ago

8.0.0-beta.5

11 months ago

8.0.0-beta.7

10 months ago

8.0.0-beta.0

11 months ago

8.0.0-beta.2

11 months ago

8.0.0-beta.1

11 months ago

8.0.0-beta.4

11 months ago

8.0.0-beta.3

11 months ago

8.0.0-rc.0

10 months ago

7.4.0

1 year ago

7.0.0

1 year ago

7.2.0

1 year ago

7.1.0

1 year ago

6.3.0

2 years ago

6.2.0

3 years ago

6.1.0

3 years ago

6.0.0

3 years ago

5.1.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.1

3 years ago

4.0.2

3 years ago

4.0.0

3 years ago

4.0.0-beta.0

3 years ago

3.0.0

4 years ago

2.7.0

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.0

4 years ago

1.9.1

6 years ago

2.0.0

6 years ago

1.9.0

6 years ago

1.8.0

6 years ago

1.7.2

6 years ago

1.7.1

6 years ago

1.7.0

7 years ago

1.6.0

7 years ago

1.5.1

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago