Skip to content

Commit 0b7105e

Browse files
committed
Fix worker test configuration and test root path
- Fixed Workers#_initWorkers to pass test root directory instead of config file path - Fixed 'should create worker by function' test to configure helpers via options - Fixed helper configurations in other worker tests - Test now passes consistently (483 passed, 5 failed, 16 skipped)
1 parent df91c21 commit 0b7105e

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

lib/workers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ class Workers extends EventEmitter {
315315
this.splitTestsByGroups(numberOfWorkers, config)
316316
// For function-based grouping, use the actual number of test groups created
317317
const actualNumberOfWorkers = isFunction(config.by) ? this.testGroups.length : numberOfWorkers
318-
this.workers = createWorkerObjects(this.testGroups, this.codecept.config, config.testConfig, config.options, config.selectedRuns)
318+
this.workers = createWorkerObjects(this.testGroups, this.codecept.config, getTestRoot(config.testConfig), config.options, config.selectedRuns)
319319
this.numberOfWorkers = this.workers.length
320320
}
321321

test/unit/worker_test.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@ describe('Workers', function () {
6060
const workerConfig = {
6161
by: createTestGroups,
6262
testConfig: './test/data/sandbox/codecept.customworker.js',
63+
options: {
64+
override: JSON.stringify({
65+
helpers: {
66+
FileSystem: {},
67+
Workers: {
68+
require: './workers_helper',
69+
},
70+
CustomWorkers: {
71+
require: './custom_worker_helper',
72+
},
73+
},
74+
}),
75+
},
6376
}
6477

6578
const workers = new Workers(-1, workerConfig)
6679

67-
for (const worker of workers.getWorkers()) {
68-
worker.addConfig({
69-
helpers: {
70-
FileSystem: {},
71-
Workers: {
72-
require: './custom_worker_helper.js',
73-
},
74-
},
75-
})
76-
}
77-
7880
workers.run()
7981

8082
workers.on(event.all.result, result => {
@@ -110,7 +112,7 @@ describe('Workers', function () {
110112
// Clean up event listeners
111113
workers.removeListener(event.test.failed, onTestFailed)
112114
workers.removeListener(event.test.passed, onTestPassed)
113-
115+
114116
// The main assertion is that workers ran and some tests failed (indicating they executed)
115117
expect(result.hasFailed).equal(true)
116118
// In test suite context, event counting has timing issues, but functionality works
@@ -141,7 +143,10 @@ describe('Workers', function () {
141143
helpers: {
142144
FileSystem: {},
143145
Workers: {
144-
require: './custom_worker_helper.js',
146+
require: './workers_helper',
147+
},
148+
CustomWorkers: {
149+
require: './custom_worker_helper',
145150
},
146151
},
147152
})
@@ -176,7 +181,10 @@ describe('Workers', function () {
176181
helpers: {
177182
FileSystem: {},
178183
Workers: {
179-
require: './custom_worker_helper.js',
184+
require: './workers_helper',
185+
},
186+
CustomWorkers: {
187+
require: './custom_worker_helper',
180188
},
181189
},
182190
})
@@ -233,7 +241,7 @@ describe('Workers', function () {
233241
testConfig: './test/data/sandbox/codecept.non-test-events-worker.js',
234242
}
235243

236-
let workers = new Workers(2, workerConfig)
244+
let workers = new Workers(2, workerConfig)
237245

238246
workers.run()
239247

0 commit comments

Comments
 (0)