Skip to content

Commit e39a8b0

Browse files
committed
only disable CLI-using plugins, add tests
1 parent 629f09f commit e39a8b0

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function sentryUnpluginFactory({
111111

112112
const options = normalizeUserOptions(userOptions);
113113

114-
if (isDevMode || options.disable) {
114+
if (options.disable) {
115115
return [
116116
{
117117
name: "sentry-noop-plugin",
@@ -324,6 +324,8 @@ export function sentryUnpluginFactory({
324324
logger.debug(
325325
"No release name provided. Will not create release. Please set the `release.name` option to identify your release."
326326
);
327+
} else if (isDevMode) {
328+
logger.debug("Running in development mode. Will not create release.");
327329
} else if (!options.authToken) {
328330
logger.warn(
329331
"No auth token provided. Will not create release. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/"
@@ -372,6 +374,8 @@ export function sentryUnpluginFactory({
372374
logger.debug(
373375
"Source map upload was disabled. Will not upload sourcemaps using debug ID process."
374376
);
377+
} else if (isDevMode) {
378+
logger.debug("Running in development mode. Will not upload sourcemaps.");
375379
} else if (!options.authToken) {
376380
logger.warn(
377381
"No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/"

packages/rollup-plugin/test/public-api.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test("Rollup plugin should exist", () => {
77
});
88

99
describe("sentryRollupPlugin", () => {
10+
beforeEach(() => {
11+
jest.clearAllMocks();
12+
});
13+
1014
it("returns an array of rollup plugins", () => {
1115
const plugins = sentryRollupPlugin({
1216
authToken: "test-token",
@@ -27,4 +31,41 @@ describe("sentryRollupPlugin", () => {
2731
"sentry-file-deletion-plugin",
2832
]);
2933
});
34+
35+
it("doesn't include release management and debug id upload plugins if NODE_ENV is 'development'", () => {
36+
const originalNodeEnv = process.env["NODE_ENV"];
37+
process.env["NODE_ENV"] = "development";
38+
39+
const consoleSpy = jest.spyOn(console, "debug").mockImplementation(() => {
40+
/* avoid test output pollution */
41+
});
42+
43+
const plugins = sentryRollupPlugin({
44+
authToken: "test-token",
45+
org: "test-org",
46+
project: "test-project",
47+
debug: true,
48+
}) as Plugin[];
49+
50+
expect(Array.isArray(plugins)).toBe(true);
51+
52+
const pluginNames = plugins.map((plugin) => plugin.name);
53+
54+
expect(pluginNames).toEqual([
55+
"sentry-telemetry-plugin",
56+
"sentry-rollup-release-injection-plugin",
57+
"sentry-rollup-debug-id-injection-plugin",
58+
"sentry-file-deletion-plugin",
59+
]);
60+
61+
expect(consoleSpy).toHaveBeenCalledWith(
62+
expect.stringContaining("Running in development mode. Will not create release.")
63+
);
64+
65+
expect(consoleSpy).toHaveBeenCalledWith(
66+
expect.stringContaining("Running in development mode. Will not upload sourcemaps.")
67+
);
68+
69+
process.env["NODE_ENV"] = originalNodeEnv;
70+
});
3071
});

packages/vite-plugin/test/public-api.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ test("Vite plugin should exist", () => {
77
});
88

99
describe("sentryVitePlugin", () => {
10+
beforeEach(() => {
11+
jest.clearAllMocks();
12+
});
13+
1014
it("returns an array of Vite plugins", () => {
1115
const plugins = sentryVitePlugin({
1216
authToken: "test-token",
@@ -27,4 +31,41 @@ describe("sentryVitePlugin", () => {
2731
"sentry-file-deletion-plugin",
2832
]);
2933
});
34+
35+
it("doesn't include release management and debug id upload plugins if NODE_ENV is 'development'", () => {
36+
const originalNodeEnv = process.env["NODE_ENV"];
37+
process.env["NODE_ENV"] = "development";
38+
39+
const consoleSpy = jest.spyOn(console, "debug").mockImplementation(() => {
40+
/* avoid test output pollution */
41+
});
42+
43+
const plugins = sentryVitePlugin({
44+
authToken: "test-token",
45+
org: "test-org",
46+
project: "test-project",
47+
debug: true,
48+
}) as VitePlugin[];
49+
50+
expect(Array.isArray(plugins)).toBe(true);
51+
52+
const pluginNames = plugins.map((plugin) => plugin.name);
53+
54+
expect(pluginNames).toEqual([
55+
"sentry-telemetry-plugin",
56+
"sentry-vite-release-injection-plugin",
57+
"sentry-vite-debug-id-injection-plugin",
58+
"sentry-file-deletion-plugin",
59+
]);
60+
61+
expect(consoleSpy).toHaveBeenCalledWith(
62+
expect.stringContaining("Running in development mode. Will not create release.")
63+
);
64+
65+
expect(consoleSpy).toHaveBeenCalledWith(
66+
expect.stringContaining("Running in development mode. Will not upload sourcemaps.")
67+
);
68+
69+
process.env["NODE_ENV"] = originalNodeEnv;
70+
});
3071
});

0 commit comments

Comments
 (0)