From 9a43381ff0a84026b338c16921aa37d47771abfb Mon Sep 17 00:00:00 2001 From: Ivan Kabir Date: Fri, 9 Aug 2024 13:51:34 +0300 Subject: [PATCH] fix: do not show warnings in workers --- src/base-testplane.ts | 2 +- src/utils/typescript.ts | 28 ++++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/base-testplane.ts b/src/base-testplane.ts index 93a96afa6..be58125d1 100644 --- a/src/base-testplane.ts +++ b/src/base-testplane.ts @@ -30,7 +30,7 @@ export abstract class BaseTestplane extends AsyncEmitter { this._interceptors = []; - tryToRegisterTsNode(); + tryToRegisterTsNode(this.isWorker()); this._config = Config.create(config); this._setLogLevel(); diff --git a/src/utils/typescript.ts b/src/utils/typescript.ts index 3bced9d86..ada981dbf 100644 --- a/src/utils/typescript.ts +++ b/src/utils/typescript.ts @@ -1,7 +1,7 @@ import _ from "lodash"; import logger from "./logger"; -export const tryToRegisterTsNode = (): void => { +export const tryToRegisterTsNode = (isWorker: boolean = false): void => { if (process.env.TS_ENABLE === "false") { return; } @@ -31,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 (!isWorker) { + 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); + } } } } @@ -64,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 (!isWorker) { + 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 };