Skip to content

Commit

Permalink
fix: Fix parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
EntraptaJ committed May 31, 2020
1 parent 3135304 commit ce59760
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/Modules/Worker/WorkerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface WorkerThread {
}

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

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

async function processDirectory(
directoryPath: string,
): Promise<TestFile[]> {
async function processDirectory(directoryPath: string): Promise<void> {
const directoryContents = await fs.readdir(directoryPath, {
withFileTypes: true,
encoding: 'utf-8',
});

const testFiles = await Promise.all(
await Promise.all(
directoryContents.map(async (dirContent) => {
const contentName = dirContent.name;
const contentPath = resolvePath(directoryPath, contentName);

if (controllerOptions.testFileRegex.test(contentName)) {
testFiles.push(
new TestFile({
path: contentPath,
}),
);

return;
}

if (contentName === 'node_modules') {
return [];
return;
}

if (dirContent.isDirectory()) {
return processDirectory(contentPath);
}

if (controllerOptions.testFileRegex.test(dirContent.name)) {
return [
new TestFile({
path: contentPath,
}),
];
}

return [];
}),
);

return testFiles.filter(Boolean).flat();
}

const testFiles = await processDirectory(rootDir);
this.testFiles.push(...testFiles);
await processDirectory(rootDir);
}

/**
Expand Down

0 comments on commit ce59760

Please sign in to comment.