Skip to content

Commit 1710a99

Browse files
committed
add comparison test for cache / no cache
- should probably do this for each integration test suite - refactor: split out a `genBundle` func to DRY things up - this was bound to happen eventually - don't think testing other output formats is necessary since we don't have any specific logic for that, so that is just Rollup behavior - take `input` path and rpt2 options as params - and add the `tsconfig` as a default - add a hacky workaround so that Rollup doesn't output a bunch of warnings in the logs - format: use double quotes for strings consistently (my bad, I normally use single quotes in my own repos)
1 parent 132b8f0 commit 1710a99

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

__tests__/integration/index.spec.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,44 @@
11
import { test, expect } from "@jest/globals";
22
import * as path from "path";
3-
import { rollup } from "rollup";
3+
import { rollup, OutputAsset } from "rollup";
44

5-
import rpt2 from "../../src/index";
5+
import rpt2, { RPT2Options } from "../../src/index";
66

77
const local = (x: string) => path.resolve(__dirname, x);
88

9-
test("integration - no error case", async () => {
9+
async function genBundle (input: string, extraOpts?: RPT2Options) {
1010
const bundle = await rollup({
11-
input: local("fixtures/no-errors/index.ts"),
11+
input: local(input),
1212
plugins: [rpt2({
1313
tsconfig: local("fixtures/tsconfig.json"),
14+
...extraOpts,
1415
})],
1516
});
1617

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);
2242

2343
expect(output[0].fileName).toEqual("index.ts");
2444
expect(output[1].fileName).toEqual("index.d.ts");

0 commit comments

Comments
 (0)