yeoman / generator

Rails-inspired generator system that provides scaffolding for your apps
http://yeoman.io
BSD 2-Clause "Simplified" License
1.2k stars 298 forks source link

RunContext#withGenerators() ignore composeWith with a local property #704

Closed SBoudrias closed 8 years ago

SBoudrias commented 9 years ago

When using composition with a local path (composeWith('gen:app', { local: 'local/path' })), it ignores/bypass the generators mocks we setup on the RunContext with #withGenerators() as it requires/register the generator directly.

This should probably be fixed, I'm unsure about the correct solution ATM.

SBoudrias commented 9 years ago

A potential solution I've come to think about is to mock the module require (with for example proxyquire).

We might to extract our test utilities to a separate module at this point. These are becoming fairly large and are impacting end user download time (who don't care about testing).

thaiat commented 9 years ago

another solution i use is to define an 'testmode' option in the generator, that defaults to false

and then use the following code when calling the subgenerator:

this.composeWith('xxx', 
     {} , 
    this.options.testmode ? null : {local: require.resolve('generator-xxx'})

Then when you run the generator in your test, set the option 'testmode' to true with withOptions

SBoudrias commented 8 years ago

Reopened under https://github.com/yeoman/yeoman-test/issues/16