yo-inception
v0.3.2
Published
Library to run commands on generated code within yeoman generator tests
Downloads
6
Maintainers
Readme
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