Skip to content

Instantly share code, notes, and snippets.

@thebuilder
Last active October 29, 2022 02:42
Show Gist options
  • Save thebuilder/15a084f74b1c6a1f163fc6254ad5a5ba to your computer and use it in GitHub Desktop.
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
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)',
]
},
],
};
@jviel
Copy link

jviel commented Aug 26, 2022

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