【问题标题】:Where does the yeoman test-helper look for sub-generators?yeoman 测试助手在哪里寻找子生成器?
【发布时间】:2016-07-02 08:55:52
【问题描述】:

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

我不知道如何使用yeoman's test helpers 来完成此操作。 我已经能够使用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 个生成器。

【问题讨论】:

  • 尝试传递路径看看yeoman.io/authoring/composability.htmlsettings.local
  • 使用 .withGenerators(['../sub-generator/index.js']) 会产生相同的错误,但会计算 1 个注册生成器而不是 2 个。我还尝试使用 path.join()path.resolve() 在路径上传递变化,但没有效果。

标签: javascript node.js testing yeoman yeoman-generator


【解决方案1】:

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

传递路径本身将解决您可能遇到的大部分边缘情况。

【讨论】:

  • 解决了,谢谢!我仍然很好奇为什么测试工作需要settings.local,但在使用yo my-generator 运行生成器时不需要。
猜你喜欢
  • 1970-01-01
  • 2015-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-18
相关资源
最近更新 更多