Skip to content

Commit 409bfec

Browse files
authored
[WIP] Fix and push failed unit tests (#5306)
1 parent 44002f3 commit 409bfec

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

lib/container.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let container = {
2222
helpers: {},
2323
support: {},
2424
proxySupport: {},
25+
proxySupportConfig: {}, // Track config used to create proxySupport
2526
plugins: {},
2627
actor: null,
2728
/**
@@ -67,7 +68,8 @@ class Container {
6768
container.support = {}
6869
container.helpers = await createHelpers(config.helpers || {})
6970
container.translation = await loadTranslation(config.translation || null, config.vocabularies || [])
70-
container.proxySupport = createSupportObjects(config.include || {})
71+
container.proxySupportConfig = config.include || {}
72+
container.proxySupport = createSupportObjects(container.proxySupportConfig)
7173
container.plugins = await createPlugins(config.plugins || {}, opts)
7274
container.result = new Result()
7375

@@ -207,8 +209,10 @@ class Container {
207209

208210
// If new support objects are added, update the proxy support
209211
if (newContainer.support) {
210-
const newProxySupport = createSupportObjects(newContainer.support)
211-
container.proxySupport = { ...container.proxySupport, ...newProxySupport }
212+
// Merge the new support config with existing config
213+
container.proxySupportConfig = { ...container.proxySupportConfig, ...newContainer.support }
214+
// Recreate the proxy with merged config
215+
container.proxySupport = createSupportObjects(container.proxySupportConfig)
212216
}
213217

214218
debug('appended', JSON.stringify(newContainer).slice(0, 300))
@@ -224,6 +228,7 @@ class Container {
224228
static async clear(newHelpers = {}, newSupport = {}, newPlugins = {}) {
225229
container.helpers = newHelpers
226230
container.translation = await loadTranslation()
231+
container.proxySupportConfig = newSupport
227232
container.proxySupport = createSupportObjects(newSupport)
228233
container.plugins = newPlugins
229234
container.sharedKeys = new Set() // Clear shared keys

lib/helper/REST.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ class REST extends Helper {
218218
}
219219
}
220220

221-
if (this.options.onRequest) {
222-
await this.options.onRequest(request)
221+
const onRequest = this.options.onRequest || this.config.onRequest
222+
if (onRequest) {
223+
await onRequest(request)
223224
}
224225

225226
try {
@@ -248,8 +249,9 @@ class REST extends Helper {
248249
}
249250
response = err.response
250251
}
251-
if (this.options.onResponse) {
252-
await this.options.onResponse(response)
252+
const onResponse = this.options.onResponse || this.config.onResponse
253+
if (onResponse) {
254+
await onResponse(response)
253255
}
254256
try {
255257
this.options.prettyPrintJson ? this.debugSection('Response', beautify(JSON.stringify(response.data))) : this.debugSection('Response', JSON.stringify(response.data))

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)