From e90dd4735f0768169b11eda349230b61df5ab48c Mon Sep 17 00:00:00 2001 From: liuxingbaoyu <30521560+liuxingbaoyu@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:38:41 +0800 Subject: [PATCH] fix test --- packages/babel-core/test/config-ts.js | 66 +++++++++++++++------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/packages/babel-core/test/config-ts.js b/packages/babel-core/test/config-ts.js index f22c574ec308..77d389d32982 100644 --- a/packages/babel-core/test/config-ts.js +++ b/packages/babel-core/test/config-ts.js @@ -7,41 +7,51 @@ import semver from "semver"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const require = createRequire(import.meta.url); -describe("@babel/core config with ts", () => { - it("should work with simple .cts", () => { - const config = loadPartialConfigSync({ - configFile: path.join( - __dirname, - "fixtures/config-ts/simple-cts/babel.config.cts", - ), - }); +// We skip older versions of node testing for two reasons. +// 1. ts-node does not support the old version of node. +// 2. In the old version of node, jest has been registered in `require.extensions`, which will cause babel to disable the transforming as expected. - expect(config.options.targets).toMatchInlineSnapshot(` +describe("@babel/core config with ts [dummy]", () => { + it("dummy", () => { + expect(1).toBe(1); + }); +}); + +semver.gte(process.version, "12.0.0") + ? describe + : describe.skip("@babel/core config with ts", () => { + it("should work with simple .cts", () => { + const config = loadPartialConfigSync({ + configFile: path.join( + __dirname, + "fixtures/config-ts/simple-cts/babel.config.cts", + ), + }); + + expect(config.options.targets).toMatchInlineSnapshot(` Object { "node": "12.0.0", } `); - }); + }); - it("should throw with invalid .ts register", () => { - require.extensions[".ts"] = () => { - throw new Error("Not support .ts."); - }; - expect(() => { - loadPartialConfigSync({ - configFile: path.join( - __dirname, - "fixtures/config-ts/invalid-cts-register/babel.config.cts", - ), + it("should throw with invalid .ts register", () => { + require.extensions[".ts"] = () => { + throw new Error("Not support .ts."); + }; + expect(() => { + loadPartialConfigSync({ + configFile: path.join( + __dirname, + "fixtures/config-ts/invalid-cts-register/babel.config.cts", + ), + }); + }).toThrow(/Unexpected identifier.*/); + delete require.extensions[".ts"]; }); - }).toThrow(/Unexpected identifier.*/); - delete require.extensions[".ts"]; - }); - semver.gte(process.version, "12.0.0") - ? it - : it.skip("should work with ts-node", async () => { - const service = import("ts-node").register({ + it("should work with ts-node", async () => { + const service = eval("import('ts-node')").register({ experimentalResolver: true, compilerOptions: { module: "CommonJS", @@ -69,4 +79,4 @@ describe("@babel/core config with ts", () => { } `); }); -}); + });