Skip to content

Commit

Permalink
test: ensure declarationMap sources are correct
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
agilgur5 committed Jul 26, 2022
1 parent 37f4247 commit 100e853
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions __tests__/integration/no-errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { jest, afterAll, test, expect } from "@jest/globals";
import * as path from "path";
import * as fs from "fs-extra";
import { OutputAsset } from "rollup";
import { normalizePath as normalize } from "@rollup/pluginutils";

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

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

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

async function genBundle(relInput: string, extraOpts?: RPT2Options) {
return helpers.genBundle({
input: local(`fixtures/no-errors/${relInput}`),
tsconfig: local("fixtures/no-errors/tsconfig.json"),
input: `${fixtureDir}/${relInput}`,
tsconfig: `${fixtureDir}/tsconfig.json`,
testDir,
extraOpts,
});
Expand All @@ -41,6 +44,11 @@ test("integration - no errors", async () => {

// JS file should be bundled by Rollup, even though rpt2 does not resolve it (as Rollup natively understands ESM)
expect(output[0].code).toEqual(expect.stringContaining("identity"));

// declaration map sources should be correctly remapped (and not point to placeholder dir, c.f. https://github.com/ezolenko/rollup-plugin-typescript2/pull/221)
const decMapSources = JSON.parse((output[2] as OutputAsset).source as string).sources;
const decRelPath = normalize(path.relative(`${testDir}/dist`, `${fixtureDir}/index.ts`));
expect(decMapSources).toEqual([decRelPath]);
});

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

0 comments on commit 100e853

Please sign in to comment.