Skip to content

Commit 7d8a276

Browse files
author
Luca Forstner
committed
Add test
1 parent 404a8e5 commit 7d8a276

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* eslint-disable jest/no-standalone-expect */
2+
/* eslint-disable jest/expect-expect */
3+
import childProcess from "child_process";
4+
import path from "path";
5+
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
6+
7+
function checkBundle(bundlePath1: string, bundlePath2: string) {
8+
const process1Output = childProcess.execSync(`node ${bundlePath1}`, { encoding: "utf-8" });
9+
const debugIdMap1 = JSON.parse(process1Output) as Record<string, string>;
10+
const debugIds1 = Object.values(debugIdMap1);
11+
expect(debugIds1).toHaveLength(0);
12+
13+
const process2Output = childProcess.execSync(`node ${bundlePath2}`, { encoding: "utf-8" });
14+
const debugIdMap2 = JSON.parse(process2Output) as Record<string, string>;
15+
const debugIds2 = Object.values(debugIdMap2);
16+
expect(debugIds2).toHaveLength(0);
17+
}
18+
19+
describe("should not inject debug IDs when `sourcemaps.disable` is `true`", () => {
20+
test("esbuild bundle", () => {
21+
checkBundle(
22+
path.join(__dirname, "out", "esbuild", "bundle1.js"),
23+
path.join(__dirname, "out", "esbuild", "bundle2.js")
24+
);
25+
});
26+
27+
test("rollup bundle", () => {
28+
checkBundle(
29+
path.join(__dirname, "out", "rollup", "bundle1.js"),
30+
path.join(__dirname, "out", "rollup", "bundle2.js")
31+
);
32+
});
33+
34+
test("vite bundle", () => {
35+
checkBundle(
36+
path.join(__dirname, "out", "vite", "bundle1.js"),
37+
path.join(__dirname, "out", "vite", "bundle2.js")
38+
);
39+
});
40+
41+
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
42+
checkBundle(
43+
path.join(__dirname, "out", "webpack4", "bundle1.js"),
44+
path.join(__dirname, "out", "webpack4", "bundle2.js")
45+
);
46+
});
47+
48+
test("webpack 5 bundle", () => {
49+
checkBundle(
50+
path.join(__dirname, "out", "webpack5", "bundle1.js"),
51+
path.join(__dirname, "out", "webpack5", "bundle2.js")
52+
);
53+
});
54+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-console
2+
console.log(JSON.stringify(global._sentryDebugIds));
3+
4+
// Just so the two bundles generate different hashes:
5+
global.iAmBundle1 = 1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-console
2+
console.log(JSON.stringify(global._sentryDebugIds));
3+
4+
// Just so the two bundles generate different hashes:
5+
global.iAmBundle2 = 2;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as path from "path";
2+
import { createCjsBundles } from "../../utils/create-cjs-bundles";
3+
4+
const outputDir = path.resolve(__dirname, "out");
5+
6+
createCjsBundles(
7+
{
8+
bundle1: path.resolve(__dirname, "input", "bundle1.js"),
9+
bundle2: path.resolve(__dirname, "input", "bundle2.js"),
10+
},
11+
outputDir,
12+
{
13+
telemetry: false,
14+
sourcemaps: {
15+
disable: true,
16+
},
17+
}
18+
);

0 commit comments

Comments
 (0)