questions.on('ask', function(val, key, question, answers) { if (count < 5) { count++; bddStdin('\n'); } else { bddStdin('bar\n'); } });
"Check that generates a container properly": function (test) { var template_name = 'container'; test.expect(1); bddStdin('container-test\n', 'ssr\n', 'container-test\n', 'testTemplate\n', 'layouts\n', 'layouts\n', 'Personal\n', 'P\n' ); program.parse(['node', 'test', 'generate', template_name]); setTimeout(function () { dircompare .compare(path.join(__dirname, 'expected', 'container-test'), path.join(__dirname, 'generated', 'container-test'), dcOptions) .then(function (res) { test.equals(res.distinct, 0, 'Both containers have the same content.'); test.done(); }) .catch(function (error) { test.done(); }); }, timeout); },
"Check that generates an agnostic widget properly": function (test) { var template_name = 'agnosthic-widget'; test.expect(1); bddStdin('test\n', 'agnostic-widget\n', 'Agnostic Widget\n', '1.0.0\n', 'author@company.com\n', 'test\n', 'test\n', 'N\n', 'N\n', 'a\n' ); program.parse(['node', 'test', 'generate', template_name]); setTimeout(function () { dircompare .compare(path.join(__dirname, 'expected', 'agnostic-widget'), path.join(__dirname, 'generated', 'agnostic-widget'), dcOptions) .then(function (res) { test.equals(res.distinct, 0, 'Both agnostic widgets have the same content.'); test.done(); }) .catch(function (error) { test.done(); }); }, timeout); }
"Check that generates a template properly": function (test) { var template_name = 'template'; var expectedOutput = [ chalk.gray('Generating ' + template_name + ' on path: ' + process.cwd()) ]; test.expect(2); bddStdin('Test Template\n', 'testTemplate\n', 'Personal\n', 'P\n', 'N\n', 'N\n', 'a\n' ); program.parse(['node', 'test', 'generate', template_name]); expectedOutput.forEach(function (output, index) { test.equals(generatedOutput[index], output, 'Our command tool has found a valid template'); }); setTimeout(function () { dircompare .compare(path.join(__dirname, 'expected', 'test-template'), path.join(__dirname, 'generated', 'test-template'), dcOptions) .then(function (res) { test.equals(res.distinct, 0, 'Both templates have the same content.'); test.done(); }) .catch(function (error) { test.done(); }); }, timeout); },
it('returns a promise, resolved on yes', function () { bddStdin('yes\n') return confirm('is this ok?').catch(function () { la(false, 'invalid response, should be resolved on yes') }) })
it('should not overwrite points with n-response', function() { stdin('n'); return add(local, 'foo', ['./'], false, customConfig) .then(function(res) { expect(res.point).to.not.be.ok; }); });
it('should overwrite points with y-response', function() { stdin('y'); return add(local, 'foo', ['./'], false, customConfig) .then(function(res) { expect(res.point).to.equal('foo'); expect(res.path).to.equal(path.resolve(process.cwd())); }); });
it('should work with nested sub-generators', function(cb) { app .register('foo', generator) .register('bar', generator) .register('baz', generator); bddStdin('\n', '\n', '\n'); app.generate('foo.bar.baz', exists('.babelrc', cb)); });
it('default value is false', () => { bddStdin('\n') // note we don't actually enter anything return confirm({question: 'pass extra?', extra: 42, default: false}) .then(() => { la(false, 'should have picked default answer false') }, (value) => { la(value === 42, 'expected extra value on default answer false', value) }) })
it('should skip questions when options.skip is true', function(cb) { questions.set('foo', {skip: true}); bddStdin('bar\n'); questions.ask('foo', function(err, answers) { if (err) return cb(err); var question = questions.get('foo'); assert.equal(question.skipped, true); assert.equal(typeof answers.foo, 'undefined'); cb(); }); });
it('should ask a question', function(cb) { var intercepted = interception('foo'); questions.set('foo'); bddStdin('bar\n'); questions.ask('foo', function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'bar'); intercepted(); cb(); }); });
questions.ask('foo', function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'bar'); bddStdin('qux\n'); questions.ask('foo', {force: true}, function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'qux'); intercepted(); cb(); }); });
createConfig(boilerplateFolderPath, () => { const ugenConfigPath = path.join(process.cwd(), 'ugen.config.js') const config = require(ugenConfigPath) const expectedAnswers = { ENV_HOME: 'AppHomeDir' } bddStdin('AppHomeDir\n') buildApp(config).then((answers) => { expect(answers).to.be.deep.equal(expectedAnswers) fs.removeSync(testFolderPath) done() }).catch((err) => {console.log(`Test error ${err}`)}) process.chdir(currentCwd) })
it('should not remove points with n-response', function() { expect(store(local).get('foo')).to.not.be.ok; localStore.set('foo', './test'); expect(store(local).get('foo')).to.be.ok; stdin('n'); return remove(local, 'foo', false, customConfig) .then(function(res) { expect(store(local).get('foo')).to.be.ok; expect(res).to.be.false; }); });
it('should generate `test` env when defined explicitly', function(cb) { bddStdin('\n', '\n', bddStdin.keys.down, bddStdin.keys.down, bddStdin.keys.down, ' ', '\n', '\n'); app.generate( 'babelrc', existscontains( '.babelrc', function(json) { return json.hasOwnProperty('env') && json.env.hasOwnProperty('test'); }, cb ) ); });
it('should generate `presets` when defined explicitly', function(cb) { bddStdin('\n', ' ', '\n', '\n'); app.generate( 'babelrc', existscontains( '.babelrc', function(json) { return json.presets.indexOf('es2015') !== -1 && json.presets.indexOf('es2016') !== -1 && json.presets.indexOf('react') !== -1; }, cb ) ); });
it('rejected on no', function () { bddStdin('no\n') var rejected return confirm('is this ok?') .then( function () { la(false, 'invalid response, should be rejected on no') }, function () { rejected = true } ) .then(function () { la(rejected, 'response was never rejected') }) })
it('should force all questions to be asked', function(cb) { // var unhook = interception(/Name|Description/); app.question('name', {message: 'Name?'}); app.question('desc', {message: 'Description?'}); bddStdin('Brian Woodward', '\n', 'Foo', '\n'); app.ask({force: true}, function(err, answers) { if (err) { cb(err); return; } assert.deepEqual(answers, {name: 'Brian Woodward', desc: 'Foo'}); // unhook(); cb(); }); });
it('should not ask the same question more than once', function(cb) { var intercepted = interception('foo'); questions.set('foo'); bddStdin('bar\n'); questions.ask('foo', function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'bar'); bddStdin('qux\n'); questions.ask('foo', function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'bar'); intercepted(); cb(); }); }); });
it('should always ask the question when force is true', function(cb) { var intercepted = interception('foo'); questions.set('foo'); bddStdin('bar\n'); questions.ask('foo', function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'bar'); bddStdin('qux\n'); questions.ask('foo', {force: true}, function(err, answers) { if (err) return cb(err); assert.equal(answers.foo, 'qux'); intercepted(); cb(); }); }); });
"Check that generates a lp-module properly": function (test) { var template_name = 'lp-module'; test.expect(1); bddStdin('module-launchpad\n', 'Module Launchpad Architecture\n', '1.0.0\n', 'author@company.com\n', 'Y\n', 'N\n', 'a\n' ); program.parse(['node', 'test', 'generate', template_name]); setTimeout(function () { dircompare .compare(path.join(__dirname, 'expected', 'module-launchpad'), path.join(__dirname, 'generated', 'module-launchpad'), dcOptions) .then(function (res) { test.equals(res.distinct, 0, 'Both projects have the same content.'); test.done(); }) .catch(function (error) { test.done(); }); }, timeout); },
it('should run the `default` task when defined explicitly', function(cb) { bddStdin('\n', '\n', '\n'); app.generate('babelrc:default', exists('.babelrc', cb)); });
it('passes extra value', () => { bddStdin('yes\n') return confirm('pass extra?', 42).then(value => { la(value === 42, 'expected extra value', value) }) })
it('default value is true', () => { bddStdin('\n') // note we don't actually enter anything return confirm({question: 'pass extra?', extra: 42}).then(value => { la(value === 42, 'expected extra value', value) }) })
it('passes extra value', () => { bddStdin('yes\n') return confirm({question: 'pass extra?', extra: 42}).then(value => { la(value === 42, 'expected extra value', value) }) })
beforeEach(function() { app.use(generator); bddStdin('\n', '\n', '\n'); });
it('should run the default task on the generator', function(cb) { bddStdin('\n', '\n', '\n'); app.generate('babelrc', exists('.babelrc', cb)); });
it('should run the `babelrc` task', function(cb) { bddStdin('\n', '\n', '\n'); app.generate('babelrc:babelrc', exists('.babelrc', cb)); });
app.on('ask', function() { bddStdin('foo', '\n'); });
beforeEach(function() { app.register('foo', function(foo) { foo.register('babelrc', generator); }); bddStdin('\n', '\n', '\n'); });