@@ -4,8 +4,12 @@ import { expect, onTestFinished, test, vi } from 'vitest'
44import { createVitest } from 'vitest/node'
55import { runInlineTests , useFS } from '#test-utils'
66
7+ function affectedSummary ( stdout : string ) {
8+ return stdout . split ( '\n' ) . find ( ( line ) => line . includes ( 'Affected' ) )
9+ }
10+
711test ( 'custom vcsProvider that returns specific files runs only matching tests' , async ( ) => {
8- const { testTree, stderr } = await runInlineTests (
12+ const { testTree, stderr, stdout } = await runInlineTests (
913 {
1014 'vitest.config.js' : `
1115 import path from 'node:path'
@@ -51,6 +55,47 @@ test('custom vcsProvider that returns specific files runs only matching tests',
5155 },
5256 }
5357 ` )
58+ expect ( affectedSummary ( stdout ) ) . toMatchInlineSnapshot (
59+ `" Affected 1 of 2 test files (related to 1 changed file)"` ,
60+ )
61+ } )
62+
63+ test ( 'related prints how many test files were affected' , async ( ) => {
64+ const { testTree, stderr, stdout } = await runInlineTests (
65+ {
66+ 'src/changed.ts' : 'export const a = 1' ,
67+ 'src/not-changed.ts' : 'export const b = 2' ,
68+ 'related.test.ts' : `
69+ import { a } from './src/changed.ts'
70+ import { test, expect } from 'vitest'
71+ test('related test', () => {
72+ expect(a).toBe(1)
73+ })
74+ ` ,
75+ 'not-related.test.ts' : `
76+ import { b } from './src/not-changed.ts'
77+ import { test, expect } from 'vitest'
78+ test('not related test', () => {
79+ expect(b).toBe(2)
80+ })
81+ ` ,
82+ } ,
83+ {
84+ related : [ 'src/changed.ts' ] ,
85+ } ,
86+ )
87+
88+ expect ( stderr ) . toBe ( '' )
89+ expect ( testTree ( ) ) . toMatchInlineSnapshot ( `
90+ {
91+ "related.test.ts": {
92+ "related test": "passed",
93+ },
94+ }
95+ ` )
96+ expect ( affectedSummary ( stdout ) ) . toMatchInlineSnapshot (
97+ `" Affected 1 of 2 test files (related to src/changed.ts)"` ,
98+ )
5499} )
55100
56101test ( 'custom vcsProvider that returns no files runs no tests' , async ( ) => {
0 commit comments