Skip to content

Library to run commands on generated code within a yeoman generator

Notifications You must be signed in to change notification settings

Eskalol/yo-inception

Repository files navigation

NPM version Build Status Greenkeeper badge codecov dependencies Status devDependencies Status

Imagine if you could run your generated tests within your yeoman generator tests, just as simple as dreaming within a dream... Lol

Install

$ npm install --save-dev yo-inception

or

$ yarn add --dev yo-inception

Examples

More examples coming soon...

Jest Example

describe('run generated tests', () => {
  let inception;

  beforeAll(done => {
    inception = new Inception(path.join(__dirname, 'tempDir'));
    inception.copyPackageJson(
      path.join(__dirname, '../path/to/generator/templates/_package.json'), {
        someAnswer: true
      }
    );
    return inception.npmInstall()
      .then(() => inception.runGen(path.join(__dirname, '../path/to/generator'), { someAnswer: true }))
      .then(() => done());
  });

  it('should pass', async () => {
      await expect(inception.runAsyncCommand('npm', ['run', 'test-pass'])).resolves.toBe(0);
  });

  afterAll(() => {
    inception.clean();
  });
});

Copy and process package.json into tempDir

const Inception = require('yo-inception');
const path = require('path');
const inception = new Inception(path.join(__dirname, 'tempDir');
inception.copyPackageJson(
  path.join(__dirname, '../path/to/generator/_package.json'), {
    someAnswer: true
  });

Install dependencies into tempDir (package.json required in tempDir)

const Inception = require('yo-inception');
const path = require('path');
const inception = new Inception(path.join(__dirname, 'tempDir');
// with npm
inception.npmInstall();
// or with yarn
inception.yarnInstall();

Run test command on generated code (node_modules needs to be present in tempDir)

const Inception = require('yo-inception');
const path = require('path');
const inception = new Inception(path.join(__dirname, 'tempDir');
inception.runGen(path.join(__dirname, '../path/to/gen'), { someAnswer: true })
  .then(() => inception.runAsyncCommand(['gulp'], ['test']));

Clean TempDir

const Inception = require('yo-inception');
const path = require('path');
const inception = new Inception(path.join(__dirname, 'tempDir');
inception.clean(); // removes tempDir

About

Library to run commands on generated code within a yeoman generator

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •