Skip to content

Commit 77f1afa

Browse files
committed
tests: added tests to confirm bug
1 parent 70e8927 commit 77f1afa

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Output both debug IDs and metadata to verify both features work together
2+
// eslint-disable-next-line no-console
3+
console.log(
4+
JSON.stringify({
5+
debugIds: global._sentryDebugIds,
6+
metadata: global._sentryModuleMetadata,
7+
})
8+
);
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable jest/no-standalone-expect */
2+
/* eslint-disable jest/expect-expect */
3+
import { execSync } from "child_process";
4+
import path from "path";
5+
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
6+
7+
interface BundleOutput {
8+
debugIds: Record<string, string> | undefined;
9+
metadata: Record<string, unknown> | undefined;
10+
}
11+
12+
function checkBundle(bundlePath: string): void {
13+
const output = execSync(`node ${bundlePath}`, { encoding: "utf-8" });
14+
const result = JSON.parse(output) as BundleOutput;
15+
16+
// Check that debug IDs are present
17+
expect(result.debugIds).toBeDefined();
18+
const debugIds = Object.values(result.debugIds ?? {});
19+
expect(debugIds.length).toBeGreaterThan(0);
20+
// Verify debug ID format (UUID v4)
21+
expect(debugIds).toContainEqual(
22+
expect.stringMatching(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/)
23+
);
24+
// The key should be a stack trace
25+
expect(Object.keys(result.debugIds ?? {})[0]).toContain("Error");
26+
27+
// Check that metadata is present
28+
expect(result.metadata).toBeDefined();
29+
const metadataValues = Object.values(result.metadata ?? {});
30+
expect(metadataValues).toHaveLength(1);
31+
expect(metadataValues).toEqual([{ team: "frontend" }]);
32+
// The key should be a stack trace
33+
expect(Object.keys(result.metadata ?? {})[0]).toContain("Error");
34+
}
35+
36+
describe("metadata with debug ID injection", () => {
37+
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
38+
checkBundle(path.join(__dirname, "out", "webpack4", "bundle.js"));
39+
});
40+
41+
test("webpack 5 bundle", () => {
42+
checkBundle(path.join(__dirname, "out", "webpack5", "bundle.js"));
43+
});
44+
45+
test("esbuild bundle", () => {
46+
checkBundle(path.join(__dirname, "out", "esbuild", "bundle.js"));
47+
});
48+
49+
test("rollup bundle", () => {
50+
checkBundle(path.join(__dirname, "out", "rollup", "bundle.js"));
51+
});
52+
53+
test("vite bundle", () => {
54+
checkBundle(path.join(__dirname, "out", "vite", "bundle.js"));
55+
});
56+
});
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+
bundle: path.resolve(__dirname, "input", "bundle.js"),
9+
},
10+
outputDir,
11+
{
12+
// Enable both moduleMetadata AND debug ID injection (sourcemaps enabled by default)
13+
moduleMetadata: { team: "frontend" },
14+
telemetry: false,
15+
release: { name: "test-release", create: false },
16+
},
17+
["webpack4", "webpack5", "esbuild", "rollup", "vite"]
18+
);

0 commit comments

Comments
 (0)