@@ -4,6 +4,7 @@ import pathlib from 'path';
44import { bundlesDir , tabsDir } from '@sourceacademy/modules-repotools/getGitRoot' ;
55import * as manifest from '@sourceacademy/modules-repotools/manifest' ;
66import * as configs from '@sourceacademy/modules-repotools/testing' ;
7+ import { isSamePath } from '@sourceacademy/modules-repotools/utils' ;
78import { beforeEach , describe , expect , it , vi } from 'vitest' ;
89import type { TestProjectInlineConfiguration } from 'vitest/config' ;
910import { testMocksDir } from '../../__tests__/fixtures.js' ;
@@ -15,13 +16,6 @@ class ENOENT extends Error {
1516 }
1617}
1718
18- vi . mock ( import ( '@sourceacademy/modules-repotools/getGitRoot' ) , ( ) => ( {
19- gitRoot : '/' ,
20- bundlesDir : '/bundles' ,
21- tabsDir : '/tabs' ,
22- outDir : '/out'
23- } ) ) ;
24-
2519const mockedFsGlob = vi . spyOn ( fs , 'glob' ) ;
2620function mockHasTestsOnce ( retValue : boolean ) {
2721 mockedFsGlob . mockImplementationOnce ( retValue ? async function * ( ) {
@@ -142,10 +136,11 @@ describe('Test setBrowserOptions', () => {
142136describe ( 'Test getTestConfiguration' , ( ) => {
143137 describe ( 'With tabs' , ( ) => {
144138 const tabPath = pathlib . join ( tabsDir , 'Tab0' ) ;
139+ const tabPackageJson = pathlib . join ( tabPath , 'package.json' ) ;
145140
146141 beforeEach ( ( ) => {
147142 mockedReadFile . mockImplementation ( p => {
148- if ( p === '/tabs/Tab0/package.json' ) {
143+ if ( isSamePath ( tabPackageJson , p as string ) ) {
149144 return Promise . resolve ( JSON . stringify ( {
150145 name : '@sourceacademy/tab-Tab0'
151146 } ) ) ;
@@ -204,10 +199,11 @@ describe('Test getTestConfiguration', () => {
204199
205200 describe ( 'With bundles' , ( ) => {
206201 const bundlePath = pathlib . join ( bundlesDir , 'bundle0' ) ;
202+ const bundlePackageJson = pathlib . join ( bundlePath , 'package.json' ) ;
207203
208204 beforeEach ( ( ) => {
209205 mockedReadFile . mockImplementation ( p => {
210- if ( p === '/bundles/bundle0/package.json' ) {
206+ if ( isSamePath ( p as string , bundlePackageJson ) ) {
211207 return Promise . resolve ( JSON . stringify ( {
212208 name : '@sourceacademy/bundle-bundle0'
213209 } ) ) ;
@@ -242,7 +238,7 @@ describe('Test getTestConfiguration', () => {
242238 } ) ;
243239 } ) ;
244240
245- it ( 'Should return the config even if the function was called from not the tab \'s root directory' , async ( ) => {
241+ it ( 'Should return the config even if the function was called from not the bundle \'s root directory' , async ( ) => {
246242 const subdir = pathlib . join ( bundlePath , 'sub' , 'directory' ) ;
247243 mockHasTestsOnce ( true ) ;
248244 await expect ( utils . getTestConfiguration ( subdir , false ) ) . resolves . toMatchObject ( {
0 commit comments