Skip to content

Commit 65c3e76

Browse files
committed
test: added applicationKey setting tests
1 parent 8f92c31 commit 65c3e76

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 applicationKey metadata is present
28+
expect(result.metadata).toBeDefined();
29+
const metadataValues = Object.values(result.metadata ?? {});
30+
expect(metadataValues).toHaveLength(1);
31+
// applicationKey sets a special key in the metadata
32+
expect(metadataValues[0]).toEqual({ "_sentryBundlerPluginAppKey:my-app-key": true });
33+
// The key should be a stack trace
34+
expect(Object.keys(result.metadata ?? {})[0]).toContain("Error");
35+
}
36+
37+
describe("applicationKey with debug ID injection", () => {
38+
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
39+
checkBundle(path.join(__dirname, "out", "webpack4", "bundle.js"));
40+
});
41+
42+
test("webpack 5 bundle", () => {
43+
checkBundle(path.join(__dirname, "out", "webpack5", "bundle.js"));
44+
});
45+
46+
test("esbuild bundle", () => {
47+
checkBundle(path.join(__dirname, "out", "esbuild", "bundle.js"));
48+
});
49+
50+
test("rollup bundle", () => {
51+
checkBundle(path.join(__dirname, "out", "rollup", "bundle.js"));
52+
});
53+
54+
test("vite bundle", () => {
55+
checkBundle(path.join(__dirname, "out", "vite", "bundle.js"));
56+
});
57+
});
58+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access */
2+
// Output both debug IDs and metadata to verify applicationKey works with debug ID injection
3+
// eslint-disable-next-line no-console
4+
console.log(
5+
JSON.stringify({
6+
debugIds: global._sentryDebugIds,
7+
metadata: global._sentryModuleMetadata,
8+
})
9+
);
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 applicationKey AND debug ID injection (sourcemaps enabled by default)
13+
applicationKey: "my-app-key",
14+
telemetry: false,
15+
release: { name: "test-release", create: false },
16+
},
17+
["webpack4", "webpack5", "esbuild", "rollup", "vite"]
18+
);

0 commit comments

Comments
 (0)