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
1 change: 1 addition & 0 deletions lib/command/run-multiple.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function executeRun(runName, runConfig) {

// tweaking default output directories
overriddenConfig = replaceValueDeep(overriddenConfig, 'output', path.join(config.output, outputDir))
overriddenConfig = replaceValueDeep(overriddenConfig, 'reportDir', path.join(config.output, outputDir))
overriddenConfig = replaceValueDeep(overriddenConfig, 'mochaFile', path.join(config.output, outputDir, `${browserName}_report.xml`))

// override tests configuration
Expand Down
5 changes: 3 additions & 2 deletions lib/container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { globSync } from 'glob'
import path from 'path'
import fs from 'fs'
import { isMainThread } from 'worker_threads'
import debugModule from 'debug'
const debug = debugModule('codeceptjs:container')
import { MetaStep } from './step.js'
Expand Down Expand Up @@ -731,11 +732,11 @@ async function createPlugins(config, options = {}) {
const runInWorker = pluginConfig.runInWorker ?? pluginConfig.runInWorkers ?? (pluginName === 'testomatio' ? false : true)
const runInParent = pluginConfig.runInParent ?? pluginConfig.runInMain ?? true

if (options.child && !runInWorker) {
if (!isMainThread && !runInWorker) {
continue
}

if (!options.child && store.workerMode && !runInParent) {
if (isMainThread && store.workerMode && !runInParent) {
continue
}
let module
Expand Down
28 changes: 28 additions & 0 deletions test/data/sandbox/codecept.multiple.plugin.runInWorkerFalse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const config = {
tests: './*_test.multiple.js',
timeout: 10000,
output: './output',
helpers: {
FakeDriver: {
require: '../fake_driver',
browser: 'dummy',
windowSize: 'maximize',
},
},
multiple: {
default: {
browsers: ['chrome', 'firefox'],
},
},
plugins: {
runInWorkerFalsePlugin: {
enabled: true,
runInWorker: false,
require: './plugin-runInWorkerFalse.js',
reportDir: 'output/report',
},
},
bootstrap: false,
mocha: {},
name: 'sandbox',
}
6 changes: 6 additions & 0 deletions test/data/sandbox/plugin-runInWorkerFalse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function (config) {
process.stdout.write('plugin-runInWorkerFalse:loaded\n')
if (config.reportDir) {
process.stdout.write(`plugin-runInWorkerFalse:reportDir=${config.reportDir}\n`)
}
}
17 changes: 17 additions & 0 deletions test/runner/run_multiple_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ describe('CodeceptJS Multiple Runner', function () {
})
})

it('should load plugins with runInWorker:false in each child process and give each its own reportDir', done => {
exec(`${runner} run-multiple --config ${codecept_dir}/codecept.multiple.plugin.runInWorkerFalse.js default`, (err, stdout) => {
// Plugin must be initialised once per forked child (chrome + firefox = 2 times).
// Regression: in 4.x the plugin was silently skipped because options.child was
// truthy in run-multiple children, same as in worker threads.
;(stdout.match(/plugin-runInWorkerFalse:loaded/g) || []).should.have.lengthOf(2)
// reportDir must be replaced per child so each child writes its own report.
// Regression: run-multiple.js dropped the replaceValueDeep('reportDir', ...) call
// that was present in 3.x, causing all children to overwrite the same file.
const dirs = (stdout.match(/plugin-runInWorkerFalse:reportDir=(.+)/g) || []).map(m => m.split('=')[1])
dirs.should.have.lengthOf(2)
dirs[0].should.not.equal(dirs[1])
assert(!err)
done()
})
})

describe('bootstrapAll and teardownAll', () => {
const _codecept_run = `run-multiple --config ${codecept_dir}`
it('should be executed from async function in config', done => {
Expand Down