Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Jan 12, 2023
1 parent 8a71976 commit e90dd47
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions packages/babel-core/test/config-ts.js
Expand Up @@ -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",
Expand Down Expand Up @@ -69,4 +79,4 @@ describe("@babel/core config with ts", () => {
}
`);
});
});
});

0 comments on commit e90dd47

Please sign in to comment.