我正在研究一个自定义的yeoman发生器,我正在尝试为子发电机添加一些测试 .
我无法弄清楚如何使用yeoman's test helpers来实现这一目标 . 我已经能够使用 composeWith()
与我的主生成器一起运行子生成器,但我无法让测试助手识别它 .
此外,当我从测试文件中运行生成器时,与正常运行(从命令行)运行时,我会遇到一些奇怪的差异 .
在app / index.js中:
Note: 此代码在正常运行时失败,并且从我的测试运行时失败 . 如果我将 composeWith
fucntion更改为 this.composeWith('my-generator:sub-generator')
,它会从命令行成功运行,但在测试期间仍然会失败 .
initializing: function() {
this.composeWith('sub-generator');
},
在我的测试文件中:
before(function (done) {
helpers.run(roundhouse)
.withGenerators([
[helpers.createDummyGenerator(), '../sub-generator']
])
.inDir(testDir)
.withPrompts(prompts.default)
.withOptions({"skipInstall": true})
.on('end', done);
});
从命令行运行生成器时出错( yo my-generator
):
You don't seem to have a generator with the name sub-generator installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 24 registered generators run yo with the `--help` option.
从我的测试运行时:
Uncaught Error: You don't seem to have a generator with the name sub-generator installed.
You can see available generators with npm search yeoman-generator and then install them with npm install [name].
To see the 2 registered generators run yo with the `--help` option.
为什么我的测试文件看不到我安装的其他发生器?而不是24个发电机,它告诉我,我只有2个 .
1 回答
调用composeWith http://yeoman.io/authoring/composability.html时需要传递
settings.local
传递路径本身将修复您可能遇到的大部分边缘情况 .