Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/SHARDING_WORKFLOWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Test Sharding Workflows

This document explains the GitHub Actions workflows that demonstrate the new test sharding functionality in CodeceptJS.

## Updated/Created Workflows

### 1. `acceptance-tests.yml` (Updated)

**Purpose**: Demonstrates sharding with acceptance tests across multiple browser configurations.

**Key Features**:

- Runs traditional docker-compose tests (for backward compatibility)
- Adds new sharded acceptance tests using CodeceptJS directly
- Tests across multiple browser configurations (Puppeteer, Playwright)
- Uses 2x2 matrix: 2 configs × 2 shards = 4 parallel jobs

**Example Output**:

```
- Sharded Tests: codecept.Puppeteer.js (Shard 1/2)
- Sharded Tests: codecept.Puppeteer.js (Shard 2/2)
- Sharded Tests: codecept.Playwright.js (Shard 1/2)
- Sharded Tests: codecept.Playwright.js (Shard 2/2)
```

### 2. `sharding-demo.yml` (New)

**Purpose**: Comprehensive demonstration of sharding features with larger test suite.

**Key Features**:

- Uses sandbox tests (2 main test files) for sharding demonstration
- Shows basic sharding with 2-way split (`1/2`, `2/2`)
- Demonstrates combination of `--shuffle` + `--shard` options
- Uses `DONT_FAIL_ON_EMPTY_RUN=true` to handle cases where some shards may be empty

### 3. `test.yml` (Updated)

**Purpose**: Clarifies which tests support sharding.

**Changes**:

- Added comment explaining that runner tests are mocha-based and don't support sharding
- Points to sharding-demo.yml for examples of CodeceptJS-based sharding

## Sharding Commands Used

### Basic Sharding

```bash
npx codeceptjs run --config ./codecept.js --shard 1/2
npx codeceptjs run --config ./codecept.js --shard 2/2
```

### Combined with Other Options

```bash
npx codeceptjs run --config ./codecept.js --shuffle --shard 1/2 --verbose
```

## Test Distribution

The sharding algorithm distributes tests evenly:

- **38 tests across 4 shards**: ~9-10 tests per shard
- **6 acceptance tests across 2 shards**: 3 tests per shard
- **Uneven splits handled gracefully**: Earlier shards get extra tests when needed

## Benefits Demonstrated

1. **Parallel Execution**: Tests run simultaneously across multiple CI workers
2. **No Manual Configuration**: Automatic test distribution without maintaining test lists
3. **Load Balancing**: Even distribution ensures balanced execution times
4. **Flexibility**: Works with any number of shards and test configurations
5. **Integration**: Compatible with existing CodeceptJS features (`--shuffle`, `--verbose`, etc.)

## CI Matrix Integration

The workflows show practical CI matrix usage:

```yaml
strategy:
matrix:
config: ['codecept.Puppeteer.js', 'codecept.Playwright.js']
shard: ['1/2', '2/2']
```

This creates 4 parallel jobs:

- Config A, Shard 1/2
- Config A, Shard 2/2
- Config B, Shard 1/2
- Config B, Shard 2/2

Perfect for scaling test execution across multiple machines and configurations.
2 changes: 1 addition & 1 deletion .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Acceptance Tests using docker compose
name: Acceptance Tests

on:
push:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/sharding-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Minimal Sharding Test

on:
push:
branches:
- '3.x'
pull_request:
branches:
- '**'

env:
CI: true
FORCE_COLOR: 1

jobs:
test-sharding:
runs-on: ubuntu-latest
name: 'Shard ${{ matrix.shard }}'

strategy:
fail-fast: false
matrix:
shard: ['1/2', '2/2']

steps:
- name: Checkout
uses: actions/checkout@v5

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install --ignore-scripts

- name: Run tests with sharding
run: npx codeceptjs run --config ./codecept.js --shard ${{ matrix.shard }}
working-directory: test/data/sandbox
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: true
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- run: npm run test:runner
# Note: Runner tests are mocha-based, so sharding doesn't apply here.
# For CodeceptJS sharding examples, see sharding-demo.yml workflow.
1 change: 1 addition & 0 deletions bin/codecept.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ program
.option('--no-timeouts', 'disable all timeouts')
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated')
.option('--shuffle', 'Shuffle the order in which test files run')
.option('--shard <index/total>', 'run only a fraction of tests (e.g., --shard 1/4)')

// mocha options
.option('--colors', 'force enabling of colors')
Expand Down
Loading