我需要一些提示来编写脚本来回答yeoman生成器的提示。如何以编程方式调用yeoman生成器?
这是背景。我使用yeoman的发电机发电机创建了我自己的发电机。我添加了一些提示。为了现在和将来的开发过程中测试模板项目,我需要生成一个示例项目并测试不断发展的模板。因为我想哈德森做的测试程序,我需要自动执行它(回答脚本的提示)
对于我的需求,我没能找到在以下来源的相关信息:
- http://yeoman.github.io/generator/
- https://github.com/yeoman/generator,在测试中有一些生成器调用代码,但我不知道如何使用grunt或node脚本运行它。
有没有人以前做过这个?
--update 30/April--
我尝试下面的脚本为 '测试/测试app.js':
var path = require('path');
var helpers = require('yeoman-generator').test;
describe('viena', function(){
var options = { 'skip-install': true };
var prompts = { 'scriptAppName': 'Viena' , "appTitle": "Test"};
// Runs once:
before(function(done){
// This method creates temporary folder for test output
// and clears it afterwards.
helpers.setUpTestDirectory(path.join(__dirname, 'tmp'));
done();
});
it('tests something', function(done){
// Emulating user's prompts:
helpers.run(path.join(__dirname, '../generators/app')).withPrompts(prompts);
done();
});
});
然后做:
npm test
但我未能掌握生成的应用程序。我需要获取应用程序并运行专为该应用程序设计的测试。我不想检查是否复制了某些文件,但我想验证生成的应用程序是否通过了测试。这些测试属于应用程序而不是生成器。
谢谢。你的建议让发电机启动,但我最终没有生成应用程序。请参阅我的更新。我希望你能进一步提供帮助。 – chfw
您正在运行发电机的主要应用程序(发电机本身)。为什么不为这个应用程序创建与此类似的第二个测试文件?只需更改'yourApp = helpers.createGenerator('your-generator:appName',['../../appName'],false,options);'或'helpers.run(path.join(__ dirname,'../generators/appName'))。withPrompts(prompts);'如果这对你有效(我没有试过这个语法)。 – sobolevn