Closed decline closed 4 months ago
experiencing the same but with the applicationGenerator from '@nx/next' on v18.3.4
I'm experiencing the same problem. Tests work on MacOS but not on our Linux CI.
It happens when I call the libraryGenerator
function from @nx/nest
@18.3.4 on a Jest test
I have a similar issue with a Jest test also using the libraryGenerator
. However, I see the error on both Github Actions / nx agents as well as on my Mac developer machine.
I also tried to copy paste the test in this issue and run the test, and it fails on my mac running Sonoma 14.4.1
I got my test to run by following a workaround from https://github.com/mswjs/msw/issues/1851
Object.defineProperties(globalThis, {
performance: { value: performance, writable: true },
});
Not quite sure why it works, but my test runs again with this 'fix'.
I'm having the same issue when wrapping the service schematic from @schematics/angular, and executing that.
Although, when running locally (MacOS) I get this error
ReferenceError: TextDecoder is not defined
18 |
19 | const serviceGenerator = wrapAngularDevkitSchematic('@schematics/angular', 'service');
> 20 | await serviceGenerator(tree, serviceOptions);
| ^
21 |
at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/src/rules/template.js:33:17)
at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/src/index.js:56:14)
at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/tools/file-system-engine-host-base.js:16:15)
at Object.<anonymous> (../../node_modules/@angular-devkit/schematics/tools/index.js:27:14)
at createWorkflow (../../node_modules/nx/src/adapter/ngcli-adapter.js:165:26)
at ../../node_modules/nx/src/adapter/ngcli-adapter.js:697:26
at serviceGenerator (src/generators/service/generator.ts:20:3)
at Object.<anonymous> (src/generators/service/generator.spec.ts:34:5)
but on CI I get the same as OP.
facing the same issue, but only in the TeamCity environment.
@AgentEnder , any update on this?
Having the same issue. Tests run well on local Mac, but does not work on Linux env in CI.
Hi there 👋 - so this is a bit more complex than one may imagine. Most typically getting this error during a unit test is a result of a test doing something that is causing the project graph to be created. You'll need to mock the project graph during these tests, and while that sounds rough its also going to give you much more accurate and repeatable tests.
Without mocking the graph, the tests will be running generators which create the project graph of the current Nx workspace and make some decisions about that. That's almost always not really what you want. We just recently fixed that behavior on the Nx repo.
This suddenly became a problem for some folks because several of our published generators do rely on the graph now.
You can see how we are mocking this in our unit test setup: https://github.com/nrwl/nx/blob/master/scripts/unit-test-setup.js
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
When using the
libraryGenerator()
method from@nx/angular/generators
inside a (Jest) test, it will fail.Example:
The test will fail with the following error message:
Important:
This error only happens on Linux operating system. The same test passes on a MacOS operating system.
Expected Behavior
The test should run successfully on every operating system.
GitHub Repo
https://github.com/decline/nx-plugin-issue
Steps to Reproduce
docker compose up
Info:
Starting the docker container will execute the
nx run my-plugin:test
command which will fail the test. If you run thenx run my-plugin:test
command on a MacOS system, it will pass!Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
No response