vendredi 1 juillet 2016

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

I'm working on a custom yeoman generator, and I'm trying to add some tests for a sub-generator.

I can't figure out how to use yeoman's test helpers to accomplish this. I have been able to use composeWith() to run the sub-generator alongside my main generator, but I can't get the test helper to recognize it.

Furthermore, I'm getting some weird discrepancies when I run the generator from my test files, vs when I run it normally (from the command line).

in app/index.js:

Note: This code fails when run normally, and when run from my tests. If I change the composeWith fucntion to this.composeWith('my-generator:sub-generator'), it runs successfuly from the command line, but still fails during testing.

initializing: function() {
  this.composeWith('sub-generator');
},

in my test file:

before(function (done) {
  helpers.run(roundhouse)
    .withGenerators([
      [helpers.createDummyGenerator(), '../sub-generator']
    ])
    .inDir(testDir)
    .withPrompts(prompts.default)
    .withOptions({"skipInstall": true})
    .on('end', done);
});

The error produced when running the generator from the command line (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.

When run from my tests:

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.

Why can't my test-file see the other generators I have installed? Instead of 24 generators, it tells me that I only have 2.

Aucun commentaire:

Enregistrer un commentaire