|
1 | 1 | import { test, expect } from "@jest/globals";
|
2 | 2 | import * as path from "path";
|
3 |
| -import { rollup } from "rollup"; |
| 3 | +import { rollup, OutputAsset } from "rollup"; |
4 | 4 |
|
5 |
| -import rpt2 from "../../src/index"; |
| 5 | +import rpt2, { RPT2Options } from "../../src/index"; |
6 | 6 |
|
7 | 7 | const local = (x: string) => path.resolve(__dirname, x);
|
8 | 8 |
|
9 |
| -test("integration - no error case", async () => { |
| 9 | +async function genBundle (input: string, extraOpts?: RPT2Options) { |
10 | 10 | const bundle = await rollup({
|
11 |
| - input: local("fixtures/no-errors/index.ts"), |
| 11 | + input: local(input), |
12 | 12 | plugins: [rpt2({
|
13 | 13 | tsconfig: local("fixtures/tsconfig.json"),
|
| 14 | + ...extraOpts, |
14 | 15 | })],
|
15 | 16 | });
|
16 | 17 |
|
17 |
| - const { output } = await bundle.generate({ |
18 |
| - file: './dist/index.ts', |
19 |
| - format: 'esm', |
20 |
| - exports: 'named' |
21 |
| - }) |
| 18 | + const esm = await bundle.generate({ |
| 19 | + file: "./dist/index.ts", |
| 20 | + format: "esm", |
| 21 | + exports: "named", |
| 22 | + }); |
| 23 | + |
| 24 | + // Rollup has some deprecated properties like `get isAsset`, so enumerating them with, e.g. `.toEqual`, causes a bunch of warnings to be output |
| 25 | + // delete the `isAsset` property for (much) cleaner logs |
| 26 | + const { output: files } = esm; |
| 27 | + for (const file of files) { |
| 28 | + if ("isAsset" in file) { |
| 29 | + const optIsAsset = file as Partial<Pick<OutputAsset, "isAsset">> & Omit<OutputAsset, "isAsset">; |
| 30 | + delete optIsAsset["isAsset"]; |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + return esm; |
| 35 | +} |
| 36 | + |
| 37 | +test("integration - no error case", async () => { |
| 38 | + const { output } = await genBundle("fixtures/no-errors/index.ts", { clean: true }); |
| 39 | + const { output: outputWithCache } = await genBundle("fixtures/no-errors/index.ts"); |
| 40 | + |
| 41 | + expect(output).toEqual(outputWithCache); |
22 | 42 |
|
23 | 43 | expect(output[0].fileName).toEqual("index.ts");
|
24 | 44 | expect(output[1].fileName).toEqual("index.d.ts");
|
|
0 commit comments