Skip to content

Commit cd9c272

Browse files
committed
tests
1 parent 76a0886 commit cd9c272

File tree

2 files changed

+185
-2
lines changed

2 files changed

+185
-2
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export function sentryUnpluginFactory({
123123
},
124124
});
125125

126-
if (!options.sourcemaps?.disable) {
126+
if (options.sourcemaps?.disable !== true) {
127127
plugins.push(debugIdInjectionPlugin(logger));
128128

129129
if (options.sourcemaps?.disable !== "disable-upload") {

packages/bundler-plugin-core/test/index.test.ts

Lines changed: 184 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getDebugIdSnippet } from "../src";
1+
import { Compiler } from "webpack";
2+
import { getDebugIdSnippet, sentryUnpluginFactory } from "../src";
23

34
describe("getDebugIdSnippet", () => {
45
it("returns the debugId injection snippet for a passed debugId", () => {
@@ -8,3 +9,185 @@ describe("getDebugIdSnippet", () => {
89
);
910
});
1011
});
12+
13+
describe("sentryUnpluginFactory sourcemaps.disable behavior", () => {
14+
const mockReleaseInjectionPlugin = jest.fn((_injectionCode: string) => ({
15+
name: "mock-release-injection-plugin",
16+
}));
17+
18+
const mockComponentNameAnnotatePlugin = jest.fn(() => ({
19+
name: "mock-component-name-annotate-plugin",
20+
}));
21+
22+
const mockModuleMetadataInjectionPlugin = jest.fn((_injectionCode: string) => ({
23+
name: "mock-module-metadata-injection-plugin",
24+
}));
25+
26+
const mockDebugIdInjectionPlugin = jest.fn(() => ({
27+
name: "mock-debug-id-injection-plugin",
28+
}));
29+
30+
const mockDebugIdUploadPlugin = jest.fn(() => ({
31+
name: "mock-debug-id-upload-plugin",
32+
}));
33+
34+
const mockBundleSizeOptimizationsPlugin = jest.fn(() => ({
35+
name: "mock-bundle-size-optimizations-plugin",
36+
}));
37+
38+
const createUnpluginInstance = (): ReturnType<typeof sentryUnpluginFactory> => {
39+
return sentryUnpluginFactory({
40+
releaseInjectionPlugin: mockReleaseInjectionPlugin,
41+
componentNameAnnotatePlugin: mockComponentNameAnnotatePlugin,
42+
moduleMetadataInjectionPlugin: mockModuleMetadataInjectionPlugin,
43+
debugIdInjectionPlugin: mockDebugIdInjectionPlugin,
44+
debugIdUploadPlugin: mockDebugIdUploadPlugin,
45+
bundleSizeOptimizationsPlugin: mockBundleSizeOptimizationsPlugin,
46+
});
47+
};
48+
49+
beforeEach(() => {
50+
jest.clearAllMocks();
51+
});
52+
53+
describe("when sourcemaps.disable is true", () => {
54+
it("should not include debug ID injection or upload plugins", () => {
55+
const unpluginInstance = createUnpluginInstance();
56+
57+
const plugins = unpluginInstance.raw(
58+
{
59+
authToken: "test-token",
60+
org: "test-org",
61+
project: "test-project",
62+
sourcemaps: {
63+
disable: true,
64+
},
65+
},
66+
{ framework: "webpack", webpack: { compiler: {} as Compiler } }
67+
);
68+
69+
const pluginNames = plugins.map((plugin) => plugin.name);
70+
71+
// Should not include debug ID related plugins
72+
expect(pluginNames).not.toContain("mock-debug-id-injection-plugin");
73+
expect(pluginNames).not.toContain("mock-debug-id-upload-plugin");
74+
75+
// Should still include other core plugins
76+
expect(pluginNames).toContain("sentry-telemetry-plugin");
77+
expect(pluginNames).toContain("sentry-release-management-plugin");
78+
expect(pluginNames).toContain("sentry-file-deletion-plugin");
79+
});
80+
});
81+
82+
describe('when sourcemaps.disable is "disable-upload"', () => {
83+
it("should include debug ID injection plugin but not upload plugin", () => {
84+
const unpluginInstance = createUnpluginInstance();
85+
86+
const plugins = unpluginInstance.raw(
87+
{
88+
authToken: "test-token",
89+
org: "test-org",
90+
project: "test-project",
91+
sourcemaps: {
92+
disable: "disable-upload",
93+
},
94+
},
95+
{ framework: "webpack", webpack: { compiler: {} as Compiler } }
96+
);
97+
98+
const pluginNames = plugins.map((plugin) => plugin.name);
99+
100+
// Should include debug ID injection but not upload
101+
expect(pluginNames).toContain("mock-debug-id-injection-plugin");
102+
expect(pluginNames).not.toContain("mock-debug-id-upload-plugin");
103+
104+
// Should still include other core plugins
105+
expect(pluginNames).toContain("sentry-telemetry-plugin");
106+
expect(pluginNames).toContain("sentry-release-management-plugin");
107+
expect(pluginNames).toContain("sentry-file-deletion-plugin");
108+
});
109+
});
110+
111+
describe("when sourcemaps.disable is false", () => {
112+
it("should include both debug ID injection and upload plugins", () => {
113+
const unpluginInstance = createUnpluginInstance();
114+
115+
const plugins = unpluginInstance.raw(
116+
{
117+
authToken: "test-token",
118+
org: "test-org",
119+
project: "test-project",
120+
sourcemaps: {
121+
disable: false,
122+
},
123+
},
124+
{ framework: "webpack", webpack: { compiler: {} as Compiler } }
125+
);
126+
127+
const pluginNames = plugins.map((plugin) => plugin.name);
128+
129+
// Should include both debug ID related plugins
130+
expect(pluginNames).toContain("mock-debug-id-injection-plugin");
131+
expect(pluginNames).toContain("mock-debug-id-upload-plugin");
132+
133+
// Should include other core plugins
134+
expect(pluginNames).toContain("sentry-telemetry-plugin");
135+
expect(pluginNames).toContain("sentry-release-management-plugin");
136+
expect(pluginNames).toContain("sentry-file-deletion-plugin");
137+
});
138+
});
139+
140+
describe("when sourcemaps.disable is undefined (default)", () => {
141+
it("should include both debug ID injection and upload plugins", () => {
142+
const unpluginInstance = createUnpluginInstance();
143+
144+
const plugins = unpluginInstance.raw(
145+
{
146+
authToken: "test-token",
147+
org: "test-org",
148+
project: "test-project",
149+
// sourcemaps.disable not specified (undefined)
150+
},
151+
{ framework: "webpack", webpack: { compiler: {} as Compiler } }
152+
);
153+
154+
const pluginNames = plugins.map((plugin) => plugin.name);
155+
156+
// Should include both debug ID related plugins by default
157+
expect(pluginNames).toContain("mock-debug-id-injection-plugin");
158+
expect(pluginNames).toContain("mock-debug-id-upload-plugin");
159+
160+
// Should include other core plugins
161+
expect(pluginNames).toContain("sentry-telemetry-plugin");
162+
expect(pluginNames).toContain("sentry-release-management-plugin");
163+
expect(pluginNames).toContain("sentry-file-deletion-plugin");
164+
});
165+
});
166+
167+
describe("when entire sourcemaps option is undefined", () => {
168+
it("should include both debug ID injection and upload plugins", () => {
169+
const unpluginInstance = createUnpluginInstance();
170+
171+
const plugins = unpluginInstance.raw(
172+
{
173+
authToken: "test-token",
174+
org: "test-org",
175+
project: "test-project",
176+
// sourcemaps option not specified at all
177+
},
178+
{ framework: "webpack", webpack: { compiler: {} as Compiler } }
179+
);
180+
181+
const pluginNames = plugins.map((plugin) => plugin.name);
182+
183+
// Should include both debug ID related plugins by default
184+
expect(pluginNames).toContain("mock-debug-id-injection-plugin");
185+
expect(pluginNames).toContain("mock-debug-id-upload-plugin");
186+
187+
// Should include other core plugins
188+
expect(pluginNames).toContain("sentry-telemetry-plugin");
189+
expect(pluginNames).toContain("sentry-release-management-plugin");
190+
expect(pluginNames).toContain("sentry-file-deletion-plugin");
191+
});
192+
});
193+
});

0 commit comments

Comments
 (0)