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
7 changes: 6 additions & 1 deletion lib/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,12 @@ class Codecept {
})
}

await loadTests(mocha)
// Worker threads pre-load and filter tests before run(); reloading duplicates Gherkin suites.
if (!mocha.suite.total()) {
await loadTests(mocha)
} else {
mocha.lazyLoadFiles(true)
}

return new Promise((resolve, reject) => {
const done = async (failures) => {
Expand Down
21 changes: 21 additions & 0 deletions test/data/sandbox/codecept.workers-gherkin.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export const config = {
tests: './workers-gherkin/_placeholder.js',
timeout: 10000,
output: './output',
helpers: {
BDD: {
require: './support/bdd_helper.js',
},
Workers: {
require: './workers_helper.js',
},
},
gherkin: {
features: './workers-gherkin/*.feature',
steps: ['./workers-gherkin/steps.js'],
},
include: {},
bootstrap: false,
mocha: {},
name: 'sandbox-workers-gherkin',
}
1 change: 1 addition & 0 deletions test/data/sandbox/workers-gherkin/_placeholder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Gherkin-only worker sandbox; JS tests path must exist for config.
4 changes: 4 additions & 0 deletions test/data/sandbox/workers-gherkin/single.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Feature: Worker gherkin single scenario

Scenario: runs once @worker_gherkin_once
Given I open a browser on a site
3 changes: 3 additions & 0 deletions test/data/sandbox/workers-gherkin/steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Given } from '../../../../lib/mocha/bdd.js'

Given('I open a browser on a site', () => {})
27 changes: 27 additions & 0 deletions test/unit/worker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,31 @@ describe('Workers', function () {
const actualFiles = testFiles.map(f => path.resolve(f))
expect(actualFiles).to.deep.equal(expectedFiles, 'loadTests() should preserve original glob order without sorting')
})

it('should run each assigned gherkin worker test once after pre-load', done => {
const workerConfig = {
by: 'test',
testConfig: './test/data/sandbox/codecept.workers-gherkin.conf.js',
options: {
grep: '@worker_gherkin_once',
},
}

let passedCount = 0
const workers = new Workers(1, workerConfig)

workers.on(event.test.passed, () => {
passedCount += 1
})

workers.run()

workers.on(event.all.result, result => {
expect(passedCount).to.equal(1)
expect(result.stats.tests).to.equal(1)
expect(result.stats.passes).to.equal(1)
done()
})
})

})
Loading