Skip to content

Commit 51c7fdc

Browse files
authored
Merge branch 'codeceptjs:3.x' into patch-9
2 parents 886bbe7 + f55a991 commit 51c7fdc

21 files changed

+175
-217
lines changed

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ updates:
55
directory: '/'
66
schedule:
77
interval: 'weekly'
8-
target-branch: '3.x'
8+
target-branch: '4.x'
99
# npm
1010
- package-ecosystem: 'npm'
1111
directory: '/'
1212
schedule:
1313
interval: 'weekly'
14-
target-branch: '3.x'
14+
target-branch: '4.x'
1515
ignore:
1616
- dependency-name: 'escape-string-regexp'
1717
versions: ['>=5.0']

docs/parallel.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,23 @@ npx codeceptjs run-workers --suites 2
9595
CodeceptJS supports three different strategies for distributing tests across workers:
9696

9797
#### Default Strategy (`--by test`)
98+
9899
Tests are pre-assigned to workers at startup, distributing them evenly across all workers. Each worker gets a predetermined set of tests to run.
99100

100101
```sh
101102
npx codeceptjs run-workers 3 --by test
102103
```
103104

104105
#### Suite Strategy (`--by suite`)
106+
105107
Test suites are pre-assigned to workers, with all tests in a suite running on the same worker. This ensures better test isolation but may lead to uneven load distribution.
106108

107109
```sh
108110
npx codeceptjs run-workers 3 --by suite
109111
```
110112

111113
#### Pool Strategy (`--by pool`) - **Recommended for optimal performance**
114+
112115
Tests are maintained in a shared pool and distributed dynamically to workers as they become available. This provides the best load balancing and resource utilization.
113116

114117
```sh
@@ -121,19 +124,19 @@ The pool mode enables dynamic test distribution for improved worker load balanci
121124

122125
### Benefits of Pool Mode
123126

124-
* **Better load balancing**: Workers never sit idle while others are still running long tests
125-
* **Improved performance**: Especially beneficial when tests have varying execution times
126-
* **Optimal resource utilization**: All CPU cores stay busy until the entire test suite is complete
127-
* **Automatic scaling**: Workers continuously process tests until the pool is empty
127+
- **Better load balancing**: Workers never sit idle while others are still running long tests
128+
- **Improved performance**: Especially beneficial when tests have varying execution times
129+
- **Optimal resource utilization**: All CPU cores stay busy until the entire test suite is complete
130+
- **Automatic scaling**: Workers continuously process tests until the pool is empty
128131

129132
### When to Use Pool Mode
130133

131134
Pool mode is particularly effective in these scenarios:
132135

133-
* **Uneven test execution times**: When some tests take significantly longer than others
134-
* **Large test suites**: With hundreds or thousands of tests where load balancing matters
135-
* **Mixed test types**: When combining unit tests, integration tests, and end-to-end tests
136-
* **CI/CD pipelines**: For consistent and predictable test execution times
136+
- **Uneven test execution times**: When some tests take significantly longer than others
137+
- **Large test suites**: With hundreds or thousands of tests where load balancing matters
138+
- **Mixed test types**: When combining unit tests, integration tests, and end-to-end tests
139+
- **CI/CD pipelines**: For consistent and predictable test execution times
137140

138141
### Usage Examples
139142

@@ -144,7 +147,7 @@ npx codeceptjs run-workers 4 --by pool
144147
# Pool mode with grep filtering
145148
npx codeceptjs run-workers 3 --by pool --grep "@smoke"
146149

147-
# Pool mode in debug mode
150+
# Pool mode in debug mode
148151
npx codeceptjs run-workers 2 --by pool --debug
149152

150153
# Pool mode with specific configuration
@@ -165,7 +168,7 @@ npx codeceptjs run-workers 3 --by pool -c codecept.conf.js
165168
# Traditional mode - tests pre-assigned, some workers may finish early
166169
npx codeceptjs run-workers 3 --by test # ✓ Good for uniform test times
167170

168-
# Suite mode - entire suites assigned to workers
171+
# Suite mode - entire suites assigned to workers
169172
npx codeceptjs run-workers 3 --by suite # ✓ Good for test isolation
170173

171174
# Pool mode - tests distributed dynamically
@@ -437,17 +440,17 @@ async function runWorkers() {
437440
Inside `event.all.result` you can obtain test results from all workers, so you can customize the report:
438441

439442
```js
440-
workers.on(event.all.result, (status, completedTests, workerStats) => {
443+
workers.on(event.all.result, result => {
441444
// print output
442-
console.log('Test status : ', status ? 'Passes' : 'Failed ');
445+
console.log('Test status : ', result.hasFailed() ? 'Failed' : 'Passed');
443446

444447
// print stats
445-
console.log(`Total tests : ${workerStats.tests}`);
446-
console.log(`Passed tests : ${workerStats.passes}`);
447-
console.log(`Failed test tests : ${workerStats.failures}`);
448+
console.log(`Total tests : ${result.stats.tests}`);
449+
console.log(`Passed tests : ${result.stats.passes}`);
450+
console.log(`Failed test tests : ${result.stats.failures}`);
448451

449-
// If you don't want to listen for failed and passed test separately, use completedTests object
450-
for (const test of Object.values(completedTests)) {
452+
// If you don't want to listen for failed and passed test separately, use `tests` array
453+
for (const test of result.tests) {
451454
console.log(`Test status: ${test.err===null}, `, `Test : ${test.title}`);
452455
}
453456
}
@@ -498,7 +501,7 @@ workers.on('message', data => {
498501
console.log(data)
499502
})
500503

501-
workers.on(event.all.result, (status, completedTests, workerStats) => {
504+
workers.on(event.all.result, result => {
502505
// logic
503506
})
504507
```

docs/reports.md

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ GitHub --
3535
```
3636

3737
output steps use `--steps` option:
38+
3839
```
3940
npx codeceptjs run --steps
4041
```
@@ -73,12 +74,10 @@ GitHub --
7374

7475
To get additional information about test execution use `--debug` option.
7576

76-
7777
```
7878
npx codeceptjs run --debug
7979
```
8080

81-
8281
This will show execution steps
8382
as well as notices from test runner. To get even more information with more technical details like error stack traces,
8483
and global promises, or events use `--verbose` mode.
@@ -141,7 +140,6 @@ npx codecepjs dry-run --debug
141140

142141
> ℹ If you use custom JavaScript code inside tests, or rely on values from `grab*` commands, dry-run may produce error output.
143142
144-
145143
## Testomat.io
146144

147145
[Testomat.io](https://testomat.io) is a modern test management tool focused on CodeceptJS and **created by CodeceptJS team**.
@@ -153,18 +151,17 @@ Testomat.io is commercial SaaS service that can receive run reports from local r
153151
154152
To receive run reports you should:
155153

156-
* [Sign up](https://app.testomat.io/users/sign_up) at Testomat.io
157-
* Create a new "Classical" project (select "BDD" project if you use CodeceptJS in BDD mode)
158-
* Select "Import from Source Code"
159-
* Select "CodeceptJS" as testing framework and JavaScript or TypeScript as a language. If you use BDD select "Gherkin" as language.
160-
* Execute provided command in a terminal with your project. This will be "check-tests" or "check-cucmber" command. It scans all your test files and imports them into Testomat.io. This way all your e2e tests will be visible in one UI.
161-
* After tests are imported, go to Runs tab and select "Setup automated tests".
162-
* Follow the instructions:
163-
154+
- [Sign up](https://app.testomat.io/users/sign_up) at Testomat.io
155+
- Create a new "Classical" project (select "BDD" project if you use CodeceptJS in BDD mode)
156+
- Select "Import from Source Code"
157+
- Select "CodeceptJS" as testing framework and JavaScript or TypeScript as a language. If you use BDD select "Gherkin" as language.
158+
- Execute provided command in a terminal with your project. This will be "check-tests" or "check-cucmber" command. It scans all your test files and imports them into Testomat.io. This way all your e2e tests will be visible in one UI.
159+
- After tests are imported, go to Runs tab and select "Setup automated tests".
160+
- Follow the instructions:
164161

165162
![image](https://user-images.githubusercontent.com/77803888/151834217-5da44d92-a59a-458d-8856-64ce61bf3a38.png)
166163

167-
* You will need to install `@testomatio/reporter` package and enable it as a plugin in codeceptjs config:
164+
- You will need to install `@testomatio/reporter` package and enable it as a plugin in codeceptjs config:
168165

169166
```js
170167
plugins: {
@@ -176,14 +173,11 @@ plugins: {
176173
}
177174
```
178175

179-
* Run tests with `TESTOMATIO=` env variable and API key provided by Testomat.io
180-
* See the run report is created and updated in realtime.
181-
176+
- Run tests with `TESTOMATIO=` env variable and API key provided by Testomat.io
177+
- See the run report is created and updated in realtime.
182178

183179
[Testomat.io](https://testomat.io) reporter works in the cloud, so it doesn't require you to install additional software. It can be integrated with your CI service to rerun only failed tests, launch new runs from UI, and send report notifications by email or in Slack, MS Teams, or create issue in Jira.
184180

185-
186-
187181
## ReportPortal
188182

189183
For enterprise grade we reporting we recommend using [ReportPortal](https://reportportal.io).
@@ -195,7 +189,6 @@ Think of it as Kibana but for test reports.
195189

196190
Use official [CodeceptJS Agent for ReportPortal](https://github.com/reportportal/agent-js-codecept/) to start publishing your test results.
197191

198-
199192
## XML
200193

201194
Use default xunit reporter of Mocha to print xml reports. Provide `--reporter xunit` to get the report to screen.
@@ -226,6 +219,21 @@ codeceptjs run --reporter mocha-junit-reporter
226219

227220
Result will be located at `output/result.xml` file.
228221

222+
Alternatively, the reporter name can be added to the configuration file as well. In this case, CodeceptJS can be executed without additional CLI options.
223+
224+
```json
225+
"mocha": {
226+
"reporter": "mocha-junit-reporter",
227+
"reporterOptions": {
228+
"mochaFile": "output/result.xml"
229+
}
230+
},
231+
```
232+
233+
```sh
234+
codeceptjs run
235+
```
236+
229237
## Html
230238

231239
### Built-in HTML Reporter
@@ -252,13 +260,13 @@ exports.config = {
252260
plugins: {
253261
htmlReporter: {
254262
enabled: true,
255-
output: './output', // Directory for the report
256-
reportFileName: 'report.html', // Name of the HTML file
257-
includeArtifacts: true, // Include screenshots/artifacts
258-
showSteps: true, // Show individual test steps
259-
showSkipped: true // Show skipped tests
260-
}
261-
}
263+
output: './output', // Directory for the report
264+
reportFileName: 'report.html', // Name of the HTML file
265+
includeArtifacts: true, // Include screenshots/artifacts
266+
showSteps: true, // Show individual test steps
267+
showSkipped: true, // Show skipped tests
268+
},
269+
},
262270
}
263271
```
264272

@@ -299,6 +307,7 @@ npm i mochawesome
299307
```
300308

301309
If you get an error like this
310+
302311
```sh
303312
"mochawesome" reporter not found
304313

@@ -321,14 +330,29 @@ Configure it to use `output` directory to print HTML reports:
321330
},
322331
```
323332

324-
Execute CodeceptJS with HTML reporter:
333+
Execute CodeceptJS with mochawesome reporter:
325334

326335
```sh
327336
codeceptjs run --reporter mochawesome
328337
```
329338

330339
Result will be located at `output/index.html` file.
331340

341+
Alternatively, the reporter name can be added to the configuration file as well. In this case, CodeceptJS can be executed without additional CLI options.
342+
343+
```json
344+
"mocha": {
345+
"reporter": "mochawesome",
346+
"reporterOptions": {
347+
"reportDir": "output"
348+
}
349+
},
350+
```
351+
352+
```sh
353+
codeceptjs run
354+
```
355+
332356
### Advanced usage
333357

334358
Want to have screenshots for failed tests?
@@ -349,7 +373,7 @@ Then tests with failure will have screenshots.
349373
This helper should be configured in codecept.conf.ts
350374

351375
- `uniqueScreenshotNames` (optional, default: false) - option to prevent screenshot override if you have scenarios with the same name in different suites. This option should be the same as in common helper.
352-
- `disableScreenshots` (optional, default: false) - don't save screenshot on failure. This option should be the same as in common helper.
376+
- `disableScreenshots` (optional, default: false) - don't save screenshot on failure. This option should be the same as in common helper.
353377

354378
Also if you will add Mochawesome helper, then you will able to add custom context in report:
355379

@@ -358,21 +382,22 @@ Also if you will add Mochawesome helper, then you will able to add custom contex
358382
Adds context to executed test in HTML report:
359383

360384
```js
361-
I.addMochawesomeContext('simple string');
362-
I.addMochawesomeContext('http://www.url.com/pathname');
363-
I.addMochawesomeContext('http://www.url.com/screenshot-maybe.jpg');
364-
I.addMochawesomeContext({title: 'expected output',
365-
value: {
366-
a: 1,
367-
b: '2',
368-
c: 'd'
369-
}
370-
});
385+
I.addMochawesomeContext('simple string')
386+
I.addMochawesomeContext('http://www.url.com/pathname')
387+
I.addMochawesomeContext('http://www.url.com/screenshot-maybe.jpg')
388+
I.addMochawesomeContext({
389+
title: 'expected output',
390+
value: {
391+
a: 1,
392+
b: '2',
393+
c: 'd',
394+
},
395+
})
371396
```
372397

373398
##### Parameters
374399

375-
- `context` string, url, path to screenshot, object. See [this](https://www.npmjs.com/package/mochawesome#adding-test-context)
400+
- `context` string, url, path to screenshot, object. See [this](https://www.npmjs.com/package/mochawesome#adding-test-context)
376401

377402
## Multi Reports
378403

@@ -422,6 +447,20 @@ npx codeceptjs run --reporter mocha-multi
422447

423448
This will give you cli with steps in console and HTML report in `output` directory.
424449

450+
Alternatively, the reporter name can be added to the configuration file as well. In this case, CodeceptJS can be executed without additional CLI options.
451+
452+
```json
453+
"mocha": {
454+
"reporter": "mocha-multi",
455+
"reporterOptions": {
456+
...
457+
}
458+
}
459+
```
460+
461+
```sh
462+
codeceptjs run
463+
```
425464

426465
## Testrail
427466

@@ -440,7 +479,6 @@ npm i codeceptjs-testrail --save
440479
Now there is new feature, add the configuration to test run of test plan
441480
![Attachemnt for failed case](http://g.recordit.co/uQLvQUq7cT.gif)
442481

443-
444482
## Tesults
445483

446484
Submit test results data from CodeceptJS to [Tesults](https://www.tesults.com) easily with the [codeceptjs-tesults](https://www.npmjs.com/package/codeceptjs-tesults) plugin. Test results data is submitted automatically after a test run completes.

lib/listener/globalTimeout.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,29 @@ module.exports = function () {
2020

2121
// disable timeout for BeforeSuite/AfterSuite hooks
2222
// add separate configs to them?
23+
// When a BeforeSuite/AfterSuite hook starts we want to disable the
24+
// per-test timeout during that hook execution only. Previously the
25+
// code cleared `suiteTimeout` permanently which caused the suite
26+
// level timeout to be lost for subsequent tests. Save previous
27+
// values and restore them when the hook finishes.
28+
let __prevTimeout = undefined
29+
let __prevSuiteTimeout = undefined
30+
2331
event.dispatcher.on(event.hook.started, hook => {
24-
if (hook instanceof BeforeSuiteHook) {
32+
if (hook instanceof BeforeSuiteHook || hook instanceof AfterSuiteHook) {
33+
__prevTimeout = timeout
34+
// copy array to preserve original values
35+
__prevSuiteTimeout = suiteTimeout.slice()
2536
timeout = null
2637
suiteTimeout = []
2738
}
28-
if (hook instanceof AfterSuiteHook) {
29-
timeout = null
30-
suiteTimeout = []
39+
})
40+
41+
event.dispatcher.on(event.hook.finished, hook => {
42+
if (hook instanceof BeforeSuiteHook || hook instanceof AfterSuiteHook) {
43+
// restore previously stored values
44+
timeout = __prevTimeout
45+
suiteTimeout = __prevSuiteTimeout.slice()
3146
}
3247
})
3348

lib/plugin/retryFailedStep.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ module.exports = config => {
108108
event.dispatcher.on(event.test.before, test => {
109109
// pass disableRetryFailedStep is a preferred way to disable retries
110110
// test.disableRetryFailedStep is used for backward compatibility
111+
if (!test.opts) test.opts = {}
111112
if (test.opts.disableRetryFailedStep || test.disableRetryFailedStep) {
112113
store.autoRetries = false
113114
return // disable retry when a test is not active

0 commit comments

Comments
 (0)