Skip to content

Commit

Permalink
add comparison test for cache / no cache
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
agilgur5 committed Jul 4, 2022
1 parent 132b8f0 commit 1710a99
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions __tests__/integration/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import { test, expect } from "@jest/globals";
import * as path from "path";
import { rollup } from "rollup";
import { rollup, OutputAsset } from "rollup";

import rpt2 from "../../src/index";
import rpt2, { RPT2Options } from "../../src/index";

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

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

const { output } = await bundle.generate({
file: './dist/index.ts',
format: 'esm',
exports: 'named'
})
const esm = await bundle.generate({
file: "./dist/index.ts",
format: "esm",
exports: "named",
});

// Rollup has some deprecated properties like `get isAsset`, so enumerating them with, e.g. `.toEqual`, causes a bunch of warnings to be output
// delete the `isAsset` property for (much) cleaner logs
const { output: files } = esm;
for (const file of files) {
if ("isAsset" in file) {
const optIsAsset = file as Partial<Pick<OutputAsset, "isAsset">> & Omit<OutputAsset, "isAsset">;
delete optIsAsset["isAsset"];
}
}

return esm;
}

test("integration - no error case", async () => {
const { output } = await genBundle("fixtures/no-errors/index.ts", { clean: true });
const { output: outputWithCache } = await genBundle("fixtures/no-errors/index.ts");

expect(output).toEqual(outputWithCache);

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

0 comments on commit 1710a99

Please sign in to comment.