Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. # Burn-in Test Runner
  2. ## Principle
  3. Use smart test selection with git diff analysis to run only affected tests. Filter out irrelevant changes (configs, types, docs) and control test volume with percentage-based execution. Reduce unnecessary CI runs while maintaining reliability.
  4. ## Rationale
  5. Playwright's `--only-changed` triggers all affected tests:
  6. - Config file changes trigger hundreds of tests
  7. - Type definition changes cause full suite runs
  8. - No volume control (all or nothing)
  9. - Slow CI pipelines
  10. The `burn-in` utility provides:
  11. - **Smart filtering**: Skip patterns for irrelevant files (configs, types, docs)
  12. - **Volume control**: Run percentage of affected tests after filtering
  13. - **Custom dependency analysis**: More accurate than Playwright's built-in
  14. - **CI optimization**: Faster pipelines without sacrificing confidence
  15. - **Process of elimination**: Start with all → filter irrelevant → control volume
  16. ## Pattern Examples
  17. ### Example 1: Basic Burn-in Setup
  18. **Context**: Run burn-in on changed files compared to main branch.
  19. **Implementation**:
  20. ```typescript
  21. // Step 1: Create burn-in script
  22. // playwright/scripts/burn-in-changed.ts
  23. import { runBurnIn } from '@seontechnologies/playwright-utils/burn-in'
  24. async function main() {
  25. await runBurnIn({
  26. configPath: 'playwright/config/.burn-in.config.ts',
  27. baseBranch: 'main'
  28. })
  29. }
  30. main().catch(console.error)
  31. // Step 2: Create config
  32. // playwright/config/.burn-in.config.ts
  33. import type { BurnInConfig } from '@seontechnologies/playwright-utils/burn-in'
  34. const config: BurnInConfig = {
  35. // Files that never trigger tests (first filter)
  36. skipBurnInPatterns: [
  37. '**/config/**',
  38. '**/*constants*',
  39. '**/*types*',
  40. '**/*.md',
  41. '**/README*'
  42. ],
  43. // Run 30% of remaining tests after skip filter
  44. burnInTestPercentage: 0.3,
  45. // Burn-in repetition
  46. burnIn: {
  47. repeatEach: 3, // Run each test 3 times
  48. retries: 1 // Allow 1 retry
  49. }
  50. }
  51. export default config
  52. // Step 3: Add package.json script
  53. {
  54. "scripts": {
  55. "test:pw:burn-in-changed": "tsx playwright/scripts/burn-in-changed.ts"
  56. }
  57. }
  58. ```
  59. **Key Points**:
  60. - Two-stage filtering: skip patterns, then volume control
  61. - `skipBurnInPatterns` eliminates irrelevant files
  62. - `burnInTestPercentage` controls test volume (0.3 = 30%)
  63. - Custom dependency analysis finds actually affected tests
  64. ### Example 2: CI Integration
  65. **Context**: Use burn-in in GitHub Actions for efficient CI runs.
  66. **Implementation**:
  67. ```yaml
  68. # .github/workflows/burn-in.yml
  69. name: Burn-in Changed Tests
  70. on:
  71. pull_request:
  72. branches: [main]
  73. jobs:
  74. burn-in:
  75. runs-on: ubuntu-latest
  76. steps:
  77. - uses: actions/checkout@v4
  78. with:
  79. fetch-depth: 0 # Need git history
  80. - name: Setup Node
  81. uses: actions/setup-node@v4
  82. - name: Install dependencies
  83. run: npm ci
  84. - name: Run burn-in on changed tests
  85. run: npm run test:pw:burn-in-changed -- --base-branch=origin/main
  86. - name: Upload artifacts
  87. if: failure()
  88. uses: actions/upload-artifact@v4
  89. with:
  90. name: burn-in-failures
  91. path: test-results/
  92. ```
  93. **Key Points**:
  94. - `fetch-depth: 0` for full git history
  95. - Pass `--base-branch=origin/main` for PR comparison
  96. - Upload artifacts only on failure
  97. - Significantly faster than full suite
  98. ### Example 3: How It Works (Process of Elimination)
  99. **Context**: Understanding the filtering pipeline.
  100. **Scenario:**
  101. ```
  102. Git diff finds: 21 changed files
  103. ├─ Step 1: Skip patterns filter
  104. │ Removed: 6 files (*.md, config/*, *types*)
  105. │ Remaining: 15 files
  106. ├─ Step 2: Dependency analysis
  107. │ Tests that import these 15 files: 45 tests
  108. └─ Step 3: Volume control (30%)
  109. Final tests to run: 14 tests (30% of 45)
  110. Result: Run 14 targeted tests instead of 147 with --only-changed!
  111. ```
  112. **Key Points**:
  113. - Three-stage pipeline: skip → analyze → control
  114. - Custom dependency analysis (not just imports)
  115. - Percentage applies AFTER filtering
  116. - Dramatically reduces CI time
  117. ### Example 4: Environment-Specific Configuration
  118. **Context**: Different settings for local vs CI environments.
  119. **Implementation**:
  120. ```typescript
  121. import type { BurnInConfig } from '@seontechnologies/playwright-utils/burn-in';
  122. const config: BurnInConfig = {
  123. skipBurnInPatterns: ['**/config/**', '**/*types*', '**/*.md'],
  124. // CI runs fewer iterations, local runs more
  125. burnInTestPercentage: process.env.CI ? 0.2 : 0.3,
  126. burnIn: {
  127. repeatEach: process.env.CI ? 2 : 3,
  128. retries: process.env.CI ? 0 : 1, // No retries in CI
  129. },
  130. };
  131. export default config;
  132. ```
  133. **Key Points**:
  134. - `process.env.CI` for environment detection
  135. - Lower percentage in CI (20% vs 30%)
  136. - Fewer iterations in CI (2 vs 3)
  137. - No retries in CI (fail fast)
  138. ### Example 5: Sharding Support
  139. **Context**: Distribute burn-in tests across multiple CI workers.
  140. **Implementation**:
  141. ```typescript
  142. // burn-in-changed.ts with sharding
  143. import { runBurnIn } from '@seontechnologies/playwright-utils/burn-in';
  144. async function main() {
  145. const shardArg = process.argv.find((arg) => arg.startsWith('--shard='));
  146. if (shardArg) {
  147. process.env.PW_SHARD = shardArg.split('=')[1];
  148. }
  149. await runBurnIn({
  150. configPath: 'playwright/config/.burn-in.config.ts',
  151. });
  152. }
  153. ```
  154. ```yaml
  155. # GitHub Actions with sharding
  156. jobs:
  157. burn-in:
  158. strategy:
  159. matrix:
  160. shard: [1/3, 2/3, 3/3]
  161. steps:
  162. - run: npm run test:pw:burn-in-changed -- --shard=${{ matrix.shard }}
  163. ```
  164. **Key Points**:
  165. - Pass `--shard=1/3` for parallel execution
  166. - Burn-in respects Playwright sharding
  167. - Distribute across multiple workers
  168. - Reduces total CI time further
  169. ## Integration with CI Workflow
  170. When setting up CI with `*ci` workflow, recommend burn-in for:
  171. - Pull request validation
  172. - Pre-merge checks
  173. - Nightly builds (subset runs)
  174. ## Related Fragments
  175. - `ci-burn-in.md` - Traditional burn-in patterns (10-iteration loops)
  176. - `selective-testing.md` - Test selection strategies
  177. - `overview.md` - Installation
  178. ## Anti-Patterns
  179. **❌ Over-aggressive skip patterns:**
  180. ```typescript
  181. skipBurnInPatterns: [
  182. '**/*', // Skips everything!
  183. ];
  184. ```
  185. **✅ Targeted skip patterns:**
  186. ```typescript
  187. skipBurnInPatterns: ['**/config/**', '**/*types*', '**/*.md', '**/*constants*'];
  188. ```
  189. **❌ Too low percentage (false confidence):**
  190. ```typescript
  191. burnInTestPercentage: 0.05; // Only 5% - might miss issues
  192. ```
  193. **✅ Balanced percentage:**
  194. ```typescript
  195. burnInTestPercentage: 0.2; // 20% in CI, provides good coverage
  196. ```