|
| 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 | + |
0 commit comments