|
| 1 | +/** |
| 2 | + * Unit tests for lifecycle harness args: parseArgs with given argv. |
| 3 | + */ |
| 4 | + |
| 5 | +import { describe, expect, it } from 'vitest' |
| 6 | +import { parseArgs } from '../../lifecycle-harness/src/args.js' |
| 7 | + |
| 8 | +describe('parseArgs', () => { |
| 9 | + it('returns help mode for --help', () => { |
| 10 | + const out = parseArgs(['node', 'harness', '--help']) |
| 11 | + expect(out.mode).toBe('help') |
| 12 | + }) |
| 13 | + |
| 14 | + it('returns help mode for -h', () => { |
| 15 | + const out = parseArgs(['node', 'harness', '-h']) |
| 16 | + expect(out.mode).toBe('help') |
| 17 | + }) |
| 18 | + |
| 19 | + it('returns version mode for --version', () => { |
| 20 | + const out = parseArgs(['node', 'harness', '--version']) |
| 21 | + expect(out.mode).toBe('version') |
| 22 | + }) |
| 23 | + |
| 24 | + it('returns run mode with defaults when only node and script', () => { |
| 25 | + const out = parseArgs(['node', 'scripts/lifecycle-harness/src/index.ts']) |
| 26 | + expect(out.mode).toBe('run') |
| 27 | + if (out.mode === 'run') { |
| 28 | + expect(typeof out.seed).toBe('number') |
| 29 | + expect(out.scenarios).toBe(10) |
| 30 | + expect(out.budgetMinutes).toBe(14) |
| 31 | + expect(out.scenarioTimeoutSeconds).toBe(90) |
| 32 | + expect(out.diskBudgetMb).toBe(1024) |
| 33 | + expect(out.commits).toBe('minimal') |
| 34 | + expect(out.verbose).toBe(false) |
| 35 | + expect(out.dryRun).toBe(false) |
| 36 | + expect(out.epBin).toBe('ep') |
| 37 | + } |
| 38 | + }) |
| 39 | + |
| 40 | + it('parses --seed', () => { |
| 41 | + const out = parseArgs(['node', 'harness', '--seed', '42']) |
| 42 | + expect(out.mode).toBe('run') |
| 43 | + if (out.mode === 'run') expect(out.seed).toBe(42) |
| 44 | + }) |
| 45 | + |
| 46 | + it('parses --scenarios', () => { |
| 47 | + const out = parseArgs(['node', 'harness', '--seed', '1', '--scenarios', '3']) |
| 48 | + expect(out.mode).toBe('run') |
| 49 | + if (out.mode === 'run') expect(out.scenarios).toBe(3) |
| 50 | + }) |
| 51 | + |
| 52 | + it('parses --only-scenario', () => { |
| 53 | + const out = parseArgs(['node', 'harness', '--seed', '1', '--only-scenario', '2']) |
| 54 | + expect(out.mode).toBe('run') |
| 55 | + if (out.mode === 'run') expect(out.onlyScenario).toBe(2) |
| 56 | + }) |
| 57 | + |
| 58 | + it('ignores negative --only-scenario', () => { |
| 59 | + const out = parseArgs(['node', 'harness', '--seed', '1', '--only-scenario', '-1']) |
| 60 | + expect(out.mode).toBe('run') |
| 61 | + if (out.mode === 'run') expect(out.onlyScenario).toBeUndefined() |
| 62 | + }) |
| 63 | + |
| 64 | + it('parses --commits none', () => { |
| 65 | + const out = parseArgs(['node', 'harness', '--seed', '1', '--commits', 'none']) |
| 66 | + expect(out.mode).toBe('run') |
| 67 | + if (out.mode === 'run') expect(out.commits).toBe('none') |
| 68 | + }) |
| 69 | + |
| 70 | + it('parses --verbose and --dry-run', () => { |
| 71 | + const out = parseArgs(['node', 'harness', '--seed', '1', '--verbose', '--dry-run']) |
| 72 | + expect(out.mode).toBe('run') |
| 73 | + if (out.mode === 'run') { |
| 74 | + expect(out.verbose).toBe(true) |
| 75 | + expect(out.dryRun).toBe(true) |
| 76 | + } |
| 77 | + }) |
| 78 | + |
| 79 | + it('parses --ep-bin', () => { |
| 80 | + const out = parseArgs(['node', 'harness', '--seed', '1', '--ep-bin', '/usr/local/bin/ep']) |
| 81 | + expect(out.mode).toBe('run') |
| 82 | + if (out.mode === 'run') expect(out.epBin).toBe('/usr/local/bin/ep') |
| 83 | + }) |
| 84 | +}) |
0 commit comments