File tree Expand file tree Collapse file tree
packages/mocker/src/browser
test/browser/fixtures/mocking-out-of-root Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { CreateMockInstanceProcedure } from '../automocker'
22import type { MockedModule , MockedModuleType } from '../registry'
33import type { ModuleMockContext , ModuleMockOptions , TestModuleMocker } from '../types'
44import type { ModuleMockerInterceptor } from './interceptor'
5+ import { withTrailingSlash } from '@vitest/utils/helpers'
56import { extname , join } from 'pathe'
67import { mockObject } from '../automocker'
78import { AutomockedModule , MockerRegistry , RedirectedModule } from '../registry'
@@ -277,11 +278,11 @@ export class ModuleMocker implements TestModuleMocker {
277278 const fsRoot = join ( '/@fs/' , config . root )
278279
279280 // URL can be /file/path.js, but path is resolved to /file/path
280- if ( path . startsWith ( config . root ) ) {
281+ if ( path . startsWith ( withTrailingSlash ( config . root ) ) ) {
281282 return path . slice ( config . root . length )
282283 }
283284
284- if ( path . startsWith ( fsRoot ) ) {
285+ if ( path . startsWith ( withTrailingSlash ( fsRoot ) ) ) {
285286 return path . slice ( fsRoot . length )
286287 }
287288
Original file line number Diff line number Diff line change 1+ export default "project1-utils"
Original file line number Diff line number Diff line change 11import { test , expect , vi } from 'vitest' ;
22import project2 from "../project2/index.js"
3+ import project1Utils from "../project1-utils/index.js"
34import "./imported-test.js"
45import "../project3/imported-test.js"
56
67vi . mock ( "../project2/index.js" , ( ) => ( {
78 default : 'project2-mocked'
89} ) )
910
11+ vi . mock ( "../project1-utils/index.js" , ( ) => ( {
12+ default : 'project1-utils-mocked'
13+ } ) )
14+
1015test ( "basic" , ( ) => {
1116 expect ( project2 ) . toMatchInlineSnapshot ( `"project2-mocked"` )
1217} )
18+
19+ test ( "sibling directory that shares the root prefix" , ( ) => {
20+ expect ( project1Utils ) . toMatchInlineSnapshot ( `"project1-utils-mocked"` )
21+ } )
You can’t perform that action at this time.
0 commit comments