|
| 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. |
0 commit comments