Skip to content

Commit 874270e

Browse files
committed
test: ensure that JS files are part of bundle too
- ensures that TS understands the JS w/ DTS w/o error - and that rpt2 filters out JS while Rollup still resolves it on its own (since Rollup understands ESM) - similar to testing w/ a different plugin (i.e. literally testing an "integration"), but this is native Rollup behavior in this case where it doesn't need a plugin to understand ESM
1 parent 078aaf8 commit 874270e

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

__tests__/integration/fixtures/no-errors/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export function sum(a: number, b: number) {
44

55
export { difference } from "./some-import"
66
export type { num } from "./type-only-import"
7+
8+
export { identity } from "./some-js-import"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// TS needs a declaration in order to understand the import
2+
// but this is ambient, and so should not be directly imported into rpt2, just found by TS
3+
4+
export function identity(a: any): any;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// should be filtered out by rpt2, but still bundled by Rollup itself (as this is ESM, no need for a plugin)
2+
3+
export function identity(a) {
4+
return a;
5+
}

__tests__/integration/index.spec.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ async function genBundle (input: string, extraOpts?: RPT2Options) {
4444

4545
test("integration - no errors", async () => {
4646
const { output } = await genBundle("fixtures/no-errors/index.ts", { clean: true });
47+
4748
// populate the cache
4849
await genBundle("fixtures/no-errors/index.ts");
4950
const { output: outputWithCache } = await genBundle("fixtures/no-errors/index.ts");
50-
5151
expect(output).toEqual(outputWithCache);
5252

53+
// JS file should be bundled by Rollup, even though rpt2 does not resolve it (as Rollup natively understands ESM)
54+
expect(output[0].code).toEqual(expect.stringContaining("identity"));
55+
5356
expect(output[0].fileName).toEqual("index.ts");
5457
expect(output[1].fileName).toEqual("index.d.ts");
5558
expect(output[2].fileName).toEqual("index.d.ts.map");
@@ -66,12 +69,12 @@ test("integration - no errors - no declaration maps", async () => {
6669
tsconfigOverride: noDeclarationMaps,
6770
clean: true,
6871
});
72+
6973
// populate the cache
7074
await genBundle("fixtures/no-errors/index.ts", { tsconfigOverride: noDeclarationMaps });
7175
const { output: outputWithCache } = await genBundle("fixtures/no-errors/index.ts", {
7276
tsconfigOverride: noDeclarationMaps,
7377
});
74-
7578
expect(output).toEqual(outputWithCache);
7679

7780
expect(output[0].fileName).toEqual("index.ts");
@@ -88,12 +91,12 @@ test("integration - no errors - no declarations", async () => {
8891
tsconfigOverride: noDeclarations,
8992
clean: true,
9093
});
94+
9195
// populate the cache
9296
await genBundle("fixtures/no-errors/index.ts", { tsconfigOverride: noDeclarations });
9397
const { output: outputWithCache } = await genBundle("fixtures/no-errors/index.ts", {
9498
tsconfigOverride: noDeclarations,
9599
});
96-
97100
expect(output).toEqual(outputWithCache);
98101

99102
expect(output[0].fileName).toEqual("index.ts");

0 commit comments

Comments
 (0)