Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let container = {
helpers: {},
support: {},
proxySupport: {},
proxySupportConfig: {}, // Track config used to create proxySupport
plugins: {},
actor: null,
/**
Expand Down Expand Up @@ -67,7 +68,8 @@ class Container {
container.support = {}
container.helpers = await createHelpers(config.helpers || {})
container.translation = await loadTranslation(config.translation || null, config.vocabularies || [])
container.proxySupport = createSupportObjects(config.include || {})
container.proxySupportConfig = config.include || {}
container.proxySupport = createSupportObjects(container.proxySupportConfig)
container.plugins = await createPlugins(config.plugins || {}, opts)
container.result = new Result()

Expand Down Expand Up @@ -207,8 +209,10 @@ class Container {

// If new support objects are added, update the proxy support
if (newContainer.support) {
const newProxySupport = createSupportObjects(newContainer.support)
container.proxySupport = { ...container.proxySupport, ...newProxySupport }
// Merge the new support config with existing config
container.proxySupportConfig = { ...container.proxySupportConfig, ...newContainer.support }
// Recreate the proxy with merged config
container.proxySupport = createSupportObjects(container.proxySupportConfig)
}

debug('appended', JSON.stringify(newContainer).slice(0, 300))
Expand All @@ -224,6 +228,7 @@ class Container {
static async clear(newHelpers = {}, newSupport = {}, newPlugins = {}) {
container.helpers = newHelpers
container.translation = await loadTranslation()
container.proxySupportConfig = newSupport
container.proxySupport = createSupportObjects(newSupport)
container.plugins = newPlugins
container.sharedKeys = new Set() // Clear shared keys
Expand Down
10 changes: 6 additions & 4 deletions lib/helper/REST.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,9 @@ class REST extends Helper {
}
}

if (this.options.onRequest) {
await this.options.onRequest(request)
const onRequest = this.options.onRequest || this.config.onRequest
if (onRequest) {
await onRequest(request)
}

try {
Expand Down Expand Up @@ -248,8 +249,9 @@ class REST extends Helper {
}
response = err.response
}
if (this.options.onResponse) {
await this.options.onResponse(response)
const onResponse = this.options.onResponse || this.config.onResponse
if (onResponse) {
await onResponse(response)
}
try {
this.options.prettyPrintJson ? this.debugSection('Response', beautify(JSON.stringify(response.data))) : this.debugSection('Response', JSON.stringify(response.data))
Expand Down
2 changes: 1 addition & 1 deletion lib/workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class Workers extends EventEmitter {
this.splitTestsByGroups(numberOfWorkers, config)
// For function-based grouping, use the actual number of test groups created
const actualNumberOfWorkers = isFunction(config.by) ? this.testGroups.length : numberOfWorkers
this.workers = createWorkerObjects(this.testGroups, this.codecept.config, config.testConfig, config.options, config.selectedRuns)
this.workers = createWorkerObjects(this.testGroups, this.codecept.config, getTestRoot(config.testConfig), config.options, config.selectedRuns)
this.numberOfWorkers = this.workers.length
}

Expand Down
38 changes: 23 additions & 15 deletions test/unit/worker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,23 @@ describe('Workers', function () {
const workerConfig = {
by: createTestGroups,
testConfig: './test/data/sandbox/codecept.customworker.js',
options: {
override: JSON.stringify({
helpers: {
FileSystem: {},
Workers: {
require: './workers_helper',
},
CustomWorkers: {
require: './custom_worker_helper',
},
},
}),
},
}

const workers = new Workers(-1, workerConfig)

for (const worker of workers.getWorkers()) {
worker.addConfig({
helpers: {
FileSystem: {},
Workers: {
require: './custom_worker_helper.js',
},
},
})
}

workers.run()

workers.on(event.all.result, result => {
Expand Down Expand Up @@ -110,7 +112,7 @@ describe('Workers', function () {
// Clean up event listeners
workers.removeListener(event.test.failed, onTestFailed)
workers.removeListener(event.test.passed, onTestPassed)

// The main assertion is that workers ran and some tests failed (indicating they executed)
expect(result.hasFailed).equal(true)
// In test suite context, event counting has timing issues, but functionality works
Expand Down Expand Up @@ -141,7 +143,10 @@ describe('Workers', function () {
helpers: {
FileSystem: {},
Workers: {
require: './custom_worker_helper.js',
require: './workers_helper',
},
CustomWorkers: {
require: './custom_worker_helper',
},
},
})
Expand Down Expand Up @@ -176,7 +181,10 @@ describe('Workers', function () {
helpers: {
FileSystem: {},
Workers: {
require: './custom_worker_helper.js',
require: './workers_helper',
},
CustomWorkers: {
require: './custom_worker_helper',
},
},
})
Expand Down Expand Up @@ -233,7 +241,7 @@ describe('Workers', function () {
testConfig: './test/data/sandbox/codecept.non-test-events-worker.js',
}

let workers = new Workers(2, workerConfig)
let workers = new Workers(2, workerConfig)

workers.run()

Expand Down