yeoman-test
Test utilities for Yeoman generators
Last updated 4 years ago by mshima .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install yeoman-test 
SYNC missed versions from official npm registry.

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 using the convenience last RunResult instance:

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

describe('generator test', () => {
  describe('test', () => {
    beforeEach(async () => {
      await helpers
        .run(                   // 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

      [await result.create('another-generator').run();] // instantiates a new RunContext at the same directory
    );

    it('runs correctly', () => {
      // runs assertions using mem-fs.
      [result.assertFile('file.txt');]
      [result.assertNoFile('file.txt');]
      [result.assertFileContent('file.txt', 'content');]
      [result.assertEqualsFileContent('file.txt', 'content');]
      [result.assertNoFileContent('file.txt', 'content');]
      [result.assertJsonFileContent('file.txt', {});]
      [result.assertNoJsonFileContent('file.txt', {});]
    });
  });
});

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

Current Tags

  • 8.3.0                                ...           latest (8 months ago)
  • 8.1.0-beta.0                                ...           next (a year ago)
  • 4.0.0-beta.0                                ...           next-4 (4 years ago)

60 Versions

  • 8.3.0                                ...           8 months ago
  • 8.2.0                                ...           a year ago
  • 8.1.1                                ...           a year ago
  • 8.1.0                                ...           a year ago
  • 8.1.0-beta.0                                ...           a year ago
  • 8.0.0                                ...           a year ago
  • 8.0.0-rc.2                                ...           a year ago
  • 8.0.0-rc.1                                ...           2 years ago
  • 8.0.0-rc.0                                ...           2 years ago
  • 8.0.0-beta.7                                ...           2 years ago
  • 8.0.0-beta.6                                ...           2 years ago
  • 8.0.0-beta.5                                ...           2 years ago
  • 8.0.0-beta.4                                ...           2 years ago
  • 8.0.0-beta.3                                ...           2 years ago
  • 8.0.0-beta.2                                ...           2 years ago
  • 8.0.0-beta.1                                ...           2 years ago
  • 8.0.0-beta.0                                ...           2 years ago
  • 8.0.0-alpha.3                                ...           2 years ago
  • 8.0.0-alpha.2                                ...           2 years ago
  • 8.0.0-alpha.1                                ...           2 years ago
  • 8.0.0-alpha.0                                ...           2 years ago
  • 7.4.0                                ...           2 years ago
  • 7.3.0                                ...           2 years ago
  • 7.2.0                                ...           2 years ago
  • 7.1.0                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 6.3.0                                ...           3 years ago
  • 6.2.0                                ...           3 years ago
  • 6.1.0                                ...           4 years ago
  • 6.0.0                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.1                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.0.2                                ...           4 years ago
  • 4.0.1                                ...           4 years ago
  • 4.0.0                                ...           4 years ago
  • 4.0.0-beta.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.7.0                                ...           4 years ago
  • 2.6.0                                ...           5 years ago
  • 2.5.0                                ...           5 years ago
  • 2.4.1                                ...           5 years ago
  • 2.4.0                                ...           5 years ago
  • 2.3.0                                ...           5 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.0                                ...           5 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                                ...           7 years ago
  • 1.7.1                                ...           7 years ago
  • 1.7.0                                ...           7 years ago
  • 1.6.0                                ...           8 years ago
  • 1.5.1                                ...           8 years ago
  • 1.5.0                                ...           8 years ago
  • 1.4.0                                ...           9 years ago
  • 1.3.0                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.0                                ...           9 years ago
Downloads
Total 40
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (12)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE