fix(tooling): pin NODE_ENV=test on jest invocations#724
Conversation
Jest only defaults NODE_ENV to test when it is unset. In a CI pod that already exports NODE_ENV=production, React loads its production build and act(...) throws (act is not supported in production builds of React), failing the 24 @webex/cc-user-state tests among others. Pin NODE_ENV=test on every jest invocation (each package's test:unit and the root test:tooling) so tests are correct regardless of the ambient environment, covering all invocation paths (single-package, test:cc-widgets, and the aggregate test:unit). Document the rationale in testing-patterns.md.
|
This pull request is automatically being deployed by Amplify Hosting (learn more). |
mkesavan13
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks, Bharath
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab6b5aa9b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| Each package's `test:unit` (and root `test:tooling`) pins `NODE_ENV=test` on the `jest` | ||
| invocation. Jest only defaults `NODE_ENV` to `test` when it is *unset*; in a CI pod that already | ||
| exports `NODE_ENV=production`, React loads its production build and `act(...)` throws | ||
| (`act(...) is not supported in production builds of React`). Pinning it keeps tests correct | ||
| regardless of the ambient environment. |
There was a problem hiding this comment.
Update the new-widget template test script
This new testing convention doesn't update the code-generation template: ai-docs/templates/new-widget/02-code-generation.md:675 still emits tsc --project tsconfig.test.json && jest --coverage. New contact-center widgets generated from that template will therefore be the only packages without the NODE_ENV=test guard, so running their generated test:unit in a CI pod with ambient NODE_ENV=production will reintroduce the React act(...) production-build failure described here.
Useful? React with 👍 / 👎.
| "build:src": "yarn run clean:dist && webpack", | ||
| "build:watch": "webpack --watch", | ||
| "test:unit": "tsc --project tsconfig.test.json && jest --coverage", | ||
| "test:unit": "tsc --project tsconfig.test.json && NODE_ENV=test jest --coverage", |
There was a problem hiding this comment.
Update the store spec for the pinned test command
Changing this package script leaves the module's own spec stale: packages/contact-center/store/ai-docs/store-spec.md:47 still states the command is tsc --project tsconfig.test.json && jest --coverage even though the code now relies on pinning NODE_ENV=test to avoid React production builds. Anyone following the store spec for a single-package run in a CI pod with NODE_ENV=production can reproduce the failure this patch is trying to eliminate, so the spec needs the same command update.
AGENTS.md reference: AGENTS.md:L68-L68
Useful? React with 👍 / 👎.
Thank you for your contribution! |
COMPLETES #< INSERT LINK TO ISSUE >
This pull request addresses
Unit tests fail in CI/pod environments that already export
NODE_ENV=production. Jest only defaultsNODE_ENVtotestwhen it is unset; when the ambient environment already setsNODE_ENV=production, Jest inherits it, React loads its production build, andact(...)throws:This failed 24
@webex/cc-user-statetests (and is latent for every other package). The test commands in the manifest and docs only specified the bareyarn test:cc-widgets/yarn workspace @webex/{pkg} test:unit, none of which pinnedNODE_ENV, so the repository contract did not account for running inside a pod withNODE_ENV=production.by making the following changes
Pin
NODE_ENV=testdirectly on thejestinvocation at the source, so it is correct regardless of the ambient environment and regardless of which invocation path is used (single-package,test:cc-widgets, or the aggregatetest:unit):package.json:test:tooling.test:unitthat runsjest:store,cc-components,cc-widgets,cc-digital-channels,user-state,task,station-login,ui-logging, and meetings@webex/widgets.ai-docs/patterns/testing-patterns.md.Follows the repo's existing inline-env convention (
build:dev/build:prodin rootpackage.json);cross-envis not a workspace dependency. The.sdd/manifest.jsoncommand stays as the bareyarn test:cc-widgetssince the fix is now at the source.Change Type
The following scenarios were tested
NODE_ENV=production yarn workspace @webex/cc-user-state test:unitfailed withact(...) is not supported in production builds of Reactbefore the change.NODE_ENV=production yarn run test:unit→ exit 0, all suites pass, zeronot supported in production buildserrors.test:unit+test:styles) passed on commit.The GAI Coding Policy And Copyright Annotation Best Practices
Checklist before merging