Skip to content

Commit f6847ad

Browse files
committed
Still fixing tests....
1 parent e583162 commit f6847ad

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

lib/buildtools/src/prebuild/__tests__/tsc.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ describe('Test the augmented tsc functionality', () => {
4747

4848
expect(ts.createProgram).toHaveBeenCalledTimes(2);
4949
expect(mockedWriteFile).toHaveBeenCalledTimes(1);
50+
console.log(mockedWriteFile.mock.calls);
5051
const [[writePath]] = mockedWriteFile.mock.calls;
5152

5253
expect(writePath).not.toEqual(pathlib.join(testMocksDir, 'bundles', 'test0', '__tests__', 'test0.test.js'));

lib/buildtools/src/testing/__tests__/utils.test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import pathlib from 'path';
44
import { bundlesDir, tabsDir } from '@sourceacademy/modules-repotools/getGitRoot';
55
import * as manifest from '@sourceacademy/modules-repotools/manifest';
66
import * as configs from '@sourceacademy/modules-repotools/testing';
7+
import { isSamePath } from '@sourceacademy/modules-repotools/utils';
78
import { beforeEach, describe, expect, it, vi } from 'vitest';
89
import type { TestProjectInlineConfiguration } from 'vitest/config';
910
import { 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-
2519
const mockedFsGlob = vi.spyOn(fs, 'glob');
2620
function mockHasTestsOnce(retValue: boolean) {
2721
mockedFsGlob.mockImplementationOnce(retValue ? async function* () {
@@ -142,10 +136,11 @@ describe('Test setBrowserOptions', () => {
142136
describe('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

Comments
 (0)