nx icon indicating copy to clipboard operation
nx copied to clipboard

Running jest tests on node 16.15.0 fails with "Error: Unknown worker message type message"

Open jasonkenneth opened this issue 2 years ago • 6 comments

We have a long-lived NX monorepo hosting multiple angular apps/libs with a mix of karma and jest tests. While in the process of upgrading the docker image from node:12-slim to node:16-bullseye-slim, we're seeing the following during our jest unit test runs, and it breaks our CI build.:

 node:internal/event_target:912
  process.nextTick(() => { throw err; });
                           ^

Error: Unknown worker message type message
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues

    at new NodeError (node:internal/errors:372:5)
    at Function.fail (node:internal/assert:20:9)
    at Worker.[kOnMessage] (node:internal/worker:317:12)
    at MessagePort.<anonymous> (node:internal/worker:201:57)
    at l.invokeTask (/__w/1/s/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:13:7018)
    at a.runTask (/__w/1/s/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:13:2427)
    at u.invokeTask [as invoke] (/__w/1/s/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:13:8068)
    at u (/__w/1/s/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:44:1053)
    at h (/__w/1/s/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:44:1373)
    at MessagePort.p (/__w/1/s/node_modules/zone.js/fesm2015/zone-testing-bundle.min.js:44:1667) {
  code: 'ERR_INTERNAL_ASSERTION'
}

I modified our test runner to run all of the jest tests together (~45 of them) from a helper javascript with the following command:

try {
  execSync(
    `npx nx run-many --target=test --projects=${projects.join(',')} --parallel --max-parallel=3 --configuration=cicd`,
    {
      stdio: [0, 1, 2],
    },
  );
} catch (e) {
  process.exit(e.status);
}

Relevant versions:

@nrwl/angular           13.10.3
@nrwl/cli               13.10.3
@nrwl/eslint-plugin-nx  13.10.3
@nrwl/jest              13.10.3
@nrwl/linter            13.10.3
@nrwl/nest              13.10.3
@nrwl/node              13.10.3
@nrwl/workspace         13.10.3
@types/jest              27.4.1
jest                     27.5.1
jest-junit              ^13.1.0
jest-mock               ^27.5.1
jest-preset-angular     ^11.1.1
ts-jest                  27.1.4

Thoughts? Do these versions of things not work on node 16? Is there an upgrade path that will support it?

The problem does go away if I simply use node:14-bullseye-slim as the base image.

Also, I have been able to replicate outside of the container locally on node v16.15.0. Some of the tests were placeholders as simple as:

describe('server/testing-nestjs', () => {
  it('Has no tests', () => {
    expect(true).toEqual(true);
  });
});

Attempt to Fix by Upgrading Dependencies

I tried a couple of queries on google, this seems to be sort of the better one, and yet I can’t seem to find a connection to Jest itself

The solution in this link was to upgrade deps. I did spend a few days trying that in our case; however, it blew up our jest-preset-angular configuration.

In the end, it wasn't clear to me if I could run with jest v28.1.0, ts-jest 28.0.3, and jest-preset-angular 12.0.1 in nx 13.10.3. I decided to backtrack when I reached the point where it appeared that an object-oriented attempt to call an overridden method from the base in ng-jest-transformer.ts/_createConfigSet wasn't working, and I couldn't get the tests to run. Specifically, I was getting a configSet.processWithEsbuild is not a function error here.

I tried upgraded the following:

 @types/jest              27.4.1  →   27.5.1
 jest                     27.5.1  →   28.1.0
 jest-junit              ^13.1.0  →  ^13.2.0
 jest-mock               ^27.5.1  →  ^28.1.0
 jest-preset-angular     ^11.1.1  →  ^12.0.1
 ts-jest                  27.1.4  →   28.0.3

(From slack on the #angular channel with @gioragutt)

jasonkenneth avatar May 31 '22 22:05 jasonkenneth

can you try with latest nx?

barbados-clemens avatar Aug 02 '22 15:08 barbados-clemens

I'm on NX 14.5.2 (latest) and I've got the exact same error

maxime1992 avatar Aug 03 '22 14:08 maxime1992

hmmm, if this is a jest-preset-angular induced issue, it might be fixed when I finalize Jest 28 here #10857 which fixed a couple issues with the newest jest-preset-angular v12.2 that people were experience around esbuild-wasm. so I wonder if it might cover this as well.

if this happens locally, you could try checking out that PR and trying a local release of nx to migrate.

also if you got a repo I can pull down to check that would be appreciated since it doesn't seem to just happen in a new workspace with tests

barbados-clemens avatar Aug 03 '22 15:08 barbados-clemens

Hi @barbados-clemens, I believe I can repro unfortunately I'm not able to share the project.

Can you give me some guidance on #10857 and how to run the migration with that branch?

I guess I check it out, build, I can then just replace my node module with the build and launch the migration using the local instance of nx?

maxime1992 avatar Aug 03 '22 15:08 maxime1992

it's making a local release as described in the contributing guide.

which is essentially:

  • setting up the local registry
  • publishing nx to the local registry
  • running nx migrate to your repo (which will now use the local registry)

happy to help out if you got any more questions on it.

barbados-clemens avatar Aug 03 '22 15:08 barbados-clemens

any luck @maxime1992 ?

barbados-clemens avatar Aug 05 '22 21:08 barbados-clemens

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] avatar Feb 02 '23 00:02 github-actions[bot]

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.

github-actions[bot] avatar Mar 20 '23 22:03 github-actions[bot]