Last active
October 29, 2022 02:42
-
-
Save thebuilder/15a084f74b1c6a1f163fc6254ad5a5ba to your computer and use it in GitHub Desktop.
Use Jest Projects to run both JSDom and Node tests in the same project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
projects: [ | |
{ | |
displayName: 'dom', | |
testEnvironment: 'jsdom', | |
snapshotSerializers: ['enzyme-to-json/serializer'], | |
testMatch: ['**/__tests__/**/*.test.js?(x)'] | |
}, | |
{ | |
displayName: 'node', | |
testEnvironment: 'node', | |
testMatch: [ | |
'**/__tests__/**/*.test.node.js?(x)', | |
] | |
}, | |
], | |
}; |
Thanks for this.
Thanks a lot
This got me on the right track, thank you!
In my case I was missing another piece:
I have a unified project with both client/ and server/ code, each with their own package.json. I had to set "type": "module"
in the package.json corresponding to the client (with jsdom environment) tests.
Now my project root jest config works for all sub-projects.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use Jest Projects to run tests targeting both JSDom and Node. Perfect if you are are doing SSR and want to validate your code, while also testing code running in the browser.
These matches looks for
*.test.js
and*test.node.js
, but feel free to configure these to match your project. Maybe you want to use Node for all tests underserver/
?Just use
jest
like you normally to run the tests.