codeceptjs 4.0.0-beta.3 → 4.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -119
- package/bin/codecept.js +12 -2
- package/bin/test-server.js +53 -0
- package/docs/webapi/clearCookie.mustache +1 -1
- package/lib/actor.js +66 -102
- package/lib/ai.js +130 -121
- package/lib/assert/empty.js +3 -5
- package/lib/assert/equal.js +4 -7
- package/lib/assert/include.js +4 -6
- package/lib/assert/throws.js +2 -4
- package/lib/assert/truth.js +2 -2
- package/lib/codecept.js +141 -86
- package/lib/command/check.js +201 -0
- package/lib/command/configMigrate.js +2 -4
- package/lib/command/definitions.js +8 -26
- package/lib/command/dryRun.js +30 -35
- package/lib/command/generate.js +10 -14
- package/lib/command/gherkin/snippets.js +75 -73
- package/lib/command/gherkin/steps.js +1 -1
- package/lib/command/info.js +42 -8
- package/lib/command/init.js +13 -12
- package/lib/command/interactive.js +10 -2
- package/lib/command/list.js +1 -1
- package/lib/command/run-multiple/chunk.js +48 -45
- package/lib/command/run-multiple.js +12 -35
- package/lib/command/run-workers.js +21 -58
- package/lib/command/utils.js +5 -6
- package/lib/command/workers/runTests.js +263 -222
- package/lib/container.js +386 -238
- package/lib/data/context.js +10 -13
- package/lib/data/dataScenarioConfig.js +8 -8
- package/lib/data/dataTableArgument.js +6 -6
- package/lib/data/table.js +5 -11
- package/lib/effects.js +223 -0
- package/lib/element/WebElement.js +327 -0
- package/lib/els.js +158 -0
- package/lib/event.js +21 -17
- package/lib/heal.js +88 -80
- package/lib/helper/AI.js +2 -1
- package/lib/helper/ApiDataFactory.js +4 -7
- package/lib/helper/Appium.js +50 -57
- package/lib/helper/FileSystem.js +3 -3
- package/lib/helper/GraphQLDataFactory.js +4 -4
- package/lib/helper/JSONResponse.js +75 -37
- package/lib/helper/Mochawesome.js +31 -9
- package/lib/helper/Nightmare.js +37 -58
- package/lib/helper/Playwright.js +267 -272
- package/lib/helper/Protractor.js +56 -87
- package/lib/helper/Puppeteer.js +247 -264
- package/lib/helper/REST.js +29 -17
- package/lib/helper/TestCafe.js +22 -47
- package/lib/helper/WebDriver.js +157 -368
- package/lib/helper/extras/PlaywrightPropEngine.js +2 -2
- package/lib/helper/extras/Popup.js +22 -22
- package/lib/helper/network/utils.js +1 -1
- package/lib/helper/testcafe/testcafe-utils.js +27 -28
- package/lib/listener/emptyRun.js +55 -0
- package/lib/listener/exit.js +7 -10
- package/lib/listener/{retry.js → globalRetry.js} +5 -5
- package/lib/listener/globalTimeout.js +165 -0
- package/lib/listener/helpers.js +15 -15
- package/lib/listener/mocha.js +1 -1
- package/lib/listener/result.js +12 -0
- package/lib/listener/retryEnhancer.js +85 -0
- package/lib/listener/steps.js +32 -18
- package/lib/listener/store.js +20 -0
- package/lib/locator.js +1 -1
- package/lib/mocha/asyncWrapper.js +231 -0
- package/lib/{interfaces → mocha}/bdd.js +3 -3
- package/lib/mocha/cli.js +308 -0
- package/lib/mocha/factory.js +104 -0
- package/lib/{interfaces → mocha}/featureConfig.js +32 -12
- package/lib/{interfaces → mocha}/gherkin.js +26 -28
- package/lib/mocha/hooks.js +112 -0
- package/lib/mocha/index.js +12 -0
- package/lib/mocha/inject.js +29 -0
- package/lib/{interfaces → mocha}/scenarioConfig.js +31 -7
- package/lib/mocha/suite.js +82 -0
- package/lib/mocha/test.js +181 -0
- package/lib/mocha/types.d.ts +42 -0
- package/lib/mocha/ui.js +232 -0
- package/lib/output.js +93 -65
- package/lib/pause.js +160 -138
- package/lib/plugin/analyze.js +396 -0
- package/lib/plugin/auth.js +435 -0
- package/lib/plugin/autoDelay.js +8 -8
- package/lib/plugin/autoLogin.js +3 -338
- package/lib/plugin/commentStep.js +6 -1
- package/lib/plugin/coverage.js +10 -22
- package/lib/plugin/customLocator.js +3 -3
- package/lib/plugin/customReporter.js +52 -0
- package/lib/plugin/eachElement.js +1 -1
- package/lib/plugin/fakerTransform.js +1 -1
- package/lib/plugin/heal.js +36 -9
- package/lib/plugin/htmlReporter.js +1947 -0
- package/lib/plugin/pageInfo.js +140 -0
- package/lib/plugin/retryFailedStep.js +17 -18
- package/lib/plugin/retryTo.js +2 -113
- package/lib/plugin/screenshotOnFail.js +17 -58
- package/lib/plugin/selenoid.js +15 -35
- package/lib/plugin/standardActingHelpers.js +4 -1
- package/lib/plugin/stepByStepReport.js +56 -17
- package/lib/plugin/stepTimeout.js +5 -12
- package/lib/plugin/subtitles.js +4 -4
- package/lib/plugin/tryTo.js +3 -102
- package/lib/plugin/wdio.js +8 -10
- package/lib/recorder.js +155 -124
- package/lib/rerun.js +43 -42
- package/lib/result.js +161 -0
- package/lib/secret.js +1 -2
- package/lib/step/base.js +239 -0
- package/lib/step/comment.js +10 -0
- package/lib/step/config.js +50 -0
- package/lib/step/func.js +46 -0
- package/lib/step/helper.js +50 -0
- package/lib/step/meta.js +99 -0
- package/lib/step/record.js +74 -0
- package/lib/step/retry.js +11 -0
- package/lib/step/section.js +55 -0
- package/lib/step.js +21 -332
- package/lib/steps.js +50 -0
- package/lib/store.js +37 -5
- package/lib/template/heal.js +2 -11
- package/lib/test-server.js +323 -0
- package/lib/timeout.js +66 -0
- package/lib/utils.js +351 -218
- package/lib/within.js +75 -55
- package/lib/workerStorage.js +2 -1
- package/lib/workers.js +386 -277
- package/package.json +81 -75
- package/translations/de-DE.js +5 -3
- package/translations/fr-FR.js +5 -4
- package/translations/index.js +1 -0
- package/translations/it-IT.js +4 -3
- package/translations/ja-JP.js +4 -3
- package/translations/nl-NL.js +76 -0
- package/translations/pl-PL.js +4 -3
- package/translations/pt-BR.js +4 -3
- package/translations/ru-RU.js +4 -3
- package/translations/utils.js +9 -0
- package/translations/zh-CN.js +4 -3
- package/translations/zh-TW.js +4 -3
- package/typings/index.d.ts +197 -187
- package/typings/promiseBasedTypes.d.ts +53 -903
- package/typings/types.d.ts +372 -1042
- package/lib/cli.js +0 -257
- package/lib/helper/ExpectHelper.js +0 -391
- package/lib/helper/MockServer.js +0 -221
- package/lib/helper/SoftExpectHelper.js +0 -381
- package/lib/listener/artifacts.js +0 -19
- package/lib/listener/timeout.js +0 -109
- package/lib/mochaFactory.js +0 -113
- package/lib/plugin/debugErrors.js +0 -67
- package/lib/scenario.js +0 -224
- package/lib/ui.js +0 -236
|
@@ -1,292 +1,333 @@
|
|
|
1
|
-
const tty = require('tty')
|
|
1
|
+
const tty = require('tty')
|
|
2
2
|
|
|
3
3
|
if (!tty.getWindowSize) {
|
|
4
4
|
// this is really old method, long removed from Node, but Mocha
|
|
5
5
|
// reporters fall back on it if they cannot use `process.stdout.getWindowSize`
|
|
6
6
|
// we need to polyfill it.
|
|
7
|
-
tty.getWindowSize = () => [40, 80]
|
|
7
|
+
tty.getWindowSize = () => [40, 80]
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
const { parentPort, workerData } = require('worker_threads')
|
|
11
|
-
const event = require('../../event')
|
|
12
|
-
const container = require('../../container')
|
|
13
|
-
const { getConfig } = require('../utils')
|
|
14
|
-
const { tryOrDefault, deepMerge } = require('../../utils')
|
|
10
|
+
const { parentPort, workerData } = require('worker_threads')
|
|
11
|
+
const event = require('../../event')
|
|
12
|
+
const container = require('../../container')
|
|
13
|
+
const { getConfig } = require('../utils')
|
|
14
|
+
const { tryOrDefault, deepMerge } = require('../../utils')
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const stderr = '';
|
|
16
|
+
let stdout = ''
|
|
17
|
+
|
|
18
|
+
const stderr = ''
|
|
20
19
|
|
|
21
20
|
// Requiring of Codecept need to be after tty.getWindowSize is available.
|
|
22
|
-
const Codecept = require(process.env.CODECEPT_CLASS_PATH || '../../codecept')
|
|
21
|
+
const Codecept = require(process.env.CODECEPT_CLASS_PATH || '../../codecept')
|
|
23
22
|
|
|
24
|
-
const {
|
|
25
|
-
options, tests, testRoot, workerIndex,
|
|
26
|
-
} = workerData;
|
|
23
|
+
const { options, tests, testRoot, workerIndex, poolMode } = workerData
|
|
27
24
|
|
|
28
25
|
// hide worker output
|
|
29
|
-
if (!options.debug && !options.verbose)
|
|
26
|
+
if (!options.debug && !options.verbose)
|
|
27
|
+
process.stdout.write = string => {
|
|
28
|
+
stdout += string
|
|
29
|
+
return true
|
|
30
|
+
}
|
|
30
31
|
|
|
31
|
-
const overrideConfigs = tryOrDefault(() => JSON.parse(options.override), {})
|
|
32
|
+
const overrideConfigs = tryOrDefault(() => JSON.parse(options.override), {})
|
|
32
33
|
|
|
33
34
|
// important deep merge so dynamic things e.g. functions on config are not overridden
|
|
34
|
-
const config = deepMerge(getConfig(options.config || testRoot), overrideConfigs)
|
|
35
|
+
const config = deepMerge(getConfig(options.config || testRoot), overrideConfigs)
|
|
35
36
|
|
|
36
37
|
// Load test and run
|
|
37
|
-
const codecept = new Codecept(config, options)
|
|
38
|
-
codecept.init(testRoot)
|
|
39
|
-
codecept.loadTests()
|
|
40
|
-
const mocha = container.mocha()
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
const codecept = new Codecept(config, options)
|
|
39
|
+
codecept.init(testRoot)
|
|
40
|
+
codecept.loadTests()
|
|
41
|
+
const mocha = container.mocha()
|
|
42
|
+
|
|
43
|
+
if (poolMode) {
|
|
44
|
+
// In pool mode, don't filter tests upfront - wait for assignments
|
|
45
|
+
// We'll reload test files fresh for each test request
|
|
46
|
+
} else {
|
|
47
|
+
// Legacy mode - filter tests upfront
|
|
48
|
+
filterTests()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// run tests
|
|
52
|
+
;(async function () {
|
|
53
|
+
if (poolMode) {
|
|
54
|
+
await runPoolTests()
|
|
55
|
+
} else if (mocha.suite.total()) {
|
|
56
|
+
await runTests()
|
|
46
57
|
}
|
|
47
|
-
}()
|
|
58
|
+
})()
|
|
59
|
+
|
|
60
|
+
let globalStats = { passes: 0, failures: 0, tests: 0, pending: 0, failedHooks: 0 }
|
|
48
61
|
|
|
49
62
|
async function runTests() {
|
|
50
63
|
try {
|
|
51
|
-
await codecept.bootstrap()
|
|
64
|
+
await codecept.bootstrap()
|
|
52
65
|
} catch (err) {
|
|
53
|
-
throw new Error(`Error while running bootstrap file :${err}`)
|
|
66
|
+
throw new Error(`Error while running bootstrap file :${err}`)
|
|
54
67
|
}
|
|
55
|
-
listenToParentThread()
|
|
56
|
-
initializeListeners()
|
|
57
|
-
disablePause()
|
|
68
|
+
listenToParentThread()
|
|
69
|
+
initializeListeners()
|
|
70
|
+
disablePause()
|
|
58
71
|
try {
|
|
59
|
-
await codecept.run()
|
|
72
|
+
await codecept.run()
|
|
60
73
|
} finally {
|
|
61
|
-
await codecept.teardown()
|
|
74
|
+
await codecept.teardown()
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
for (const suite of mocha.suite.suites) {
|
|
71
|
-
suite.tests = suite.tests.filter(test => tests.indexOf(test.uid) >= 0);
|
|
78
|
+
async function runPoolTests() {
|
|
79
|
+
try {
|
|
80
|
+
await codecept.bootstrap()
|
|
81
|
+
} catch (err) {
|
|
82
|
+
throw new Error(`Error while running bootstrap file :${err}`)
|
|
72
83
|
}
|
|
73
|
-
}
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
initializeListeners()
|
|
86
|
+
disablePause()
|
|
87
|
+
|
|
88
|
+
// Accumulate results across all tests in pool mode
|
|
89
|
+
let consolidatedStats = { passes: 0, failures: 0, tests: 0, pending: 0, failedHooks: 0 }
|
|
90
|
+
let allTests = []
|
|
91
|
+
let allFailures = []
|
|
92
|
+
let previousStats = { passes: 0, failures: 0, tests: 0, pending: 0, failedHooks: 0 }
|
|
93
|
+
|
|
94
|
+
// Keep requesting tests until no more available
|
|
95
|
+
while (true) {
|
|
96
|
+
// Request a test assignment
|
|
97
|
+
sendToParentThread({ type: 'REQUEST_TEST', workerIndex })
|
|
98
|
+
|
|
99
|
+
const testResult = await new Promise((resolve, reject) => {
|
|
100
|
+
// Set up pool mode message handler
|
|
101
|
+
const messageHandler = async eventData => {
|
|
102
|
+
if (eventData.type === 'TEST_ASSIGNED') {
|
|
103
|
+
const testUid = eventData.test
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
// In pool mode, we need to create a fresh Mocha instance for each test
|
|
107
|
+
// because Mocha instances become disposed after running tests
|
|
108
|
+
container.createMocha() // Create fresh Mocha instance
|
|
109
|
+
filterTestById(testUid)
|
|
110
|
+
const mocha = container.mocha()
|
|
111
|
+
|
|
112
|
+
if (mocha.suite.total() > 0) {
|
|
113
|
+
// Run the test and complete
|
|
114
|
+
await codecept.run()
|
|
115
|
+
|
|
116
|
+
// Get the results from this specific test run
|
|
117
|
+
const result = container.result()
|
|
118
|
+
const currentStats = result.stats || {}
|
|
119
|
+
|
|
120
|
+
// Calculate the difference from previous accumulated stats
|
|
121
|
+
const newPasses = Math.max(0, (currentStats.passes || 0) - previousStats.passes)
|
|
122
|
+
const newFailures = Math.max(0, (currentStats.failures || 0) - previousStats.failures)
|
|
123
|
+
const newTests = Math.max(0, (currentStats.tests || 0) - previousStats.tests)
|
|
124
|
+
const newPending = Math.max(0, (currentStats.pending || 0) - previousStats.pending)
|
|
125
|
+
const newFailedHooks = Math.max(0, (currentStats.failedHooks || 0) - previousStats.failedHooks)
|
|
126
|
+
|
|
127
|
+
// Add only the new results
|
|
128
|
+
consolidatedStats.passes += newPasses
|
|
129
|
+
consolidatedStats.failures += newFailures
|
|
130
|
+
consolidatedStats.tests += newTests
|
|
131
|
+
consolidatedStats.pending += newPending
|
|
132
|
+
consolidatedStats.failedHooks += newFailedHooks
|
|
133
|
+
|
|
134
|
+
// Update previous stats for next comparison
|
|
135
|
+
previousStats = { ...currentStats }
|
|
136
|
+
|
|
137
|
+
// Add new failures to consolidated collections
|
|
138
|
+
if (result.failures && result.failures.length > allFailures.length) {
|
|
139
|
+
const newFailures = result.failures.slice(allFailures.length)
|
|
140
|
+
allFailures.push(...newFailures)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Signal test completed and request next
|
|
145
|
+
parentPort?.off('message', messageHandler)
|
|
146
|
+
resolve('TEST_COMPLETED')
|
|
147
|
+
} catch (err) {
|
|
148
|
+
parentPort?.off('message', messageHandler)
|
|
149
|
+
reject(err)
|
|
150
|
+
}
|
|
151
|
+
} else if (eventData.type === 'NO_MORE_TESTS') {
|
|
152
|
+
// No tests available, exit worker
|
|
153
|
+
parentPort?.off('message', messageHandler)
|
|
154
|
+
resolve('NO_MORE_TESTS')
|
|
155
|
+
} else {
|
|
156
|
+
// Handle other message types (support messages, etc.)
|
|
157
|
+
container.append({ support: eventData.data })
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
parentPort?.on('message', messageHandler)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
// Exit if no more tests
|
|
165
|
+
if (testResult === 'NO_MORE_TESTS') {
|
|
166
|
+
break
|
|
93
167
|
}
|
|
168
|
+
}
|
|
94
169
|
|
|
95
|
-
|
|
170
|
+
try {
|
|
171
|
+
await codecept.teardown()
|
|
172
|
+
} catch (err) {
|
|
173
|
+
// Log teardown errors but don't fail
|
|
174
|
+
console.error('Teardown error:', err)
|
|
96
175
|
}
|
|
97
|
-
function simplifyTest(test, err = null) {
|
|
98
|
-
test = { ...test };
|
|
99
176
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
177
|
+
// Send final consolidated results for the entire worker
|
|
178
|
+
const finalResult = {
|
|
179
|
+
hasFailed: consolidatedStats.failures > 0,
|
|
180
|
+
stats: consolidatedStats,
|
|
181
|
+
duration: 0, // Pool mode doesn't track duration per worker
|
|
182
|
+
tests: [], // Keep tests empty to avoid serialization issues - stats are sufficient
|
|
183
|
+
failures: allFailures, // Include all failures for error reporting
|
|
184
|
+
}
|
|
104
185
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
test.status = 'failed';
|
|
108
|
-
} else if (err) {
|
|
109
|
-
err = simplifyError(err);
|
|
110
|
-
test.status = 'failed';
|
|
111
|
-
}
|
|
112
|
-
const parent = {};
|
|
113
|
-
if (test.parent) {
|
|
114
|
-
parent.title = test.parent.title;
|
|
115
|
-
}
|
|
186
|
+
sendToParentThread({ event: event.all.after, workerIndex, data: finalResult })
|
|
187
|
+
sendToParentThread({ event: event.all.result, workerIndex, data: finalResult })
|
|
116
188
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (typeof test.opts[k] === 'object') delete test.opts[k];
|
|
120
|
-
if (typeof test.opts[k] === 'function') delete test.opts[k];
|
|
121
|
-
});
|
|
122
|
-
}
|
|
189
|
+
// Add longer delay to ensure messages are delivered before closing
|
|
190
|
+
await new Promise(resolve => setTimeout(resolve, 100))
|
|
123
191
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
uid: test.uid,
|
|
128
|
-
workerIndex,
|
|
129
|
-
retries: test._retries,
|
|
130
|
-
title: test.title,
|
|
131
|
-
status: test.status,
|
|
132
|
-
duration: test.duration || 0,
|
|
133
|
-
err,
|
|
134
|
-
parent,
|
|
135
|
-
steps: test.steps && test.steps.length > 0 ? simplifyStepsInTestObject(test.steps, err) : [],
|
|
136
|
-
};
|
|
137
|
-
}
|
|
192
|
+
// Close worker thread when pool mode is complete
|
|
193
|
+
parentPort?.close()
|
|
194
|
+
}
|
|
138
195
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
for (step of steps) {
|
|
144
|
-
const _args = [];
|
|
145
|
-
|
|
146
|
-
if (step.args) {
|
|
147
|
-
for (const arg of step.args) {
|
|
148
|
-
// check if arg is a JOI object
|
|
149
|
-
if (arg && arg.$_root) {
|
|
150
|
-
_args.push(JSON.stringify(arg).slice(0, 300));
|
|
151
|
-
// check if arg is a function
|
|
152
|
-
} else if (arg && typeof arg === 'function') {
|
|
153
|
-
_args.push(arg.name);
|
|
154
|
-
} else {
|
|
155
|
-
_args.push(arg);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
196
|
+
function filterTestById(testUid) {
|
|
197
|
+
// Reload test files fresh for each test in pool mode
|
|
198
|
+
const files = codecept.testFiles
|
|
159
199
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
name: step.name,
|
|
163
|
-
status: step.status,
|
|
164
|
-
args: JSON.stringify(_args),
|
|
165
|
-
startedAt: step.startedAt,
|
|
166
|
-
startTime: step.startTime,
|
|
167
|
-
endTime: step.endTime,
|
|
168
|
-
finishedAt: step.finishedAt,
|
|
169
|
-
duration: step.duration,
|
|
170
|
-
err,
|
|
171
|
-
});
|
|
172
|
-
}
|
|
200
|
+
// Get the existing mocha instance
|
|
201
|
+
const mocha = container.mocha()
|
|
173
202
|
|
|
174
|
-
|
|
175
|
-
|
|
203
|
+
// Clear suites and tests but preserve other mocha settings
|
|
204
|
+
mocha.suite.suites = []
|
|
205
|
+
mocha.suite.tests = []
|
|
176
206
|
|
|
177
|
-
|
|
178
|
-
|
|
207
|
+
// Clear require cache for test files to ensure fresh loading
|
|
208
|
+
files.forEach(file => {
|
|
209
|
+
delete require.cache[require.resolve(file)]
|
|
210
|
+
})
|
|
179
211
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
212
|
+
// Set files and load them
|
|
213
|
+
mocha.files = files
|
|
214
|
+
mocha.loadFiles()
|
|
184
215
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
216
|
+
// Now filter to only the target test - use a more robust approach
|
|
217
|
+
let foundTest = false
|
|
218
|
+
for (const suite of mocha.suite.suites) {
|
|
219
|
+
const originalTests = [...suite.tests]
|
|
220
|
+
suite.tests = []
|
|
221
|
+
|
|
222
|
+
for (const test of originalTests) {
|
|
223
|
+
if (test.uid === testUid) {
|
|
224
|
+
suite.tests.push(test)
|
|
225
|
+
foundTest = true
|
|
226
|
+
break // Only add one matching test
|
|
227
|
+
}
|
|
191
228
|
}
|
|
192
229
|
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
parent.
|
|
230
|
+
// If no tests found in this suite, remove it
|
|
231
|
+
if (suite.tests.length === 0) {
|
|
232
|
+
suite.parent.suites = suite.parent.suites.filter(s => s !== suite)
|
|
196
233
|
}
|
|
234
|
+
}
|
|
197
235
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
236
|
+
// Filter out empty suites from the root
|
|
237
|
+
mocha.suite.suites = mocha.suite.suites.filter(suite => suite.tests.length > 0)
|
|
238
|
+
|
|
239
|
+
if (!foundTest) {
|
|
240
|
+
// If testUid doesn't match, maybe it's a simple test name - try fallback
|
|
241
|
+
mocha.suite.suites = []
|
|
242
|
+
mocha.suite.tests = []
|
|
243
|
+
mocha.loadFiles()
|
|
244
|
+
|
|
245
|
+
// Try matching by title
|
|
246
|
+
for (const suite of mocha.suite.suites) {
|
|
247
|
+
const originalTests = [...suite.tests]
|
|
248
|
+
suite.tests = []
|
|
249
|
+
|
|
250
|
+
for (const test of originalTests) {
|
|
251
|
+
if (test.title === testUid || test.fullTitle() === testUid || test.uid === testUid) {
|
|
252
|
+
suite.tests.push(test)
|
|
253
|
+
foundTest = true
|
|
254
|
+
break
|
|
255
|
+
}
|
|
256
|
+
}
|
|
203
257
|
}
|
|
204
258
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
259
|
+
// Clean up empty suites again
|
|
260
|
+
mocha.suite.suites = mocha.suite.suites.filter(suite => suite.tests.length > 0)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function filterTests() {
|
|
265
|
+
const files = codecept.testFiles
|
|
266
|
+
mocha.files = files
|
|
267
|
+
mocha.loadFiles()
|
|
268
|
+
|
|
269
|
+
for (const suite of mocha.suite.suites) {
|
|
270
|
+
suite.tests = suite.tests.filter(test => tests.indexOf(test.uid) >= 0)
|
|
215
271
|
}
|
|
272
|
+
}
|
|
216
273
|
|
|
217
|
-
|
|
274
|
+
function initializeListeners() {
|
|
218
275
|
// suite
|
|
219
|
-
event.dispatcher.on(event.suite.before, suite => sendToParentThread({ event: event.suite.before, workerIndex, data:
|
|
220
|
-
event.dispatcher.on(event.suite.after, suite => sendToParentThread({ event: event.suite.after, workerIndex, data:
|
|
276
|
+
event.dispatcher.on(event.suite.before, suite => sendToParentThread({ event: event.suite.before, workerIndex, data: suite.simplify() }))
|
|
277
|
+
event.dispatcher.on(event.suite.after, suite => sendToParentThread({ event: event.suite.after, workerIndex, data: suite.simplify() }))
|
|
221
278
|
|
|
222
279
|
// calculate duration
|
|
223
|
-
event.dispatcher.on(event.test.started, test => test.start = new Date())
|
|
280
|
+
event.dispatcher.on(event.test.started, test => (test.start = new Date()))
|
|
224
281
|
|
|
225
282
|
// tests
|
|
226
|
-
event.dispatcher.on(event.test.before, test => sendToParentThread({ event: event.test.before, workerIndex, data:
|
|
227
|
-
event.dispatcher.on(event.test.after, test => sendToParentThread({ event: event.test.after, workerIndex, data:
|
|
283
|
+
event.dispatcher.on(event.test.before, test => sendToParentThread({ event: event.test.before, workerIndex, data: test.simplify() }))
|
|
284
|
+
event.dispatcher.on(event.test.after, test => sendToParentThread({ event: event.test.after, workerIndex, data: test.simplify() }))
|
|
228
285
|
// we should force-send correct errors to prevent race condition
|
|
229
|
-
event.dispatcher.on(event.test.finished, (test, err) => sendToParentThread({ event: event.test.finished, workerIndex, data:
|
|
230
|
-
event.dispatcher.on(event.test.failed, (test, err) => sendToParentThread({ event: event.test.failed, workerIndex, data:
|
|
231
|
-
event.dispatcher.on(event.test.passed, (test, err) => sendToParentThread({ event: event.test.passed, workerIndex, data:
|
|
232
|
-
event.dispatcher.on(event.test.started, test => sendToParentThread({ event: event.test.started, workerIndex, data:
|
|
233
|
-
event.dispatcher.on(event.test.skipped, test => sendToParentThread({ event: event.test.skipped, workerIndex, data:
|
|
286
|
+
event.dispatcher.on(event.test.finished, (test, err) => sendToParentThread({ event: event.test.finished, workerIndex, data: { ...test.simplify(), err } }))
|
|
287
|
+
event.dispatcher.on(event.test.failed, (test, err) => sendToParentThread({ event: event.test.failed, workerIndex, data: { ...test.simplify(), err } }))
|
|
288
|
+
event.dispatcher.on(event.test.passed, (test, err) => sendToParentThread({ event: event.test.passed, workerIndex, data: { ...test.simplify(), err } }))
|
|
289
|
+
event.dispatcher.on(event.test.started, test => sendToParentThread({ event: event.test.started, workerIndex, data: test.simplify() }))
|
|
290
|
+
event.dispatcher.on(event.test.skipped, test => sendToParentThread({ event: event.test.skipped, workerIndex, data: test.simplify() }))
|
|
234
291
|
|
|
235
292
|
// steps
|
|
236
|
-
event.dispatcher.on(event.step.finished, step => sendToParentThread({ event: event.step.finished, workerIndex, data:
|
|
237
|
-
event.dispatcher.on(event.step.started, step => sendToParentThread({ event: event.step.started, workerIndex, data:
|
|
238
|
-
event.dispatcher.on(event.step.passed, step => sendToParentThread({ event: event.step.passed, workerIndex, data:
|
|
239
|
-
event.dispatcher.on(event.step.failed, step => sendToParentThread({ event: event.step.failed, workerIndex, data:
|
|
240
|
-
|
|
241
|
-
event.dispatcher.on(event.hook.failed, (
|
|
242
|
-
event.dispatcher.on(event.hook.passed,
|
|
243
|
-
event.dispatcher.on(event.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
293
|
+
event.dispatcher.on(event.step.finished, step => sendToParentThread({ event: event.step.finished, workerIndex, data: step.simplify() }))
|
|
294
|
+
event.dispatcher.on(event.step.started, step => sendToParentThread({ event: event.step.started, workerIndex, data: step.simplify() }))
|
|
295
|
+
event.dispatcher.on(event.step.passed, step => sendToParentThread({ event: event.step.passed, workerIndex, data: step.simplify() }))
|
|
296
|
+
event.dispatcher.on(event.step.failed, step => sendToParentThread({ event: event.step.failed, workerIndex, data: step.simplify() }))
|
|
297
|
+
|
|
298
|
+
event.dispatcher.on(event.hook.failed, (hook, err) => sendToParentThread({ event: event.hook.failed, workerIndex, data: { ...hook.simplify(), err } }))
|
|
299
|
+
event.dispatcher.on(event.hook.passed, hook => sendToParentThread({ event: event.hook.passed, workerIndex, data: hook.simplify() }))
|
|
300
|
+
event.dispatcher.on(event.hook.finished, hook => sendToParentThread({ event: event.hook.finished, workerIndex, data: hook.simplify() }))
|
|
301
|
+
|
|
302
|
+
if (!poolMode) {
|
|
303
|
+
// In regular mode, close worker after all tests are complete
|
|
304
|
+
event.dispatcher.once(event.all.after, () => {
|
|
305
|
+
sendToParentThread({ event: event.all.after, workerIndex, data: container.result().simplify() })
|
|
306
|
+
})
|
|
307
|
+
// all
|
|
308
|
+
event.dispatcher.once(event.all.result, () => {
|
|
309
|
+
sendToParentThread({ event: event.all.result, workerIndex, data: container.result().simplify() })
|
|
310
|
+
parentPort?.close()
|
|
311
|
+
})
|
|
312
|
+
} else {
|
|
313
|
+
// In pool mode, don't send result events for individual tests
|
|
314
|
+
// Results will be sent once when the worker completes all tests
|
|
315
|
+
}
|
|
247
316
|
}
|
|
248
317
|
|
|
249
318
|
function disablePause() {
|
|
250
|
-
global.pause = () => {}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function collectStats() {
|
|
254
|
-
const stats = {
|
|
255
|
-
passes: 0,
|
|
256
|
-
failures: 0,
|
|
257
|
-
skipped: 0,
|
|
258
|
-
tests: 0,
|
|
259
|
-
pending: 0,
|
|
260
|
-
};
|
|
261
|
-
event.dispatcher.on(event.test.skipped, () => {
|
|
262
|
-
stats.skipped++;
|
|
263
|
-
});
|
|
264
|
-
event.dispatcher.on(event.test.passed, () => {
|
|
265
|
-
stats.passes++;
|
|
266
|
-
});
|
|
267
|
-
event.dispatcher.on(event.test.failed, (test) => {
|
|
268
|
-
if (test.ctx._runnable.title.includes('hook: AfterSuite')) {
|
|
269
|
-
stats.failedHooks += 1;
|
|
270
|
-
}
|
|
271
|
-
stats.failures++;
|
|
272
|
-
});
|
|
273
|
-
event.dispatcher.on(event.test.skipped, () => {
|
|
274
|
-
stats.pending++;
|
|
275
|
-
});
|
|
276
|
-
event.dispatcher.on(event.test.finished, () => {
|
|
277
|
-
stats.tests++;
|
|
278
|
-
});
|
|
279
|
-
event.dispatcher.once(event.all.after, () => {
|
|
280
|
-
sendToParentThread({ event: event.all.after, data: stats });
|
|
281
|
-
});
|
|
319
|
+
global.pause = () => {}
|
|
282
320
|
}
|
|
283
321
|
|
|
284
322
|
function sendToParentThread(data) {
|
|
285
|
-
parentPort
|
|
323
|
+
parentPort?.postMessage(data)
|
|
286
324
|
}
|
|
287
325
|
|
|
288
326
|
function listenToParentThread() {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
327
|
+
if (!poolMode) {
|
|
328
|
+
parentPort?.on('message', eventData => {
|
|
329
|
+
container.append({ support: eventData.data })
|
|
330
|
+
})
|
|
331
|
+
}
|
|
332
|
+
// In pool mode, message handling is done in runPoolTests()
|
|
292
333
|
}
|