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

FileStub.js used for lodash modules :-( #1147

Closed
kentcdodds opened this issue Dec 4, 2016 · 4 comments
Closed

FileStub.js used for lodash modules :-( #1147

kentcdodds opened this issue Dec 4, 2016 · 4 comments

Comments

@kentcdodds
Copy link
Contributor

kentcdodds commented Dec 4, 2016

Can you reproduce the problem with latest npm?

Yes

Description

Due to this config for Jest, lodash.<method-name> modules are stubbed out as test-file-stub. These are quite commonly used in common modules. For example, cheerio (used by enzyme) uses lodash.assignin for _.extend behavior and because the regex used in the Jest config matches lodash. modules, it is mocked.

Expected behavior

Don't mock modules which resolve to modules ending in .js

Actual behavior

Mocks any modules referenced with a . in their name (even if they resolve to .js modules via normal CommonJS resolution semantics).

Environment

Mostly Irrelevant. I'm using v0.8.0 of react-scripts

Reproducible Demo

Happy to make a demo if that's needed, but I think the issue is pretty clear. The solution... I think that we need to go back from a blacklist (like we have now) to a whitelist (like we had before)... Effectively reverting #1077 which was meant to address #667, but unfortunately had this pretty serious side-effect :-(

I imagine that considering react-scripts was released only about 10 hours ago, you'll start to see more and more people with this same issue. It would probably be good to get this fixed quickly to minimize impact.

@kentcdodds
Copy link
Contributor Author

This appears to be related to #1145

@tamouse
Copy link

tamouse commented Dec 4, 2016

I think I just ran into this: first time user, trying out enzyme, and this error crops up:

FAIL  src/App.test.js
  ● Test suite failed to run

    TypeError: _.extend is not a function
      
      at Object.<anonymous> (node_modules/cheerio/lib/cheerio.js:93:3)
      at Object.<anonymous> (node_modules/cheerio/index.js:5:28)
      at Object.<anonymous> (node_modules/enzyme/build/ReactWrapper.js:11:16)
      at Object.<anonymous> (node_modules/enzyme/build/index.js:6:21)
      at Object.<anonymous> (src/App.test.js:2:41)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.869s
Ran all test suites related to changed files.

after changing the stock App.test.js file to:

import React from 'react';
import { shallow } from 'enzyme';
import App from './App';

it('renders without crashing', () => {
  shallow(<App/>);
});

as described here

@kentcdodds
Copy link
Contributor Author

@tamouse, until this is fixed, you can downgrade to 0.7.0 and still enjoy the beautiful simplicity of create-react-app :)

@fson
Copy link
Contributor

fson commented Dec 4, 2016

I've just published react-scripts 0.8.1 with a hot fix for this issue.

@fson fson closed this as completed Dec 4, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants