Skip to content

Commit

Permalink
fix: test files are not escaped.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 29, 2023
1 parent 213c387 commit 1cce5b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
6 changes: 6 additions & 0 deletions examples/basic/src/test/sum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import { sum } from './sum';

it('sum 2 test case', async () => {
expect(sum(1, 1)).toEqual(3);
});
2 changes: 1 addition & 1 deletion examples/basic/src/test/sum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@


export function sum(a: number, b: string) {
export function sum(a: number, b: number) {
return a + b + (a);
}
5 changes: 5 additions & 0 deletions examples/react-component/src/sum.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { sum } from './sum';

it('sum 2 test case', async () => {
expect(sum(1, 1)).toEqual(2);
});
3 changes: 3 additions & 0 deletions packages/core/src/watcher/copyFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const watcherCopyFiles = (entry: string[] = [], options: CopyFilesOptions
persistent: true,
});
watcher.on('all', async (eventName, filepath, stats) => {
if (/\.(test|spec)\.(js|jsx|ts|tsx)$/i.test(filepath)) {
return;
}
if (
!/\.(m?js|jsx?|m?ts|tsx?|c?js)$/i.test(filepath) &&
rootDirsRelative &&
Expand Down
3 changes: 2 additions & 1 deletion packages/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export default async function compile(options: TsCompileOptions = {}) {
if (parseResult.errors.length) {
return parseResult.errors.forEach(reportDiagnostic);
}

// Test files are not escaped.
parseResult.fileNames = parseResult.fileNames.filter((item) => !/\.(test|spec)\.(js|jsx|ts|tsx)$/i.test(item));
const currentDir = ts.sys.getCurrentDirectory();
const rootDirsRelative = [...new Set(getRootsFolderName(parseResult.fileNames))];
const outputDir = path.resolve(currentDir, compilerOptions.outDir || 'lib');
Expand Down

0 comments on commit 1cce5b4

Please sign in to comment.