Skip to content

Commit 2bcf0dc

Browse files
committed
Update the buildtools tests for windows compatibility
1 parent cdf70e0 commit 2bcf0dc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/buildtools/src/commands/__tests__/build.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs/promises';
2+
import pathlib from 'path';
23
import type { Command } from '@commander-js/extra-typings';
34
import type { BuildResult, Severity } from '@sourceacademy/modules-repotools/types';
45
import { beforeEach, describe, expect, test, vi, type MockInstance } from 'vitest';
@@ -67,12 +68,22 @@ function testBuildCommand<T extends Record<string, any>>(
6768
directories: string[] = [],
6869
...cmdArgs: string[]
6970
) {
71+
/**
72+
* Assert that the given directories were created/not created
73+
*/
7074
function assertDirectories(created: boolean) {
75+
const { calls } = vi.mocked(fs.mkdir).mock;
7176
for (const directory of directories) {
77+
const callFound = calls.find(([actual]) => {
78+
const relpath = pathlib.relative(actual as string, `/build/${directory}`);
79+
return relpath === '';
80+
});
81+
7282
if (created) {
73-
expect(fs.mkdir).toHaveBeenCalledWith(`/build/${directory}`, { recursive: true });
83+
expect(callFound).not.toBeUndefined();
84+
expect(callFound![1]).toEqual({ recursive: true });
7485
} else {
75-
expect(fs.mkdir).not.toHaveBeenCalledWith(`/build/${directory}`, { recursive: true });
86+
expect(callFound).toBeUndefined();
7687
}
7788
}
7889
}

lib/buildtools/vitest.setup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ vi.mock(import('fs/promises'), async importOriginal => {
2828
default: {
2929
...original,
3030
cp: vi.fn().mockResolvedValue(undefined),
31+
glob: vi.fn(),
3132
mkdir: vi.fn().mockResolvedValue(undefined),
3233
writeFile: vi.fn().mockResolvedValue(undefined),
3334
}

0 commit comments

Comments
 (0)