@@ -179,6 +179,48 @@ export default {
179179 await vitest . waitForStdout ( '1 passed' )
180180} )
181181
182+ test ( 'editing a cached source file outside the root triggers re-run' , async ( ) => {
183+ const fs = testUtils . useTmpFS (
184+ {
185+ 'app/package.json' : JSON . stringify ( { name : 'app' , type : 'module' } ) ,
186+ // keeps the workspace root at app/
187+ 'app/pnpm-workspace.yaml' : '' ,
188+ 'app/vitest.config.mjs' : /* js */ `
189+ export default {
190+ test: {
191+ fsModuleCache: true,
192+ fsModuleCachePath: './node_modules/.vitest-fs-cache',
193+ },
194+ }
195+ ` ,
196+ 'app/test/uses-lib.test.ts' : /* ts */ `
197+ import { expect, test } from 'vitest'
198+ import { helper } from '../../lib/src/helper.ts'
199+
200+ test('uses lib', () => {
201+ expect(helper()).toBe(1)
202+ })
203+ ` ,
204+ 'lib/src/helper.ts' : `export const helper = () => 1\n` ,
205+ } ,
206+ false ,
207+ )
208+ const root = resolve ( fs . root , 'app' )
209+
210+ // the first run writes the cache, so the watched run reads the helper from it
211+ const cold = await testUtils . runVitest ( { root } )
212+ expect ( cold . errorTree ( ) ) . toEqual ( { 'test/uses-lib.test.ts' : { 'uses lib' : 'passed' } } )
213+ await cold . ctx ?. close ( )
214+
215+ const { vitest } = await testUtils . runVitest ( { root, watch : true } )
216+
217+ fs . editFile ( 'lib/src/helper.ts' , modifyContent )
218+
219+ await vitest . waitForStdout ( 'New code running' )
220+ await vitest . waitForStdout ( 'RERUN ../../../lib/src/helper.ts' )
221+ await vitest . waitForStdout ( '1 passed' )
222+ } )
223+
182224test ( 'editing config file reloads new changes' , async ( ) => {
183225 const { vitest, fs } = await testUtils . runInlineTests (
184226 {
0 commit comments