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

fix(js): babel preset should also check for JEST_WORKER_ID to transpile to CJS #21754

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Feb 9, 2024

This PR fixes a longstanding issue with @nx/js/babel where NODE_ENV being anything other than test will cause errors due to modules being transpiled as ESM (and Jest not able to run it).

Previously, our @nx/jest:jest executor guarantees this NODE_ENV is test, but now with Project Crystal we are skipping the executor. To know whether we're in Jest context, we should check the JEST_WORKER_ID which is always set when using Jest runner.

For example, if you generate an app and run Jest with NODE_ENV set to anything else you'll see an error.

npx nx g @nx/react:app jest-app --unitTestRunner=jest
NODE_ENV=development npx nx test jest-app # ERROR!

Current Behavior

Setting NODE_ENV to anything other than test will result in test failure.

Expected Behavior

Our test setup should be resilient against NODE_ENV not being test.

Related Issue(s)

Fixes #

@jaysoo jaysoo requested review from meeroslav, vsavkin, mandarini and a team as code owners February 9, 2024 17:01
@jaysoo jaysoo requested a review from FrozenPandaz February 9, 2024 17:01
Copy link

vercel bot commented Feb 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Feb 9, 2024 7:41pm

@jaysoo jaysoo force-pushed the fix_babel_jest branch 4 times, most recently from 9fb588c to c716d66 Compare February 9, 2024 19:27
@FrozenPandaz FrozenPandaz merged commit 70ea82d into nrwl:master Feb 9, 2024
6 checks passed
@jaysoo jaysoo deleted the fix_babel_jest branch February 9, 2024 20:50
FrozenPandaz pushed a commit that referenced this pull request Feb 9, 2024
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants