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

Add “node” to Jest's moduleFileExtensions #2738

Merged
merged 1 commit into from
Jul 7, 2017
Merged

Add “node” to Jest's moduleFileExtensions #2738

merged 1 commit into from
Jul 7, 2017

Conversation

mostafah
Copy link
Contributor

@mostafah mostafah commented Jul 7, 2017

Jest’s default value for its moduleFileExtensions option is ["js", "json", "jsx", "node"]. CRA was not using this option before version 1.0.8, so this default list was used.

PR #2511 (merged in version 1.0.8) sets this option to ["web.js", "js", "json", "web.jsx", "jsx"]. The PR is about adding .web extensions, but it is also removing .node because it is not included like other default extensions.

Why is this a bug?

Packages using native code through node-gyp import files with .node extension. Using those packages fails the tests with a Cannot find module … error.

screen shot 1396-04-16 at 10 09 13

This used to work with version 1.0.7.

Reproduction and testing

This repo is a minimal reproduction of this bug. Tests fail there. Changing react-scripts to 1.0.7 or manually applying this change to node_modules/react-scripts/scripts/utils/createJestConfig.js fixes the problem.

Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
@gaearon gaearon added this to the 1.0.11 milestone Jul 7, 2017
@gaearon gaearon merged commit 16f0d4a into facebook:master Jul 7, 2017
@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2017

Thanks for the catch.
I guess it’s reasonable to support this, even though it wouldn’t work with webpack.

@mostafah
Copy link
Contributor Author

mostafah commented Jul 7, 2017

Thanks for the merge.

This is for projects that are using the same setup for the server. I have my backend code in src/server and take advantage of most of the CRA scripts for that.

@mostafah mostafah deleted the jest-module-extensions branch July 7, 2017 14:23
romaindso pushed a commit to romaindso/create-react-app that referenced this pull request Jul 10, 2017
Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
@Timer
Copy link
Contributor

Timer commented Aug 9, 2017

Hi there! This change is out in react-scripts@1.0.11; please give it a go! Thanks.

@mostafah
Copy link
Contributor Author

mostafah commented Aug 9, 2017

Hi. I tested react-scripts@1.0.11 and it works. The bug is fixed. Thanks for the release and the reminder.

JohnNilsson referenced this pull request in JohnNilsson/create-react-app-typescript Aug 9, 2017
Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
connectdotz added a commit to connectdotz/create-react-app-typescript that referenced this pull request Aug 30, 2017
This is the same issue documented in react-script PR #2738 (facebook/create-react-app#2738), which has already been merged.
morgs32 pushed a commit to BrickworkSoftware/create-react-app that referenced this pull request Sep 1, 2017
Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
JohnNilsson referenced this pull request in JohnNilsson/create-react-app-typescript Sep 9, 2017
Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
kasperpeulen pushed a commit to kasperpeulen/create-react-app that referenced this pull request Sep 24, 2017
Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
swengorschewski referenced this pull request in swengorschewski/cra-typescript-electron Oct 16, 2017
Jest's default value for this option is ["js", "json", "jsx", "node"].
CRA's current value is ["web.js", "js", "json", "web.jsx", "jsx"], which
is missing one of default ones: "node". This change fixes that.

This "node" extension is used in packages that use native code.
@lock lock bot locked and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants