CombinedWorkerRunError: Worker terminated with fatal error in `runUntil` with Jest

Hi all,

I am trying to run a basic Workflow test, by following this example (which runs fine locally for me). But I am running into an error:

The error:

 RUNS  src/workflows.test.ts
2023-07-05T07:52:05.071583Z  INFO temporal_sdk_core::ephemeral_server: Downloading https://temporal.download/assets/temporalio/sdk-java/releases/download/v1.17.0/temporal-test-server_1.17.0_macOS_amd64.tar.gz to /var/folders/5r/9_zw12cn2936_hj2wrmg88680000gn/T/temporal-test-server-sdk-typescript-1.
 RUNS  src/workflows.test.ts
 RUNS  src/workflows.test.ts
  console.log
    [ERROR] Worker failed

      at DefaultLogger.worker_1.Runtime.install.logger [as logFunction] (src/workflows.test.ts:15:68)
          at Map.forEach (<anonymous>)

 FAIL  src/workflows.test.ts (6.644 s)
  ✕ httpWorkflow with mock activity (791 ms)

  ● httpWorkflow with mock activity

    CombinedWorkerRunError: Worker terminated with fatal error in `runUntil`

      40 |   );
      41 |
    > 42 |   await worker.runUntil(async () => {
         |   ^
      43 |     const result = await client.workflow.execute(initLabResultsWorkflow, {
      44 |       workflowId: uuid4(),
      45 |       taskQueue: 'test',

      at Worker.runUntil (node_modules/@temporalio/worker/src/worker.ts:1669:15)
      at Object.<anonymous> (src/workflows.test.ts:42:3)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |                   
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        6.673 s
Ran all test suites.

Here are the versions I am using:

"@temporalio/activity": "1.8.0",
"@temporalio/client": "1.8.0",
"@temporalio/worker": "1.8.0",
"@temporalio/workflow": "1.8.0",
"@temporalio/nyc-test-coverage": "^1.8.0",
"@temporalio/testing": "^1.8.0",

To clarify, the code is virtually identical to the sample:

test('httpWorkflow with mock activity', async () => {
  const { client, nativeConnection } = testEnv;
  const worker = await Worker.create(
    workflowCoverage.augmentWorkerOptions({
      connection: nativeConnection,
      taskQueue: 'test',
      workflowsPath: require.resolve('./workflows'),
      activities: {
        getToken: async () => '99',
      },
    })
  );

  await worker.runUntil(async () => {
    const result = await client.workflow.execute(initLabResultsWorkflow, {
      workflowId: uuid4(),
      taskQueue: 'test',
      args: [{consumerId: '123'}],
    });
    expect(result).toEqual('The answer is 99');
  });
});

The Workflow runs fine when called with a Client.

The sample application fails as well if I upgrade all the dependencies to 1.8.0:

Looks like a regression in 1.8.0.
This is due to how Jest “replaces” global objects when it isolates test instances, failing instanceof checks that the SDK was relying on.

This PR fixes the issue and will be included in a 1.8.1 patch release hopefully by the end of the week.

Note that we do not recommend using Jest for testing workflows due to a few outstanding issues reported by the community. It may work but we do not officially support it and are not prioritizing fixing the few Jest related issues.

Thanks! Looking in the samples, the recommended alternative is Mocha then?

Any test runner that doesn’t do too much “magic” such a switching v8 contexts and transpilation.

We know that mocha and ava both work well.

1 Like