question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:5
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
barbados-clemenscommented, Aug 3, 2022

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.

0reactions
barbados-clemenscommented, Aug 5, 2022

any luck @maxime1992 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

how solve error jest-worker at run build? - Stack Overflow
I hope I get a solution from you guys. here my error at run build: /MovieDB/node_modules/jest-worker/build/WorkerPool. js:25 } catch { ^ ...
Read more >
Troubleshooting - Jest
Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​. Try using the debugging support built into...
Read more >
Running All Tests in Jest doesn't show the error message ...
I have one test where I have failed on purpose. When I create a run configuration to run individual tests or a test...
Read more >
How to find the root cause of a failing test if Jest doesn't tell ...
The issue seems to occur more likely in Angular projects when using Node 14. How to get the actual error message in Jest...
Read more >
ts-jest - npm
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. Latest version: 29.0.3, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found