Temporal Workflow Test Case issue

Hi, I’m trying to run test case for the temporal workflow using jest but i am encountering the following error “Unhandled rejection { runId: undefined } IllegalStateError: Workflow has not been initialized”.

Sample Code snippet
const mockActivities = {
userLogin: async () => ‘done’,
};
worker = await Worker.create({
connection: testEnv.nativeConnection,
activities: mockActivities,
workflowsPath: require.resolve(“…/tutorial/js_test/workflows.js”),
taskQueue: “test”,
});
const workflowId = uuid4();
console.log(Starting workflow with ID: ${workflowId});
const result = await worker.runUntil(
testEnv.client.workflow.execute(loginAndRegister, {
workflowId,
taskQueue: “test”,
args: ,
})
)

Error Output:
Unhandled rejection { runId: undefined } IllegalStateError: Workflow has not been initialized
at Object.initRuntime (/home/namith/Desktop/src/worker-interface.ts:134:10)
at evalmachine.:1:18
at Script.runInContext (node:vm:141:12)
at Object.runInContext (node:vm:291:6)
at Proxy. (/home/namith/Desktop/learn-temporal/node_modules/@temporalio/worker/lib/workflow/vm.js:40:46)
at VMWorkflowCreator.createWorkflow (/home/namith/Desktop/learn-temporal/node_modules/@temporalio/worker/lib/workflow/vm.js:47:24)
at async handleRequest (/home/namith/Desktop/learn-temporal/node_modules/@temporalio/worker/lib/workflow/workflow-worker-thread.js:42:13)
at async MessagePort. (/home/namith/Desktop/learn-temporal/node_modules/@temporalio/worker/lib/workflow/workflow-worker-thread.js:92:32)
2023-09-14T10:25:39.160004Z INFO temporal_sdk_core::worker: Initializing worker task_queue=test namespace=default
2023-09-14T10:25:39.293Z [ERROR] Worker failed {
error: UnexpectedError: Worker thread shut down prematurely, this could be caused by an unhandled rejection in workflow code that could not be associated with a workflow run
at Worker. (/home/namith/Desktop/learn-temporal/node_modules/@temporalio/worker/src/workflow/threaded-vm.ts:86:11)
at Worker.emit (node:events:513:28)
at Worker.[kOnExit] (node:internal/worker:279:10)
at Worker..onexit (node:internal/worker:199:20)
at Worker.callbackTrampoline (node:internal/async_hooks:130:17)
}
2023-09-14T10:25:39.295Z [INFO] Worker state changed { state: ‘FAILED’ }

Am i doing something wrong here?

Hey!

First, welcome in Temporal community.

I’m not sure which version of the TS SDK you are using here, but that seems to predate the 1.0.0 release. Latest release is 1.8.6. Can you please try updating all your @temporalio/* dependencies to 1.8.6, then try again? Also, make sure that you are no longer using the “all-in-one” temporalio dependency, which existed back then, but has since been deprecated.

My impression is that you probably have multiple copies of some of the Temporal packages in your workspace. We improved the developer experience in that regard in more recent versions, but there’s essentially nothing we can do to about very old releases.

James