Skip to content

Commit af28305

Browse files
authored
docs: update example for "event.all.result" handler (receives a single "result" object) (#5233)
1 parent aaf4fef commit af28305

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

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
```

0 commit comments

Comments
 (0)