Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

composeWith sub-generator not mocking as expected #1706

Closed
wulfgarpro opened this issue Feb 22, 2019 · 4 comments
Closed

composeWith sub-generator not mocking as expected #1706

wulfgarpro opened this issue Feb 22, 2019 · 4 comments

Comments

@wulfgarpro
Copy link

I'm trying to test my generator, which, using composeWith, relies on a sub-generator (generator-express):

this.composeWith(require.resolve('generator-express/app'), {dirname: this.props.app_name, createDirectory: 'n'});
My test is trying to mock said sub-generator:

var deps = [
      [helpers.createDummyGenerator(), require.resolve('generator-express/app')]
];

describe('generator-cesium/app Test', () => {
    beforeEach(() => {
        return helpers.run(path.join(__dirname, '../generators/app'))
            .inDir(path.join(__dirname, 'tmp'))
            .withPrompts({
                viewerContext: '/',  // eslint-disable-line camelcase
                appName: 'app'       // eslint-disable-line camelcase
            })
            .withGenerators(deps)
    });
...

But, I keep getting the following error:

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (TypeError: Cannot read property 'match' of undefined)

      at Immediate.setImmediate (node_modules/generator-express/node_modules/yeoman-generator/lib/index.js:406:18)

The error, indicating that the sub-generator is still being executed, leads me to believe that the mock is not actually working?

@chippawah
Copy link

I'm having the same issue. There's a command that's being run within the sub-generator that should be mocked and therefore not run.

@wulfgarpro
Copy link
Author

wulfgarpro commented Mar 3, 2019

I have a SO question here outlining the issue. AFAICT, the only answer I've been given, as light on detail as it is, does not work, and worryingly, the user who answered purports to be a contributor to the Yeoman project 😟.

@eddiemonge
Copy link
Member

@wulfgarpro @SBoudrias is one of the core contributors and wrote the sub-generator stuff.

@mshima
Copy link
Member

mshima commented Jan 31, 2020

The problem is that when you composeWith a generator path, it will load that path and ignore the registered generators/mocks.
https://github.com/yeoman/generator/blob/006e13e485fcaeed613c78d594884bc1c69961e5/lib/index.js#L707-L709

The mock is registered to the environment with the namespace.
To use the mock you should use namespaces instead of paths.

As far as I can see this is not a bug so I am closing it.

@mshima mshima closed this as completed Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants