Skip to content

Commit 48a7aa9

Browse files
committed
Refactor tests
1 parent b1069da commit 48a7aa9

File tree

9 files changed

+54
-75
lines changed

9 files changed

+54
-75
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const named = true;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as path from "path";
2+
import { resolvePlugin } from "../../../src/transpilation/utils";
3+
4+
test("resolve relative module paths", () => {
5+
expect(resolvePlugin("test", "test", __dirname, "./resolve.ts")).toMatchObject({
6+
result: true,
7+
});
8+
});
9+
10+
test("load .js modules", () => {
11+
expect(resolvePlugin("test", "test", __dirname, path.join(__dirname, "resolve.js"))).toMatchObject({
12+
result: true,
13+
});
14+
});
15+
16+
test("load .ts modules", () => {
17+
expect(resolvePlugin("test", "test", __dirname, path.join(__dirname, "resolve.ts"))).toMatchObject({
18+
result: true,
19+
});
20+
});
21+
22+
test('"import" option', () => {
23+
expect(resolvePlugin("test", "test", __dirname, path.join(__dirname, "import.ts"), "named")).toMatchObject({
24+
result: true,
25+
});
26+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports.default = true;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// tslint:disable-next-line: no-default-export
2+
export default true;

test/transpile/transformers/import.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/transpile/transformers/resolve.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/transpile/transformers/resolve.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,36 @@
11
import * as path from "path";
2-
import * as tstl from "../../../src";
32
import * as util from "../../util";
43

5-
test("should ignore language service plugins", () => {
4+
test("ignore language service plugins", () => {
65
util.testFunction`
7-
return;
6+
return false;
87
`
9-
.setOptions({ plugins: [{ name: path.join(__dirname, "resolve.ts") }] })
10-
.expectToEqual(undefined);
8+
.setOptions({ plugins: [{ name: path.join(__dirname, "types.ts") }] })
9+
.expectToEqual(false);
1110
});
1211

13-
describe("resolution", () => {
14-
const testTransform = (transformer: tstl.TransformerImport) => {
15-
util.testFunction`
16-
return;
17-
`
18-
.setOptions({ plugins: [transformer] })
19-
.expectToEqual(true);
20-
};
21-
22-
test("resolve relative transformer paths", () => {
23-
jest.spyOn(process, "cwd").mockReturnValue(__dirname);
24-
testTransform({ transform: "./resolve.ts" });
25-
});
26-
27-
test("load .js transformers", () => {
28-
testTransform({ transform: path.join(__dirname, "resolve.js") });
29-
});
30-
31-
test("load .ts transformers", () => {
32-
testTransform({ transform: path.join(__dirname, "resolve.ts") });
33-
});
34-
35-
test('"import" option', () => {
36-
testTransform({ transform: path.join(__dirname, "import.ts"), import: "transformer" });
37-
});
12+
test("default type", () => {
13+
util.testFunction`
14+
return false;
15+
`
16+
.setOptions({ plugins: [{ transform: path.join(__dirname, "fixtures.ts"), import: "program", value: true }] })
17+
.expectToEqual(true);
18+
});
3819

39-
test("error if transformer could not be resolved", () => {
40-
util.testModule``
41-
.setOptions({ plugins: [{ transform: path.join(__dirname, "error.ts") }] })
42-
.expectToHaveDiagnostics();
43-
});
20+
test("transformer resolution error", () => {
21+
util.testModule``
22+
.setOptions({ plugins: [{ transform: path.join(__dirname, "error.ts") }] })
23+
.expectToHaveDiagnostics();
4424
});
4525

4626
describe("factory types", () => {
47-
for (const type of ["program", "config", "checker", "raw", "compilerOptions"] as const) {
48-
test(type, () => {
49-
util.testFunction`
50-
return false;
51-
`
52-
.setOptions({
53-
plugins: [{ transform: path.join(__dirname, "types.ts"), type, import: type, value: true }],
54-
})
55-
.expectToEqual(true);
56-
});
57-
}
27+
test.each(["program", "config", "checker", "raw", "compilerOptions"] as const)("%s", type => {
28+
util.testFunction`
29+
return false;
30+
`
31+
.setOptions({
32+
plugins: [{ transform: path.join(__dirname, "fixtures.ts"), type, import: type, value: true }],
33+
})
34+
.expectToEqual(true);
35+
});
5836
});

0 commit comments

Comments
 (0)