|
| 1 | +import * as path from "path"; |
| 2 | +import * as tstl from "../../../src"; |
| 3 | +import * as util from "../../util"; |
| 4 | + |
| 5 | +const optionsOfTransformer = (transformer: tstl.TransformerImport): tstl.CompilerOptions => ({ |
| 6 | + plugins: [transformer], |
| 7 | +}); |
| 8 | + |
| 9 | +test("should ignore language service plugins", () => { |
| 10 | + util.testFunction` |
| 11 | + return; |
| 12 | + ` |
| 13 | + .setOptions({ plugins: [{ name: path.join(__dirname, "resolve.ts") }] }) |
| 14 | + .expectToEqual(undefined); |
| 15 | +}); |
| 16 | + |
| 17 | +describe("resolution", () => { |
| 18 | + const testTransform = (transformer: tstl.TransformerImport) => { |
| 19 | + util.testFunction` |
| 20 | + return; |
| 21 | + ` |
| 22 | + .setOptions(optionsOfTransformer(transformer)) |
| 23 | + .expectToEqual(true); |
| 24 | + }; |
| 25 | + |
| 26 | + test("resolve relative transformer paths", () => { |
| 27 | + jest.spyOn(process, "cwd").mockReturnValue(__dirname); |
| 28 | + testTransform({ transform: "./resolve.ts" }); |
| 29 | + }); |
| 30 | + |
| 31 | + test("load .js transformers", () => { |
| 32 | + testTransform({ transform: path.join(__dirname, "resolve.js") }); |
| 33 | + }); |
| 34 | + |
| 35 | + test("load .ts transformers", () => { |
| 36 | + testTransform({ transform: path.join(__dirname, "resolve.ts") }); |
| 37 | + }); |
| 38 | + |
| 39 | + test('"import" option', () => { |
| 40 | + testTransform({ transform: path.join(__dirname, "import.ts"), import: "transformer" }); |
| 41 | + }); |
| 42 | + |
| 43 | + test("error if transformer could not be resolved", () => { |
| 44 | + util.testModule`` |
| 45 | + .setOptions(optionsOfTransformer({ transform: path.join(__dirname, "error.ts") })) |
| 46 | + .expectToHaveDiagnostics(); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +describe("factory types", () => { |
| 51 | + for (const type of ["program", "config", "checker", "raw", "compilerOptions"] as const) { |
| 52 | + test(type, () => { |
| 53 | + const options = optionsOfTransformer({ |
| 54 | + transform: path.join(__dirname, "types.ts"), |
| 55 | + type, |
| 56 | + import: type, |
| 57 | + value: true, |
| 58 | + }); |
| 59 | + |
| 60 | + util.testFunction` |
| 61 | + return false; |
| 62 | + ` |
| 63 | + .setOptions(options) |
| 64 | + .expectToEqual(true); |
| 65 | + }); |
| 66 | + } |
| 67 | +}); |
0 commit comments