Vitest fails on CI with workspace generators >19.0.0
danr-za opened this issue · 6 comments
danr-za commented
Current Behavior
We are using workspace code generators using @nx/plugin
. Because we have updated prettier to v3 a while ago, we have switched to testing the generators with vitest
instead of jest
as it introduced some ESM stuff.
Lately, we have upgraded Nx from v19.0.0 to v19.6.4. During the upgrade, we noticed issues with those tests timing out or failing in CI, using Github actions.
Most code generators use Nx generators under the hood (e.g. @nx/js:lib
, @nx/react:lib
, etc.)
I have tried diagnosing the problem, and these are some interesting outputs:
- The following errors occurred while using the default vite configuration that is generated with
@nx/vite:vitest
src/generators/chart/generator.spec.ts (1 test | 1 failed) 2107ms
❯ src/generators/chart/generator.spec.ts > chart generator > should have all necessary files
→ Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
❯ src/generators/no-side-effects/generator.spec.ts (1 test | 1 failed) 3567ms
❯ src/generators/no-side-effects/generator.spec.ts > no-side-effects generator > should run successfully
→ Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
❯ src/generators/rpc-module/generator.spec.ts (1 test | 1 failed) 3683ms
❯ src/generators/rpc-module/generator.spec.ts > rpc-module generator > should generate a non buildable rpc lib
→ Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
❯ src/generators/browser-common-api/generator.spec.ts (1 test | 1 failed) 1701ms
❯ src/generators/browser-common-api/generator.spec.ts > browser-common-api generator > should run successfully
→ Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
TypeError: Cannot destructure property 'resolver' of 'pending.get(...)' as it is undefined.
❯ createNodesResult ../../node_modules/nx/src/project-graph/plugins/isolation/plugin-pool.js:162:25
❯ consumeMessage ../../node_modules/nx/src/project-graph/plugins/isolation/messaging.js:38:32
❯ ../../node_modules/nx/src/project-graph/plugins/isolation/plugin-pool.js:77:47
❯ Socket.<anonymous> ../../node_modules/nx/src/utils/consume-messages-from-socket.js:13:17
- After modifying the config with he following additions, no more errors, but tests fail with the default testTimeout. This is what we also used before, but without
sequence.hooks
addition:
poolOptions: {
threads: {
singleThread: true,
isolate: true
}
},
sequence: {
hooks: 'list'
}
- After modifying the
testTimeout
to 50s, tests are passing again. This is interesting because with that same configuration, with the defaulttestTimeout,
in Nx 19.0.0 the tests did not timeout.
Notes:
- I have also tried with Nx 19.1.0 and earlier minors - the same happens. So the issue was probably introduced in early minors/patches after 19.0.0.
- Those issues are not reproducing locally on my MB 16 Pro
Expected Behavior
Either:
- Introduce alternative configuration in the documentation to support CIs with multiple cores running tests
- Fix the (unknown) issue that was introduced in Nx versions after 19.0.0
GitHub Repo
No response
Steps to Reproduce
- Have a repo with workspace generators using
@nx/plugin
- Update prettier to v3 (3.3.3 to be precise)
- Switch the test configuration in the workspace generators to use
vitest
- Use
libraryGenerator
from@nx/js
in your code generator, withformatFiles
too (not sure it has impact though) - Write a test for the generator, for example:
describe('chart generator', () => {
let tree: Tree
beforeEach(() => {
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' })
})
it('should have all necessary files', async () => {
await chartGenerator(tree, { name: 'area' })
const config = readProjectConfiguration(tree, 'charts-area')
expect(config).toBeTruthy()
const root = config.sourceRoot
expect(tree.exists(`${root}/chart/AreaChart.tsx`)).toBeTruthy()
expect(
tree.exists(`${root}/__stories__/AreaChart.stories.tsx`)
).toBeTruthy()
})
})
Nx Report
NX Report complete - copy this into the issue template
Node : 20.15.1
OS : darwin-arm64
Native Target : aarch64-macos
yarn : 4.4.1
nx : 19.6.4
@nx/js : 19.6.4
@nx/jest : 19.6.4
@nx/linter : 19.6.4
@nx/eslint : 19.6.4
@nx/workspace : 19.6.4
@nx/cypress : 19.6.4
@nx/devkit : 19.6.4
@nx/eslint-plugin : 19.6.4
@nx/node : 19.6.4
@nx/plugin : 19.6.4
@nx/react : 19.6.4
@nx/storybook : 19.6.4
@nrwl/tao : 19.6.4
@nx/vite : 19.6.4
@nx/web : 19.6.4
@nx/webpack : 19.6.4
typescript : 5.5.4
---------------------------------------
Community plugins:
nx-stylelint : 17.1.5
---------------------------------------
Local workspace plugins:
@island/workspace
Failure Logs
No response
Package Manager Version
4.4.1
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
No response