You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default configuration that is scaffolded by the nx/plugin generators does not allow configuration of the testEnvironment. When we extend the nx/angular generators, specifically applicationGenerator and libraryGenerator, the default jest unit tests fail with:
The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "node" test environment.
Our applicationGenerator is passed the following properties:
Updating jest.config.ts to set testEnvironment to 'node' resolves the error and does not appear to affect the tests that are not using nx/angular generators. I also observed similar errors for the nx/react application generator.
The default generated jest.config.ts should be configured to allow all plugin tests to pass without requiring the manual addition of testEnvironment: 'node
GitHub Repo
No response
Steps to Reproduce
create a new Angular workspace with npx create-nx-workspace@latest
Select Jest Unit Test Runner
Add nx/plugin nx add @nx/plugin
Generate new plugin nx g @nx/plugin:plugin my-plugin
Generate new generator npx nx generate @nx/plugin:generator --path=my-plugin/generators/my-generator --description="this is my generator" --no-interactive
Update my-generator to use the nx/angular application generator
The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "node" test environment.
add testEnvironment: 'node' to the jest.config.ts file and run the tests again
my-generator generator
✕ should run successfully (153 ms)
● my-generator generator › should run successfully
The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "node"test environment.
TypeError: setTimeout(...).unref is not a function
16 | ) {
17 | const directory = `apps/${options.name}`;> 18 | await applicationGenerator(tree, {
| ^
19 | directory,
20 | e2eTestRunner: E2eTestRunner.None,
21 | });
at new DelayedSpinner (../node_modules/nx/src/utils/delayed-spinner.js:31:19)
at DaemonClient.getProjectGraphAndSourceMaps (../node_modules/nx/src/daemon/client/client.js:119:19)
at createProjectGraphAndSourceMapsAsync (../node_modules/nx/src/project-graph/project-graph.js:230:75)
at createProjectGraphAsync (../node_modules/nx/src/project-graph/project-graph.js:206:45)
at initEsLint (../node_modules/@nx/eslint/src/generators/init/init.js:55:62)
at lintInitGenerator (../node_modules/@nx/eslint/src/generators/init/init.js:94:18)
at lintProjectGeneratorInternal (../node_modules/@nx/eslint/src/generators/lint-project/lint-project.js:25:57)
at lintProjectGenerator (../node_modules/@nx/eslint/src/generators/lint-project/lint-project.js:17:12)
at addLintingGenerator (../node_modules/@nx/angular/src/generators/add-linting/add-linting.js:15:62)
at addLinting (../node_modules/@nx/angular/src/generators/application/lib/add-linting.js:11:37)
at applicationGenerator (../node_modules/@nx/angular/src/generators/application/application.js:39:32)
at async myGeneratorGenerator (my-generator.ts:18:3)
at async Object.<anonymous> (my-generator.spec.ts:17:7)
Package Manager Version
No response
Operating System
macOS
Linux
Windows
Other (Please specify)
Additional Information
I see a similar failure when extending the nx/react application generator, so the fix for the angular generators might need to be applied elsewhere. I have not tested vitest configuration so I am not sure if it suffers from the same issue.
I believe that updating the addJestOptions need to allow the application generator (and likely other generators as well) to pass the testEnvironment property to the jest configurationGenerator
Current Behavior
The default configuration that is scaffolded by the nx/plugin generators does not allow configuration of the testEnvironment. When we extend the nx/angular generators, specifically applicationGenerator and libraryGenerator, the default jest unit tests fail with:
Our applicationGenerator is passed the following properties:
Updating jest.config.ts to set testEnvironment to 'node' resolves the error and does not appear to affect the tests that are not using nx/angular generators. I also observed similar errors for the nx/react application generator.
Expected Behavior
The default generated jest.config.ts should be configured to allow all plugin tests to pass without requiring the manual addition of
testEnvironment: 'node
GitHub Repo
No response
Steps to Reproduce
npx create-nx-workspace@latest
nx add @nx/plugin
nx g @nx/plugin:plugin my-plugin
npx nx generate @nx/plugin:generator --path=my-plugin/generators/my-generator --description="this is my generator" --no-interactive
testEnvironment: 'node'
to the jest.config.ts file and run the tests againNx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
I see a similar failure when extending the nx/react application generator, so the fix for the angular generators might need to be applied elsewhere. I have not tested vitest configuration so I am not sure if it suffers from the same issue.
I believe that updating the addJestOptions need to allow the application generator (and likely other generators as well) to pass the testEnvironment property to the jest configurationGenerator
nx/packages/angular/src/generators/utils/add-jest.ts
Line 36 in 4d0ebe0
The text was updated successfully, but these errors were encountered: