yeoman测试助手在哪里查找子生成器

Where does the yeoman test-helper look for sub-generators?

本文关键字:查找 在哪里 测试 yeoman      更新时间:2023-09-26

我正在制作一个自定义的自动生成器,并且我正在尝试为子生成器添加一些测试。

我不知道如何使用约曼的测试助手来完成这一点。我已经能够使用composeWith()在主发电机旁边运行子发电机,但我无法让测试助手识别它。

此外,当我从测试文件中运行生成器时,与正常运行时(从命令行)相比,我得到了一些奇怪的差异。

在app/index.js:

注意:这段代码在正常运行时失败,在我的测试中运行时失败。如果我将composeWith函数更改为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.

为什么我的测试文件看不到我安装的其他生成器?它告诉我只有2个而不是24个生成器

调用composeWith http://yeoman.io/authoring/composability.html时需要传递settings.local

传递路径本身将修复您可能遇到的大多数边缘情况。