Skip to content

Commit

Permalink
fix: fix swc warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Kabir-Ivan committed Aug 9, 2024
1 parent 8cdcd15 commit 6afa848
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/base-testplane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export abstract class BaseTestplane extends AsyncEmitter {

this._interceptors = [];

tryToRegisterTsNode();
tryToRegisterTsNode(this.isWorker());

this._config = Config.create(config);
this._setLogLevel();
Expand Down
29 changes: 17 additions & 12 deletions src/utils/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from "lodash";
import logger from "./logger";

export const tryToRegisterTsNode = (): void => {
export const tryToRegisterTsNode = (isSilent: boolean = false): void => {
if (process.env.TS_ENABLE === "false") {
return;
}
Expand All @@ -22,6 +22,7 @@ export const tryToRegisterTsNode = (): void => {

if (JSON.parse(swcRaw)) {
try {
require("@swc/core");
register({
skipProject: JSON.parse(skipProjectRaw),
transpileOnly: JSON.parse(transpileOnlyRaw),
Expand All @@ -30,12 +31,14 @@ export const tryToRegisterTsNode = (): void => {
return;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
if (err.code === "MODULE_NOT_FOUND") {
logger.warn(
`testplane: you may install @swc/core for significantly faster reading of typescript tests.`,
);
} else {
logger.warn(`testplane: could not load @swc/core:`, err);
if (!isSilent) {
if (err.code === "MODULE_NOT_FOUND") {
logger.warn(
`testplane: you may install @swc/core for significantly faster reading of typescript tests.`,
);
} else {
logger.warn(`testplane: could not load @swc/core:`, err);
}
}
}
}
Expand Down Expand Up @@ -63,11 +66,13 @@ export const tryToRegisterTsNode = (): void => {
return;
// eslint-disable-next-line no-empty
} catch (err) {
const params = `swc: "false", transpileOnly: "${transpileOnlyRaw}", skipProject: "${skipProjectRaw}"`;
logger.warn(
`testplane: an error occured while trying to register ts-node (${params}). TypeScript tests won't be read:`,
err,
);
if (!isSilent) {
const params = `swc: "false", transpileOnly: "${transpileOnlyRaw}", skipProject: "${skipProjectRaw}"`;
logger.warn(
`testplane: an error occured while trying to register ts-node (${params}). TypeScript tests won't be read:`,
err,
);
}
}
} catch {} // eslint-disable-line no-empty
};

0 comments on commit 6afa848

Please sign in to comment.