/
config-ts.js
73 lines (64 loc) 路 1.85 KB
/
config-ts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { loadPartialConfigSync } from "../lib/index.js";
import path from "path";
import { fileURLToPath } from "url";
import { createRequire } from "module";
import { register } from "ts-node";
import semver from "semver";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const require = createRequire(import.meta.url);
describe("@babel/core config with ts", () => {
semver.gte(process.version, "12.0.0")
? it
: it.skip("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",
),
});
}).toThrow(/Unexpected identifier.*/);
delete require.extensions[".ts"];
});
it("should work with ts-node", () => {
const service = register({
experimentalResolver: true,
compilerOptions: {
module: "CommonJS",
},
});
service.enabled(true);
require(path.join(
__dirname,
"fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts",
));
const config = loadPartialConfigSync({
configFile: path.join(
__dirname,
"fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts",
),
});
service.enabled(false);
expect(config.options.targets).toMatchInlineSnapshot(`
Object {
"node": "12.0.0",
}
`);
});
});