Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/rollup-plugin";
export declare function getSentryConfig(outDir: string): SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Config that uses a Promise for filesToDeleteAfterUpload
// This tests that the plugin can handle async file deletion patterns
export function getSentryConfig(outDir) {
const fileDeletionPromise = new Promise((resolve) => {
setTimeout(() => {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
resolve([`${outDir}/basic.js.map`]);
}, 100);
});

return {
telemetry: false,
sourcemaps: {
filesToDeleteAfterUpload: fileDeletionPromise,
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
exports.sentryConfig = {
telemetry: false,
authToken: "fake-auth",
org: "fake-org",
project: "fake-project",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/rollup-plugin";
export declare const sentryConfig: SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const sentryConfig = {
telemetry: false,
release: { name: "I am release!", create: false },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/rollup-plugin";
export declare function getErrorHandlingConfig(port: string): SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function getErrorHandlingConfig(port) {
return {
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
url: `http://localhost:${port}`,
authToken: "fake-auth",
org: "fake-org",
project: "fake-project",
release: {
name: "1.0.0",
},
debug: true,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/rollup-plugin";
export declare const sentryConfig: SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const sentryConfig = {
telemetry: false,
release: {
name: 'i am a dangerous release value because I contain a "',
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/rollup-plugin";
export declare const sentryConfig: SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const sentryConfig = {
telemetry: false,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as esbuild from "esbuild";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import { getSentryConfig } from "../configs/after-upload-deletion-promise.config.js";

const outDir = "./out/after-upload-deletion-promise";

await esbuild.build({
entryPoints: ["./src/basic.js"],
bundle: true,
outfile: `${outDir}/basic.js`,
minify: false,
format: "iife",
sourcemap: true,
plugins: [sentryEsbuildPlugin(getSentryConfig(outDir))],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from "vitest";
import { test } from "./utils";
import { existsSync } from "node:fs";
import { join } from "node:path";

test(import.meta.url, ({ runBundler, outDir, runFileInNode }) => {
runBundler();

// Verify the JS file exists and works
const output = runFileInNode("basic.js");
expect(output).toBe("hello world\n");

// Verify the sourcemap was deleted (by the Promise)
const sourcemapPath = join(outDir, "basic.js.map");
expect(existsSync(sourcemapPath)).toBe(false);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const esbuild = require("esbuild");
const { sentryEsbuildPlugin } = require("@sentry/esbuild-plugin");
const { sentryConfig } = require("../configs/basic.config.cjs");

esbuild.build({
entryPoints: ["./src/basic.js"],
bundle: true,
outfile: "./out/basic-cjs/basic.js",
minify: false,
format: "iife",
plugins: [sentryEsbuildPlugin(sentryConfig)],
});
45 changes: 45 additions & 0 deletions packages/integration-tests-next/fixtures/esbuild/basic-cjs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from "vitest";
import { test } from "./utils";

test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
runBundler();
expect(readOutputFiles()).toMatchInlineSnapshot(`
{
"basic.js": "(() => {
// _sentry-injection-stub
!(function() {
try {
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
e.SENTRY_RELEASE = { id: "CURRENT_SHA" };
} catch (e2) {
}
})();

// sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000
!(function() {
try {
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
var n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "00000000-0000-0000-0000-000000000000", e._sentryDebugIdIdentifier = "sentry-dbid-00000000-0000-0000-0000-000000000000");
} catch (e2) {
}
})();

// src/basic.js
console.log("hello world");

// src/basic.js?sentryDebugIdProxy=true
var basic_default = void 0;
})();
",
"sentry-cli-mock.json": "["releases","new","CURRENT_SHA"],
["releases","set-commits","CURRENT_SHA","--auto","--ignore-missing"],
["releases","finalize","CURRENT_SHA"],
["sourcemaps","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path","--ignore","node_modules","--no-rewrite"],
",
}
`);

const output = runFileInNode("basic.js");
expect(output).toBe("hello world\n");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as esbuild from "esbuild";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import { sentryConfig } from "../configs/dont-mess-up-user-code.config.js";

await esbuild.build({
entryPoints: ["./src/index.js"],
bundle: true,
outfile: "./out/dont-mess-up-user-code/index.js",
minify: false,
format: "iife",
sourcemap: true,
plugins: [sentryEsbuildPlugin(sentryConfig)],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { expect } from "vitest";
import { test } from "./utils";

test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
runBundler();
expect(readOutputFiles()).toMatchInlineSnapshot(`
{
"index.js": "(() => {
// _sentry-injection-stub
!(function() {
try {
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
e.SENTRY_RELEASE = { id: "I am release!" };
} catch (e2) {
}
})();

// sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000
!(function() {
try {
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
var n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "00000000-0000-0000-0000-000000000000", e._sentryDebugIdIdentifier = "sentry-dbid-00000000-0000-0000-0000-000000000000");
} catch (e2) {
}
})();

// src/import.js
console.log("I am import!");

// src/index.js
console.log("I am index!");

// src/index.js?sentryDebugIdProxy=true
var index_default = void 0;
})();
//# sourceMappingURL=index.js.map
",
"index.js.map": "{"version":3,"sources":["../../_sentry-injection-stub","sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000","../../src/import.js","../../src/index.js","../../src/index.js"],"sourcesContent":["!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e.SENTRY_RELEASE={id:\\"I am release!\\"};}catch(e){}}();","!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};var n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]=\\"00000000-0000-0000-0000-000000000000\\",e._sentryDebugIdIdentifier=\\"sentry-dbid-00000000-0000-0000-0000-000000000000\\");}catch(e){}}();","// eslint-disable-next-line no-console\\nconsole.log(\\"I am import!\\");\\n\\nexport {};\\n","import \\"./import\\";\\n\\n// eslint-disable-next-line no-console\\nconsole.log(\\"I am index!\\");\\n","\\n import \\"_sentry-debug-id-injection-stub\\";\\n import * as OriginalModule from \\"./src/index.js\\";\\n export default OriginalModule.default;\\n export * from \\"./src/index.js\\";"],"mappings":";;AAAA,IAAC,WAAU;AAAC,QAAG;AAAC,UAAI,IAAE,eAAa,OAAO,SAAO,SAAO,eAAa,OAAO,SAAO,SAAO,eAAa,OAAO,aAAW,aAAW,eAAa,OAAO,OAAK,OAAK,CAAC;AAAE,QAAE,iBAAe,EAAC,IAAG,gBAAe;AAAA,IAAE,SAAOA,IAAE;AAAA,IAAC;AAAA,EAAC,GAAE;;;ACAxN,IAAC,WAAU;AAAC,QAAG;AAAC,UAAI,IAAE,eAAa,OAAO,SAAO,SAAO,eAAa,OAAO,SAAO,SAAO,eAAa,OAAO,aAAW,aAAW,eAAa,OAAO,OAAK,OAAK,CAAC;AAAE,UAAI,IAAG,IAAI,EAAE,QAAO;AAAM,YAAI,EAAE,kBAAgB,EAAE,mBAAiB,CAAC,GAAE,EAAE,gBAAgB,CAAC,IAAE,wCAAuC,EAAE,2BAAyB;AAAA,IAAoD,SAAOC,IAAE;AAAA,IAAC;AAAA,EAAC,GAAE;;;ACCnY,UAAQ,IAAI,cAAc;;;ACE1B,UAAQ,IAAI,aAAa;;;ACAX,MAAO,gBAAuB;","names":["e","e"]}",
}
`);

const output = runFileInNode("index.js");
expect(output).toContain("I am import!");
expect(output).toContain("I am index!");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as esbuild from "esbuild";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import { getErrorHandlingConfig } from "../configs/errorhandling.config.js";

const FAKE_SENTRY_PORT = process.env.FAKE_SENTRY_PORT || "9876";

await esbuild.build({
entryPoints: ["./src/basic.js"],
bundle: true,
outfile: "./out/errorhandling/basic.js",
minify: false,
format: "cjs",
sourcemap: true,
plugins: [sentryEsbuildPlugin(getErrorHandlingConfig(FAKE_SENTRY_PORT))],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from "vitest";
import { test } from "./utils";
import { withFakeSentryServer } from "../utils";

test(import.meta.url, async ({ runBundler }) => {
await withFakeSentryServer((port) => {
// Run bundler with fake server - should succeed despite server errors
runBundler({
FAKE_SENTRY_PORT: port,
SENTRY_HTTP_MAX_RETRIES: "1", // Only retry once to avoid timeout
});

// If we get here, the build succeeded (didn't throw)
expect(true).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as esbuild from "esbuild";
import * as path from "path";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";

await esbuild.build({
entryPoints: ["./src/inject-compat-index.ts"],
bundle: true,
outfile: "./out/esbuild-inject-compat/index.js",
inject: [path.resolve("./src/inject.ts")],
minify: false,
format: "iife",
plugins: [
sentryEsbuildPlugin({
telemetry: false,
}),
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect } from "vitest";
import { test } from "./utils";

test(import.meta.url, ({ readOutputFiles, runBundler, runFileInNode }) => {
runBundler();
expect(readOutputFiles()).toMatchInlineSnapshot(`
{
"index.js": "(() => {
// src/inject.ts
var process = {
env: {
FOO: "some-injected-value"
}
};
var global2 = globalThis;

// _sentry-injection-stub
!(function() {
try {
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
e.SENTRY_RELEASE = { id: "CURRENT_SHA" };
} catch (e2) {
}
})();

// sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000
!(function() {
try {
var e = "undefined" != typeof window ? window : "undefined" != typeof global2 ? global2 : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
var n = new e.Error().stack;
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "00000000-0000-0000-0000-000000000000", e._sentryDebugIdIdentifier = "sentry-dbid-00000000-0000-0000-0000-000000000000");
} catch (e2) {
}
})();

// src/inject-compat-index.ts
console.log(process.env["FOO"]);

// src/inject-compat-index.ts?sentryDebugIdProxy=true
var inject_compat_index_default = void 0;
})();
",
}
`);

const output = runFileInNode("index.js");
expect(output).toMatchInlineSnapshot(`
"some-injected-value
"
`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as esbuild from "esbuild";
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
import { sentryConfig } from "../configs/release-value-with-quotes.config.js";

await esbuild.build({
entryPoints: ["./src/release-value-with-quotes.js"],
bundle: true,
outfile: "./out/release-value-with-quotes/bundle.js",
minify: false,
format: "iife",
plugins: [sentryEsbuildPlugin(sentryConfig)],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect } from "vitest";
import { test } from "./utils";

test(import.meta.url, ({ runBundler, runFileInNode }) => {
runBundler();
const output = runFileInNode("bundle.js");
expect(output.trimEnd()).toBe('"i am a dangerous release value because I contain a \\""');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line no-console
console.log("I am import!");

export {};
4 changes: 4 additions & 0 deletions packages/integration-tests-next/fixtures/esbuild/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import "./import";

// eslint-disable-next-line no-console
console.log("I am index!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore just a test file
// eslint-disable-next-line no-console
console.log(process.env["FOO"]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const process = {
env: {
FOO: "some-injected-value",
},
};
// eslint-disable-next-line no-undef
export const global = globalThis;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Simply output the metadata to the console so it can be checked in a test
// eslint-disable-next-line no-console, @typescript-eslint/no-unsafe-member-access
console.log(JSON.stringify(global.SENTRY_RELEASE.id));
5 changes: 4 additions & 1 deletion packages/integration-tests-next/fixtures/esbuild/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ export function test(url: string, callback: TestCallback) {
// Clear the output directory before running the test
rmSync(outDir, { recursive: true, force: true });

// Detect CJS config files by test name suffix
const configExt = testName.endsWith("-cjs") ? ".config.cjs" : ".config.js";

vitestTest(`esbuild > ${testName}`, (ctx) =>
callback({
outDir,
runBundler: (env) =>
runBundler(
`node ${testName}.config.js`,
`node ${testName}${configExt}`,
{
cwd,
env: {
Expand Down
Loading
Loading