Skip to content

Commit 7cfb9b3

Browse files
committed
Using spawn tag to get errorOutput for warning validation
Explicit step definitions for parallel test verification
1 parent e512a2b commit 7cfb9b3

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

features/parallel_custom_assign.feature

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: Running scenarios in parallel with custom assignment
22

3+
@spawn
34
Scenario: Bad parallel assignment helper uses 1 worker
45
Given a file named "features/step_definitions/cucumber_steps.js" with:
56
"""
@@ -19,11 +20,11 @@ Feature: Running scenarios in parallel with custom assignment
1920
Then value is 2
2021
"""
2122
When I run cucumber-js with `--parallel 2`
22-
Then it passes
23-
And tandem tests verified
23+
Then the error output contains the text:
2424
"""
25-
expect.fail('No tests should have executed at the same time')
25+
WARNING: All workers went idle 2 time(s). Consider revising handler passed to setParallelCanAssign.
2626
"""
27+
And no tests ran in tandem
2728

2829
Scenario: Both works run tests when a valid assignment helper is used
2930
Given a file named "features/step_definitions/cucumber_steps.js" with:
@@ -132,7 +133,4 @@ Feature: Running scenarios in parallel with custom assignment
132133
"""
133134
When I run cucumber-js with `--parallel 2`
134135
Then it passes
135-
And tandem tests verified
136-
"""
137-
expect(_pickle1.tags[0].name).to.not.eq(_pickle2.tags[0].name)
138-
"""
136+
And tandem tests have unique first tag

features/step_definitions/parallel_steps.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ function parse(
4040
)
4141
}
4242

43+
function verifyTandem(
44+
assertion: (p1: messages.IPickle, p2: messages.IPickle) => void
45+
) {
46+
return function (this: World): void {
47+
const running = new Set<string>()
48+
const pickles: Dictionary<messages.IPickle> = {}
49+
const testCases: Dictionary<string> = {}
50+
const testStarts: Dictionary<string> = {}
51+
52+
const handlers = defaultHandlers({
53+
pickles,
54+
running,
55+
testCases,
56+
testStarts,
57+
})
58+
handlers.testCaseStarted = _.wrap(
59+
handlers.testCaseStarted,
60+
(fn, t: messages.TestCaseStarted) => {
61+
running.forEach((tcId) =>
62+
assertion(pickles[testCases[tcId]], pickles[testCases[t.testCaseId]])
63+
)
64+
fn(t)
65+
}
66+
)
67+
parse(this.lastRun.envelopes, handlers)
68+
}
69+
}
70+
4371
Then(/^it runs tests in order (.+)$/, function (this: World, order: string) {
4472
const running = new Set<string>()
4573
const pickles: Dictionary<messages.IPickle> = {}
@@ -52,31 +80,14 @@ Then(/^it runs tests in order (.+)$/, function (this: World, order: string) {
5280
parse(this.lastRun.envelopes, handlers)
5381
})
5482

55-
Then(/^tandem tests verified$/, function (this: World, assertion: string) {
56-
const running = new Set<string>()
57-
const pickles: Dictionary<messages.IPickle> = {}
58-
const testCases: Dictionary<string> = {}
59-
const testStarts: Dictionary<string> = {}
60-
const assertFn = (
61-
_pickle1: messages.IPickle,
62-
_pickle2: messages.IPickle
63-
): boolean => {
64-
// eslint-disable-next-line no-eval
65-
return eval(`
66-
const { expect } = require('chai')
67-
${assertion}
68-
`)
69-
}
70-
71-
const handlers = defaultHandlers({ pickles, running, testCases, testStarts })
72-
handlers.testCaseStarted = _.wrap(
73-
handlers.testCaseStarted,
74-
(fn, t: messages.TestCaseStarted) => {
75-
running.forEach((tcId) =>
76-
assertFn(pickles[testCases[tcId]], pickles[testCases[t.testCaseId]])
77-
)
78-
fn(t)
79-
}
83+
Then(
84+
/^no tests ran in tandem$/,
85+
verifyTandem(() =>
86+
expect.fail('No tests should have executed at the same time')
8087
)
81-
parse(this.lastRun.envelopes, handlers)
82-
})
88+
)
89+
90+
Then(
91+
/^tandem tests have unique first tag$/,
92+
verifyTandem((p1, p2) => expect(p1.tags[0].name).to.not.eq(p2.tags[0].name))
93+
)

0 commit comments

Comments
 (0)