cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.07k stars 1.09k forks source link

Error when trying to run in parallel #2444

Closed evertondanilo closed 1 week ago

evertondanilo commented 1 week ago

👓 What did you see?

When I try to run in parallel I get this issue below. However, it works fine when not in parallel. Why? How to resolve this?

npx cucumber-js --parallel 2

VError: Unexpected error on worker.receiveMessage: Cannot find module '../../src/Another'
Require stack:
- C:\Users\John.Smith\cucumber-parallel\features\StepDefinitions\Another.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\try_require.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\worker.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\run_worker.js
    at exit (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\run_worker.ts:8:38)
    at C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\run_worker.ts:22:9
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
caused by: Error: Cannot find module '../../src/Another'
Require stack:
- C:\Users\John.Smith\cucumber-parallel\features\StepDefinitions\Another.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\try_require.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\worker.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\run_worker.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
    at Function._load (node:internal/modules/cjs/loader:1075:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (C:\Users\John.Smith\cucumber-parallel\features\StepDefinitions\/C:/Users/John.Smith/Downloads/Studies/react/cucumber-parallel/features/StepDefinitions/Another.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._compile (C:\Users\John.Smith\cucumber-parallel\node_modules\pirates\lib\index.js:117:24)
    at node:internal/modules/cjs/loader:1689:10
    at Object.newLoader [as .js] (C:\Users\John.Smith\cucumber-parallel\node_modules\pirates\lib\index.js:121:7)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at tryRequire (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\try_require.ts:9:12)
    at C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\worker.ts:79:44
    at Array.map (<anonymous>)
    at Worker.initialize (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\worker.ts:79:18)    
    at Worker.receiveMessage (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\worker.ts:110:18)
    at process.<anonymous> (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\run_worker.ts:20:8)
    at process.emit (node:events:518:28)
    at emit (node:internal/child_process:950:14)
    at processTicksAndRejections (node:internal/process/task_queues:91:21)
VError: Unexpected error on worker.receiveMessage: Cannot find module '../../src/Another'
Require stack:
- C:\Users\John.Smith\cucumber-parallel\features\StepDefinitions\Another.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\try_require.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\worker.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\run_worker.js
    at exit (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\run_worker.ts:8:38)
    at C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\run_worker.ts:22:9
    at processTicksAndRejections (node:internal/process/task_queues:105:5)
caused by: Error: Cannot find module '../../src/Another'
Require stack:
- C:\Users\John.Smith\cucumber-parallel\features\StepDefinitions\Another.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\try_require.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\worker.js
- C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\lib\runtime\parallel\run_worker.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
    at Function._load (node:internal/modules/cjs/loader:1075:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (C:\Users\John.Smith\cucumber-parallel\features\StepDefinitions\/C:/Users/John.Smith/Downloads/Studies/react/cucumber-parallel/features/StepDefinitions/Another.js:2:1)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Module._compile (C:\Users\John.Smith\cucumber-parallel\node_modules\pirates\lib\index.js:117:24)
    at node:internal/modules/cjs/loader:1689:10
    at Object.newLoader [as .js] (C:\Users\John.Smith\cucumber-parallel\node_modules\pirates\lib\index.js:121:7)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at tryRequire (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\try_require.ts:9:12)
    at C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\worker.ts:79:44
    at Array.map (<anonymous>)
    at Worker.initialize (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\worker.ts:79:18)    
    at Worker.receiveMessage (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\worker.ts:110:18)
    at process.<anonymous> (C:\Users\John.Smith\cucumber-parallel\node_modules\@cucumber\cucumber\src\runtime\parallel\run_worker.ts:20:8)
    at process.emit (node:events:518:28)

    at emit (node:internal/child_process:950:14)
    at processTicksAndRejections (node:internal/process/task_queues:91:21)
0 scenarios
0 steps
0m02.395s (executing steps: 0m00.000s)
PS C:\Users\John.Smith\cucumber-parallel>

✅ What did you expect to see?

The expectation would be for the tests to run in parallel without errors.

📦 Which tool/library version are you using?

node v22.11.0 "@cucumber/cucumber": "^9.6.0",

🔬 How could we reproduce it?

To reproduce you can see my repo: https://github.com/evertondanilo/cucumber-parallel-issue

📚 Any additional context?

No response

davidjgoss commented 1 week ago

Thanks for including the repro project @evertondanilo, that was really helpful.

I raised a PR on your repo with the fix https://github.com/evertondanilo/cucumber-parallel-issue/pull/1 - the issue was that the ts-node transpiler was registered in your configuration file. This file is only loaded in the parent/coordinator process, but is not loaded again in the child processes that get spawned for doing parallel execution. Moving this stuff to its own file and including it via the --require-module option makes it work consistently, as this gets done the same way on the coordinator and child processes.

I'll close this issue now, but will try to add some more explicit advice to the docs around this kind of thing.

evertondanilo commented 1 week ago

@davidjgoss works beautifully thanks