From 8bb43e70a892368653189db5a53b169840838db2 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Thu, 7 Mar 2024 14:32:46 +0300 Subject: [PATCH] feat: add ability to use import and export in test files --- src/utils/typescript.ts | 3 +++ test/src/utils/typescript.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/utils/typescript.ts b/src/utils/typescript.ts index 09b0af1df..6cb19c26b 100644 --- a/src/utils/typescript.ts +++ b/src/utils/typescript.ts @@ -27,6 +27,9 @@ export const tryToRegisterTsNode = (): void => { skipProject: JSON.parse(skipProjectRaw), transpileOnly: JSON.parse(transpileOnlyRaw), swc: JSON.parse(swcRaw), + compilerOptions: { + allowJs: true, + }, }); } catch (err) { const params = `swc: "${swcRaw}", transpileOnly: "${transpileOnlyRaw}", skipProject: "${skipProjectRaw}"`; diff --git a/test/src/utils/typescript.ts b/test/src/utils/typescript.ts index 282505ef8..fc78e4e1e 100644 --- a/test/src/utils/typescript.ts +++ b/test/src/utils/typescript.ts @@ -33,6 +33,19 @@ describe("utils/typescript", () => { assert.notCalled(registerStub); }); + it("should pass 'allowJs' option", () => { + ts.tryToRegisterTsNode(); + + assert.calledOnceWith( + registerStub, + sinon.match({ + compilerOptions: { + allowJs: true, + }, + }), + ); + }); + it("should respect env vars", () => { process.env.TS_NODE_SKIP_PROJECT = "false"; process.env.TS_NODE_TRANSPILE_ONLY = "false";