Skip to content

Commit ce59760

Browse files
committed
fix: Fix parsing
1 parent 3135304 commit ce59760

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/Modules/Worker/WorkerController.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface WorkerThread {
2525
}
2626

2727
const controllerDefaultOptions: TestControllerOptions = {
28-
testFileRegex: /.*(test|spec)\.ts/gm,
28+
testFileRegex: /.*(test|spec)\.((ts|js)x?)$/gm,
2929
};
3030

3131
interface WorkerControllerEventMap {
@@ -97,45 +97,41 @@ export class WorkerController extends BaseEventEmitter<
9797
*/
9898
public async findTestFiles(rootDir: string): Promise<void> {
9999
const controllerOptions = this.options;
100+
const testFiles = this.testFiles;
100101

101-
async function processDirectory(
102-
directoryPath: string,
103-
): Promise<TestFile[]> {
102+
async function processDirectory(directoryPath: string): Promise<void> {
104103
const directoryContents = await fs.readdir(directoryPath, {
105104
withFileTypes: true,
106105
encoding: 'utf-8',
107106
});
108107

109-
const testFiles = await Promise.all(
108+
await Promise.all(
110109
directoryContents.map(async (dirContent) => {
111110
const contentName = dirContent.name;
112111
const contentPath = resolvePath(directoryPath, contentName);
113112

113+
if (controllerOptions.testFileRegex.test(contentName)) {
114+
testFiles.push(
115+
new TestFile({
116+
path: contentPath,
117+
}),
118+
);
119+
120+
return;
121+
}
122+
114123
if (contentName === 'node_modules') {
115-
return [];
124+
return;
116125
}
117126

118127
if (dirContent.isDirectory()) {
119128
return processDirectory(contentPath);
120129
}
121-
122-
if (controllerOptions.testFileRegex.test(dirContent.name)) {
123-
return [
124-
new TestFile({
125-
path: contentPath,
126-
}),
127-
];
128-
}
129-
130-
return [];
131130
}),
132131
);
133-
134-
return testFiles.filter(Boolean).flat();
135132
}
136133

137-
const testFiles = await processDirectory(rootDir);
138-
this.testFiles.push(...testFiles);
134+
await processDirectory(rootDir);
139135
}
140136

141137
/**

0 commit comments

Comments
 (0)