Skip to content

Commit 100e853

Browse files
committed
test: ensure declarationMap sources are correct
- since we set a placeholder `outDir` initially, TS sets declaration map sources to that placeholder dir - then, after ec0568b, we remap that to the correct dir that Rollup outputs to - this test checks that the remap happens and is correct
1 parent 37f4247 commit 100e853

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

__tests__/integration/no-errors.spec.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { jest, afterAll, test, expect } from "@jest/globals";
22
import * as path from "path";
33
import * as fs from "fs-extra";
4+
import { OutputAsset } from "rollup";
5+
import { normalizePath as normalize } from "@rollup/pluginutils";
46

57
import { RPT2Options } from "../../src/index";
68
import * as helpers from "./helpers";
@@ -10,13 +12,14 @@ jest.setTimeout(15000);
1012

1113
const local = (x: string) => path.resolve(__dirname, x);
1214
const testDir = local("__temp/no-errors");
15+
const fixtureDir = local("fixtures/no-errors");
1316

1417
afterAll(() => fs.remove(testDir));
1518

1619
async function genBundle(relInput: string, extraOpts?: RPT2Options) {
1720
return helpers.genBundle({
18-
input: local(`fixtures/no-errors/${relInput}`),
19-
tsconfig: local("fixtures/no-errors/tsconfig.json"),
21+
input: `${fixtureDir}/${relInput}`,
22+
tsconfig: `${fixtureDir}/tsconfig.json`,
2023
testDir,
2124
extraOpts,
2225
});
@@ -41,6 +44,11 @@ test("integration - no errors", async () => {
4144

4245
// JS file should be bundled by Rollup, even though rpt2 does not resolve it (as Rollup natively understands ESM)
4346
expect(output[0].code).toEqual(expect.stringContaining("identity"));
47+
48+
// declaration map sources should be correctly remapped (and not point to placeholder dir, c.f. https://github.com/ezolenko/rollup-plugin-typescript2/pull/221)
49+
const decMapSources = JSON.parse((output[2] as OutputAsset).source as string).sources;
50+
const decRelPath = normalize(path.relative(`${testDir}/dist`, `${fixtureDir}/index.ts`));
51+
expect(decMapSources).toEqual([decRelPath]);
4452
});
4553

4654
test("integration - no errors - no declaration maps", async () => {

0 commit comments

Comments
 (0)