Skip to content

Commit 773cd4c

Browse files
committed
Try and fix the markdown tree tests
1 parent f11b4c4 commit 773cd4c

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

lib/buildtools/src/prebuild/tsc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export async function runTsc(input: InputAsset, noEmit: boolean): Promise<TscRes
104104
// files and actually output the files
105105
const filesWithoutTests = fileNames.filter(p => {
106106
const segments = p.split(pathlib.sep);
107+
console.log(segments);
107108
return !segments.includes('__tests__');
108109
});
109110
const compileProgram = ts.createProgram({

lib/buildtools/src/testing/runner.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function getIncludes({ test }: TestProjectInlineConfiguration) {
3333
export async function runVitest(mode: VitestRunMode, filters: string[], projects: TestProjectInlineConfiguration[], options: RunVitestBoolOptions) {
3434
try {
3535
const coverageIncludeFilters = filters.length === 0 ? filters : projects.flatMap(getIncludes);
36+
3637
const runtimeOptions: ViteUserConfig['test'] = {
3738
projects,
3839
update: !!options.update,

lib/markdown-tree/src/__tests__/index.test.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import fs from 'fs';
2-
import { describe, expect, test, vi } from 'vitest';
2+
import os from 'os';
3+
import pathlib from 'path';
4+
import { describe, expect, test, vi, type MockInstance } from 'vitest';
35
import { generateStructure } from '../structure';
46
import { generateTree } from '../tree';
57
import { isRootYamlObject, isYamlObject } from '../types';
@@ -9,6 +11,8 @@ const mockStatSync = vi.spyOn(fs, 'statSync').mockReturnValue({
911
isDirectory: () => true
1012
} as any);
1113

14+
const isWindows = os.platform() === 'win32';
15+
1216
describe('Test isYamlObject', () => {
1317
const testCases: [string, unknown, boolean][] = [
1418
['Name property is required', {}, false],
@@ -75,16 +79,26 @@ test('structure generation', () => {
7579
});
7680

7781
describe('Test tree validation', () => {
78-
const validPaths = [
79-
'/',
80-
'/real_item0',
81-
'/real_item1',
82-
'/real_item1/real_item2',
83-
];
84-
85-
mockExistsSync.mockImplementation(path => validPaths.includes(path as string));
82+
interface Fixtures {
83+
rootDir: string;
84+
validPaths: string[]
85+
mockExistsSync: MockInstance<typeof fs.existsSync>
86+
}
87+
88+
const treeTest = test.extend<Fixtures>({
89+
rootDir: ({}, use) => use(isWindows ? '\\' : '/'),
90+
validPaths: ({ rootDir }, use) => use([
91+
rootDir,
92+
pathlib.join(rootDir, 'real_item0'),
93+
pathlib.join(rootDir, 'real_item1'),
94+
pathlib.join(rootDir, 'real_item1', 'real_item2'),
95+
]),
96+
mockExistsSync: ({ validPaths }, use) => use(
97+
mockExistsSync.mockImplementation(path => validPaths.includes(path as string))
98+
)
99+
});
86100

87-
test('Successful validation', () => {
101+
treeTest('Successful validation', ({ rootDir, mockExistsSync }) => {
88102
const [,,warnings] = generateStructure({
89103
path: '.',
90104
name: 'root',
@@ -95,24 +109,23 @@ describe('Test tree validation', () => {
95109
children: ['real_item2']
96110
}
97111
]
98-
}, '/');
99-
console.log(warnings);
112+
}, rootDir);
100113
expect(warnings.length).toEqual(0);
101-
expect(fs.existsSync).toHaveBeenCalledTimes(4);
114+
expect(mockExistsSync).toHaveBeenCalledTimes(4);
102115
});
103116

104-
test('Unsuccessful validation when child item doesn\'t exist', () => {
117+
treeTest('Unsuccessful validation when child item doesn\'t exist', ({ rootDir, mockExistsSync }) => {
105118
const [,,warnings] = generateStructure({
106119
path: '.',
107120
name: 'root',
108121
children: ['fake_item0']
109-
}, '/');
122+
}, rootDir);
110123

111124
expect(warnings.length).toEqual(1);
112-
expect(fs.existsSync).toHaveBeenCalledTimes(2);
125+
expect(mockExistsSync).toHaveBeenCalledTimes(2);
113126
});
114127

115-
test('Unsuccessful validation when item with children is not a folder', () => {
128+
treeTest('Unsuccessful validation when item with children is not a folder', ({ rootDir, mockExistsSync }) => {
116129
mockStatSync.mockReturnValueOnce({
117130
isDirectory: () => false
118131
} as any);
@@ -124,14 +137,14 @@ describe('Test tree validation', () => {
124137
name: 'real_item0',
125138
children: ['real_item2']
126139
}]
127-
}, '/');
140+
}, rootDir);
128141

129142
console.log(warnings);
130143
expect(warnings.length).toEqual(1);
131-
expect(fs.existsSync).toHaveBeenCalledTimes(3);
144+
expect(mockExistsSync).toHaveBeenCalledTimes(3);
132145
});
133146

134-
test('Not providing a path means no validation is run', () => {
147+
treeTest('Not providing a path means no validation is run', ({ mockExistsSync }) => {
135148
const [,,warnings] = generateStructure({
136149
path: '.',
137150
name: 'root',
@@ -142,7 +155,7 @@ describe('Test tree validation', () => {
142155
});
143156

144157
expect(warnings.length).toEqual(0);
145-
expect(fs.existsSync).not.toHaveBeenCalled();
158+
expect(mockExistsSync).not.toHaveBeenCalled();
146159
expect(fs.statSync).not.toHaveBeenCalled();
147160
});
148161
});

0 commit comments

Comments
 (0)