|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { editFile, resolvePath, runVitestCli } from '../../test-utils' |
| 3 | + |
| 4 | +test('list command with --changed flag shows only changed tests', async () => { |
| 5 | + const sourceFile = resolvePath(import.meta.url, '../fixtures/git-changed/related/src/sourceA.ts') |
| 6 | + |
| 7 | + // First, run list without --changed to see all tests |
| 8 | + const { stdout: allTests } = await runVitestCli('list', '-r=./fixtures/git-changed/related') |
| 9 | + expect(allTests).toContain('related.test.ts') |
| 10 | + expect(allTests).toContain('not-related.test.ts') |
| 11 | + |
| 12 | + // Now modify the source file to trigger --changed behavior |
| 13 | + editFile(sourceFile, content => `${content}\n// modified for test`) |
| 14 | + |
| 15 | + // Run list with --changed flag |
| 16 | + const { stdout: changedTests } = await runVitestCli('list', '-r=./fixtures/git-changed/related', '--changed') |
| 17 | + expect(changedTests).toContain('related.test.ts') |
| 18 | + expect(changedTests).not.toContain('not-related.test.ts') |
| 19 | +}) |
| 20 | + |
| 21 | +test('list command with --changed flag and --filesOnly shows only changed test files', async () => { |
| 22 | + const sourceFile = resolvePath(import.meta.url, '../fixtures/git-changed/related/src/sourceA.ts') |
| 23 | + editFile(sourceFile, content => `${content}\n// modified for filesOnly test`) |
| 24 | + |
| 25 | + const { stdout: changedFiles } = await runVitestCli('list', '-r=./fixtures/git-changed/related', '--changed', '--filesOnly') |
| 26 | + expect(changedFiles).toContain('related.test.ts') |
| 27 | + expect(changedFiles).not.toContain('not-related.test.ts') |
| 28 | +}) |
| 29 | + |
| 30 | +test('list command with --changed flag and --json outputs changed tests in JSON format', async () => { |
| 31 | + const sourceFile = resolvePath(import.meta.url, '../fixtures/git-changed/related/src/sourceA.ts') |
| 32 | + editFile(sourceFile, content => `${content}\n// modified for json test`) |
| 33 | + |
| 34 | + const { stdout: changedJson } = await runVitestCli('list', '-r=./fixtures/git-changed/related', '--changed', '--json') |
| 35 | + const jsonOutput = JSON.parse(changedJson) |
| 36 | + expect(Array.isArray(jsonOutput)).toBe(true) |
| 37 | + const relatedTest = jsonOutput.find((test: any) => test.file?.includes('related.test.ts')) |
| 38 | + expect(relatedTest).toBeDefined() |
| 39 | +}) |
| 40 | + |
| 41 | +test('list command with --changed flag when no changes exist should show no tests', async () => { |
| 42 | + const { stdout: noChangesOutput } = await runVitestCli('list', '-r=./fixtures/git-changed/related', '--changed') |
| 43 | + expect(noChangesOutput.trim()).toBe('') |
| 44 | +}) |
0 commit comments