|
| 1 | +import { expect, it } from 'vitest' |
| 2 | + |
| 3 | +import { |
| 4 | + coverBudgetMs, |
| 5 | + laneBudgetMs, |
| 6 | +} from '../../../../../scripts/fleet/constants/test-budget.mts' |
| 7 | +import { |
| 8 | + packageTestGlobs, |
| 9 | + resolvePackageTestScope, |
| 10 | + selectPackageTestGlobs, |
| 11 | +} from '../../../scripts/test-lanes.mts' |
| 12 | + |
| 13 | +it('defaults bare package tests to the fast budget', () => { |
| 14 | + const scope = resolvePackageTestScope([], '/example/repo') |
| 15 | + expect(scope).toEqual({ |
| 16 | + args: [], |
| 17 | + lane: 'fast', |
| 18 | + timeout: laneBudgetMs('fast'), |
| 19 | + }) |
| 20 | +}) |
| 21 | + |
| 22 | +it('keeps explicit files and all-unit runs outside lane filtering', () => { |
| 23 | + for (const args of [ |
| 24 | + ['--all'], |
| 25 | + ['test/unit/example.test.mts'], |
| 26 | + ['--coverage'], |
| 27 | + ]) { |
| 28 | + const scope = resolvePackageTestScope(args, '/example/repo') |
| 29 | + expect(scope.lane).toBeUndefined() |
| 30 | + expect(scope.timeout).toBe(coverBudgetMs()) |
| 31 | + expect(scope.args).toEqual(args.filter(arg => arg !== '--all')) |
| 32 | + } |
| 33 | +}) |
| 34 | + |
| 35 | +it('consumes lane flags and preserves Vitest arguments', () => { |
| 36 | + expect( |
| 37 | + resolvePackageTestScope( |
| 38 | + ['--lane', 'mid', '--reporter=json'], |
| 39 | + '/example/repo', |
| 40 | + ), |
| 41 | + ).toEqual({ |
| 42 | + args: ['--reporter=json'], |
| 43 | + lane: 'mid', |
| 44 | + timeout: laneBudgetMs('mid'), |
| 45 | + }) |
| 46 | + expect( |
| 47 | + resolvePackageTestScope( |
| 48 | + ['--lane=slow', '--config', 'vitest.integration.config.mts'], |
| 49 | + '/example/repo', |
| 50 | + ), |
| 51 | + ).toEqual({ |
| 52 | + args: ['--config', 'vitest.integration.config.mts'], |
| 53 | + lane: 'slow', |
| 54 | + timeout: laneBudgetMs('slow'), |
| 55 | + }) |
| 56 | + expect(() => |
| 57 | + resolvePackageTestScope(['--lane=unknown'], '/example/repo'), |
| 58 | + ).toThrow() |
| 59 | +}) |
| 60 | + |
| 61 | +it('normalizes member globs and excludes other packages', () => { |
| 62 | + expect( |
| 63 | + packageTestGlobs( |
| 64 | + [ |
| 65 | + 'packages\\cli\\test\\unit\\commands\\**', |
| 66 | + 'packages/cli/test/unit/meow.test.mts', |
| 67 | + 'packages/other/test/unit/example.test.mts', |
| 68 | + 'packages/cli-other/test/unit/example.test.mts', |
| 69 | + ], |
| 70 | + 'packages\\cli', |
| 71 | + ), |
| 72 | + ).toEqual(['test/unit/commands/**', 'test/unit/meow.test.mts']) |
| 73 | +}) |
| 74 | + |
| 75 | +it('partitions fast and mid while leaving unscoped coverage complete', () => { |
| 76 | + const lanes = { |
| 77 | + mid: ['test/unit/commands/**'], |
| 78 | + slow: ['test/integration/**'], |
| 79 | + } |
| 80 | + expect(selectPackageTestGlobs('fast', lanes)).toEqual({ |
| 81 | + include: ['test/**/*.test.{mts,ts}'], |
| 82 | + exclude: [...lanes.mid, ...lanes.slow], |
| 83 | + }) |
| 84 | + expect(selectPackageTestGlobs('mid', lanes)).toEqual({ |
| 85 | + include: ['test/unit/commands/**/*.test.{mts,ts}'], |
| 86 | + exclude: [], |
| 87 | + }) |
| 88 | + expect(selectPackageTestGlobs(undefined, lanes)).toEqual({ |
| 89 | + include: ['test/**/*.test.{mts,ts}'], |
| 90 | + exclude: [], |
| 91 | + }) |
| 92 | +}) |
0 commit comments