Skip to content

Commit 58d02e8

Browse files
authored
Merge branch '3.x' into copilot/fix-4107
2 parents cd686e7 + 663be8d commit 58d02e8

File tree

77 files changed

+8227
-275
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+8227
-275
lines changed

.github/SHARDING_WORKFLOWS.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Test Sharding Workflows
2+
3+
This document explains the GitHub Actions workflows that demonstrate the new test sharding functionality in CodeceptJS.
4+
5+
## Updated/Created Workflows
6+
7+
### 1. `acceptance-tests.yml` (Updated)
8+
9+
**Purpose**: Demonstrates sharding with acceptance tests across multiple browser configurations.
10+
11+
**Key Features**:
12+
13+
- Runs traditional docker-compose tests (for backward compatibility)
14+
- Adds new sharded acceptance tests using CodeceptJS directly
15+
- Tests across multiple browser configurations (Puppeteer, Playwright)
16+
- Uses 2x2 matrix: 2 configs × 2 shards = 4 parallel jobs
17+
18+
**Example Output**:
19+
20+
```
21+
- Sharded Tests: codecept.Puppeteer.js (Shard 1/2)
22+
- Sharded Tests: codecept.Puppeteer.js (Shard 2/2)
23+
- Sharded Tests: codecept.Playwright.js (Shard 1/2)
24+
- Sharded Tests: codecept.Playwright.js (Shard 2/2)
25+
```
26+
27+
### 2. `sharding-demo.yml` (New)
28+
29+
**Purpose**: Comprehensive demonstration of sharding features with larger test suite.
30+
31+
**Key Features**:
32+
33+
- Uses sandbox tests (2 main test files) for sharding demonstration
34+
- Shows basic sharding with 2-way split (`1/2`, `2/2`)
35+
- Demonstrates combination of `--shuffle` + `--shard` options
36+
- Uses `DONT_FAIL_ON_EMPTY_RUN=true` to handle cases where some shards may be empty
37+
38+
### 3. `test.yml` (Updated)
39+
40+
**Purpose**: Clarifies which tests support sharding.
41+
42+
**Changes**:
43+
44+
- Added comment explaining that runner tests are mocha-based and don't support sharding
45+
- Points to sharding-demo.yml for examples of CodeceptJS-based sharding
46+
47+
## Sharding Commands Used
48+
49+
### Basic Sharding
50+
51+
```bash
52+
npx codeceptjs run --config ./codecept.js --shard 1/2
53+
npx codeceptjs run --config ./codecept.js --shard 2/2
54+
```
55+
56+
### Combined with Other Options
57+
58+
```bash
59+
npx codeceptjs run --config ./codecept.js --shuffle --shard 1/2 --verbose
60+
```
61+
62+
## Test Distribution
63+
64+
The sharding algorithm distributes tests evenly:
65+
66+
- **38 tests across 4 shards**: ~9-10 tests per shard
67+
- **6 acceptance tests across 2 shards**: 3 tests per shard
68+
- **Uneven splits handled gracefully**: Earlier shards get extra tests when needed
69+
70+
## Benefits Demonstrated
71+
72+
1. **Parallel Execution**: Tests run simultaneously across multiple CI workers
73+
2. **No Manual Configuration**: Automatic test distribution without maintaining test lists
74+
3. **Load Balancing**: Even distribution ensures balanced execution times
75+
4. **Flexibility**: Works with any number of shards and test configurations
76+
5. **Integration**: Compatible with existing CodeceptJS features (`--shuffle`, `--verbose`, etc.)
77+
78+
## CI Matrix Integration
79+
80+
The workflows show practical CI matrix usage:
81+
82+
```yaml
83+
strategy:
84+
matrix:
85+
config: ['codecept.Puppeteer.js', 'codecept.Playwright.js']
86+
shard: ['1/2', '2/2']
87+
```
88+
89+
This creates 4 parallel jobs:
90+
91+
- Config A, Shard 1/2
92+
- Config A, Shard 2/2
93+
- Config B, Shard 1/2
94+
- Config B, Shard 2/2
95+
96+
Perfect for scaling test execution across multiple machines and configurations.

.github/workflows/acceptance-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Acceptance Tests using docker compose
1+
name: Acceptance Tests
22

33
on:
44
push:
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Minimal Sharding Test
2+
3+
on:
4+
push:
5+
branches:
6+
- '3.x'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
env:
12+
CI: true
13+
FORCE_COLOR: 1
14+
15+
jobs:
16+
test-sharding:
17+
runs-on: ubuntu-latest
18+
name: 'Shard ${{ matrix.shard }}'
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
shard: ['1/2', '2/2']
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v5
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: 20
33+
34+
- name: Install dependencies
35+
run: npm install --ignore-scripts
36+
37+
- name: Run tests with sharding
38+
run: npx codeceptjs run --config ./codecept.js --shard ${{ matrix.shard }}
39+
working-directory: test/data/sandbox

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ jobs:
4848
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
4949
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
5050
- run: npm run test:runner
51+
# Note: Runner tests are mocha-based, so sharding doesn't apply here.
52+
# For CodeceptJS sharding examples, see sharding-demo.yml workflow.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ examples/selenoid-example/output
1717
test/data/app/db
1818
test/data/sandbox/steps.d.ts
1919
test/data/sandbox/configs/custom-reporter-plugin/output/result.json
20+
test/data/sandbox/configs/html-reporter-plugin/output/
21+
output/
22+
test/runner/output/
2023
testpullfilecache*
2124
.DS_Store
2225
package-lock.json

Dockerfile

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@ RUN apt-get update && \
1212
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
1313
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
1414
# installs, work.
15-
RUN apt-get update && apt-get install -y gnupg wget && \
16-
wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
17-
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list && \
18-
apt-get update && \
19-
apt-get install -y google-chrome-stable --no-install-recommends && \
20-
rm -rf /var/lib/apt/lists/*
15+
# Skip Chrome installation for now as Playwright image already has browsers
16+
RUN echo "Skipping Chrome installation - using Playwright browsers"
2117

2218

2319
# Add pptr user.
@@ -31,17 +27,23 @@ RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
3127
COPY . /codecept
3228

3329
RUN chown -R pptruser:pptruser /codecept
34-
RUN runuser -l pptruser -c 'npm i --loglevel=warn --prefix /codecept'
30+
# Set environment variables to skip browser downloads during npm install
31+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
32+
ENV PUPPETEER_SKIP_DOWNLOAD=true
33+
# Install as root to ensure proper bin links are created
34+
RUN cd /codecept && npm install --loglevel=warn
35+
# Fix ownership after install
36+
RUN chown -R pptruser:pptruser /codecept
3537

3638
RUN ln -s /codecept/bin/codecept.js /usr/local/bin/codeceptjs
3739
RUN mkdir /tests
3840
WORKDIR /tests
39-
# Install puppeteer so it's available in the container.
40-
RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
41-
RUN google-chrome --version
41+
# Skip the redundant Puppeteer installation step since we're using Playwright browsers
42+
# RUN npm i puppeteer@$(npm view puppeteer version) && npx puppeteer browsers install chrome
43+
# RUN chromium-browser --version
4244

43-
# Install playwright browsers
44-
RUN npx playwright install
45+
# Skip the playwright browser installation step since base image already has browsers
46+
# RUN npx playwright install
4547

4648
# Allow to pass argument to codecept run via env variable
4749
ENV CODECEPT_ARGS=""

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ You don't need to worry about asynchronous nature of NodeJS or about various API
6464
- Also plays nice with TypeScript.
6565
- </> Smart locators: use names, labels, matching text, CSS or XPath to locate elements.
6666
- 🌐 Interactive debugging shell: pause test at any point and try different commands in a browser.
67+
-**Parallel testing** with dynamic test pooling for optimal load balancing and performance.
68+
- 📊 **Built-in HTML Reporter** with interactive dashboard, step-by-step execution details, and comprehensive test analytics.
6769
- Easily create tests, pageobjects, stepobjects with CLI generators.
6870

6971
## Installation
@@ -233,6 +235,49 @@ Scenario('test title', () => {
233235
})
234236
```
235237

238+
## HTML Reporter
239+
240+
CodeceptJS includes a powerful built-in HTML Reporter that generates comprehensive, interactive test reports with detailed information about your test runs. The HTML reporter is **enabled by default** for all new projects and provides:
241+
242+
### Features
243+
244+
- **Interactive Dashboard**: Visual statistics, pie charts, and expandable test details
245+
- **Step-by-Step Execution**: Shows individual test steps with timing and status indicators
246+
- **BDD/Gherkin Support**: Full support for feature files with proper scenario formatting
247+
- **System Information**: Comprehensive environment details including browser versions
248+
- **Advanced Filtering**: Real-time filtering by status, tags, features, and test types
249+
- **History Tracking**: Multi-run history with trend visualization
250+
- **Error Details**: Clean formatting of error messages and stack traces
251+
- **Artifacts Support**: Display screenshots and other test artifacts
252+
253+
### Visual Examples
254+
255+
#### Interactive Test Dashboard
256+
257+
The main dashboard provides a complete overview with interactive statistics and pie charts:
258+
259+
![HTML Reporter Dashboard](docs/shared/html-reporter-main-dashboard.png)
260+
261+
#### Detailed Test Results
262+
263+
Each test shows comprehensive execution details with expandable step information:
264+
265+
![HTML Reporter Test Details](docs/shared/html-reporter-test-details.png)
266+
267+
#### Advanced Filtering Capabilities
268+
269+
Real-time filtering allows quick navigation through test results:
270+
271+
![HTML Reporter Filtering](docs/shared/html-reporter-filtering.png)
272+
273+
#### BDD/Gherkin Support
274+
275+
Full support for Gherkin scenarios with proper feature formatting:
276+
277+
![HTML Reporter BDD Details](docs/shared/html-reporter-bdd-details.png)
278+
279+
The HTML reporter generates self-contained reports that can be easily shared with your team. Learn more about configuration and features in the [HTML Reporter documentation](https://codecept.io/plugins/#htmlreporter).
280+
236281
## PageObjects
237282

238283
CodeceptJS provides the most simple way to create and use page objects in your test.

bin/codecept.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ program
165165
.option('--no-timeouts', 'disable all timeouts')
166166
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
167167
.option('--shuffle', 'Shuffle the order in which test files run')
168+
.option('--shard <index/total>', 'run only a fraction of tests (e.g., --shard 1/4)')
168169

169170
// mocha options
170171
.option('--colors', 'force enabling of colors')
@@ -196,6 +197,7 @@ program
196197
.option('-i, --invert', 'inverts --grep matches')
197198
.option('-o, --override [value]', 'override current config options')
198199
.option('--suites', 'parallel execution of suites not single tests')
200+
.option('--by <strategy>', 'test distribution strategy: "test" (pre-assign individual tests), "suite" (pre-assign test suites), or "pool" (dynamic distribution for optimal load balancing, recommended)')
199201
.option(commandFlags.debug.flag, commandFlags.debug.description)
200202
.option(commandFlags.verbose.flag, commandFlags.verbose.description)
201203
.option('--features', 'run only *.feature files and skip tests')

bin/test-server.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Standalone test server script to replace json-server
5+
*/
6+
7+
const path = require('path')
8+
const TestServer = require('../lib/test-server')
9+
10+
// Parse command line arguments
11+
const args = process.argv.slice(2)
12+
let dbFile = path.join(__dirname, '../test/data/rest/db.json')
13+
let port = 8010
14+
let host = '0.0.0.0'
15+
16+
// Simple argument parsing
17+
for (let i = 0; i < args.length; i++) {
18+
const arg = args[i]
19+
20+
if (arg === '-p' || arg === '--port') {
21+
port = parseInt(args[++i])
22+
} else if (arg === '--host') {
23+
host = args[++i]
24+
} else if (!arg.startsWith('-')) {
25+
dbFile = path.resolve(arg)
26+
}
27+
}
28+
29+
// Create and start server
30+
const server = new TestServer({ port, host, dbFile })
31+
32+
console.log(`Starting test server with db file: ${dbFile}`)
33+
34+
server
35+
.start()
36+
.then(() => {
37+
console.log(`Test server is ready and listening on http://${host}:${port}`)
38+
})
39+
.catch(err => {
40+
console.error('Failed to start test server:', err)
41+
process.exit(1)
42+
})
43+
44+
// Graceful shutdown
45+
process.on('SIGINT', () => {
46+
console.log('\nShutting down test server...')
47+
server.stop().then(() => process.exit(0))
48+
})
49+
50+
process.on('SIGTERM', () => {
51+
console.log('\nShutting down test server...')
52+
server.stop().then(() => process.exit(0))
53+
})

0 commit comments

Comments
 (0)