|
| 1 | +import { jest, afterAll, test, expect } from "@jest/globals"; |
| 2 | +import * as path from "path"; |
| 3 | +import * as fs from "fs-extra"; |
| 4 | + |
| 5 | +import { RPT2Options } from "../../src/index"; |
| 6 | +import * as helpers from "./helpers"; |
| 7 | + |
| 8 | +// increase timeout to 15s for whole file since CI occassionally timed out -- these are integration and cache tests, so longer timeout is warranted |
| 9 | +jest.setTimeout(15000); |
| 10 | + |
| 11 | +const local = (x: string) => path.resolve(__dirname, x); |
| 12 | +const cacheRoot = local("__temp/no-errors/rpt2-cache"); // don't use the one in node_modules |
| 13 | + |
| 14 | +afterAll(() => fs.remove(cacheRoot)); |
| 15 | + |
| 16 | +async function genBundle(relInput: string, extraOpts?: RPT2Options) { |
| 17 | + return helpers.genBundle({ |
| 18 | + input: local(`fixtures/no-errors/${relInput}`), |
| 19 | + tsconfig: local("fixtures/no-errors/tsconfig.json"), |
| 20 | + cacheRoot, |
| 21 | + extraOpts, |
| 22 | + }); |
| 23 | +} |
| 24 | + |
| 25 | +test("integration - no errors", async () => { |
| 26 | + const { output } = await genBundle("index.ts", { clean: true }); |
| 27 | + |
| 28 | + // populate the cache |
| 29 | + await genBundle("index.ts"); |
| 30 | + const { output: outputWithCache } = await genBundle("index.ts"); |
| 31 | + expect(output).toEqual(outputWithCache); |
| 32 | + |
| 33 | + expect(output[0].fileName).toEqual("index.js"); |
| 34 | + expect(output[1].fileName).toEqual("index.d.ts"); |
| 35 | + expect(output[2].fileName).toEqual("index.d.ts.map"); |
| 36 | + expect(output[3].fileName).toEqual("some-import.d.ts"); |
| 37 | + expect(output[4].fileName).toEqual("some-import.d.ts.map"); |
| 38 | + expect(output[5].fileName).toEqual("type-only-import.d.ts"); |
| 39 | + expect(output[6].fileName).toEqual("type-only-import.d.ts.map"); |
| 40 | + expect(output.length).toEqual(7); // no other files |
| 41 | + |
| 42 | + // JS file should be bundled by Rollup, even though rpt2 does not resolve it (as Rollup natively understands ESM) |
| 43 | + expect(output[0].code).toEqual(expect.stringContaining("identity")); |
| 44 | +}); |
| 45 | + |
| 46 | +test("integration - no errors - no declaration maps", async () => { |
| 47 | + const noDeclarationMaps = { compilerOptions: { declarationMap: false } }; |
| 48 | + const { output } = await genBundle("index.ts", { |
| 49 | + tsconfigOverride: noDeclarationMaps, |
| 50 | + clean: true, |
| 51 | + }); |
| 52 | + |
| 53 | + expect(output[0].fileName).toEqual("index.js"); |
| 54 | + expect(output[1].fileName).toEqual("index.d.ts"); |
| 55 | + expect(output[2].fileName).toEqual("some-import.d.ts"); |
| 56 | + expect(output[3].fileName).toEqual("type-only-import.d.ts"); |
| 57 | + expect(output.length).toEqual(4); // no other files |
| 58 | +}); |
| 59 | + |
| 60 | + |
| 61 | +test("integration - no errors - no declarations", async () => { |
| 62 | + const noDeclarations = { compilerOptions: { declaration: false, declarationMap: false } }; |
| 63 | + const { output } = await genBundle("index.ts", { |
| 64 | + tsconfigOverride: noDeclarations, |
| 65 | + clean: true, |
| 66 | + }); |
| 67 | + |
| 68 | + expect(output[0].fileName).toEqual("index.js"); |
| 69 | + expect(output.length).toEqual(1); // no other files |
| 70 | +}); |
| 71 | + |
| 72 | +test("integration - no errors - allowJs + emitDeclarationOnly", async () => { |
| 73 | + const { output } = await genBundle("some-js-import.js", { |
| 74 | + include: ["**/*.js"], |
| 75 | + tsconfigOverride: { |
| 76 | + compilerOptions: { |
| 77 | + allowJs: true, |
| 78 | + emitDeclarationOnly: true, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }); |
| 82 | + |
| 83 | + expect(output[0].fileName).toEqual("index.js"); |
| 84 | + expect(output[1].fileName).toEqual("some-js-import.d.ts"); |
| 85 | + expect(output[2].fileName).toEqual("some-js-import.d.ts.map"); |
| 86 | + expect(output.length).toEqual(3); // no other files |
| 87 | + |
| 88 | + expect(output[0].code).toEqual(expect.stringContaining("identity")); |
| 89 | + expect(output[0].code).not.toEqual(expect.stringContaining("sum")); // no TS files included |
| 90 | + expect("source" in output[1] && output[1].source).toEqual(expect.stringContaining("identity")); |
| 91 | +}); |
0 commit comments