Skip to content

Commit 8a69483

Browse files
committed
Add errorhandling tests
1 parent 5aea4f8 commit 8a69483

18 files changed

Lines changed: 331 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function getErrorHandlingConfig(port) {
2+
return {
3+
url: `http://localhost:${port}`,
4+
authToken: "fake-auth",
5+
org: "fake-org",
6+
project: "fake-project",
7+
release: {
8+
name: "1.0.0",
9+
},
10+
debug: true,
11+
};
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as esbuild from "esbuild";
2+
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
3+
import { getErrorHandlingConfig } from "../configs/errorhandling.config.js";
4+
5+
const FAKE_SENTRY_PORT = process.env.FAKE_SENTRY_PORT || "9876";
6+
7+
await esbuild.build({
8+
entryPoints: ["./src/basic.js"],
9+
bundle: true,
10+
outfile: "./out/errorhandling/basic.js",
11+
minify: false,
12+
format: "cjs",
13+
sourcemap: true,
14+
plugins: [sentryEsbuildPlugin(getErrorHandlingConfig(FAKE_SENTRY_PORT))],
15+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
import { withFakeSentryServer } from "../utils";
4+
5+
test(import.meta.url, async ({ runBundler }) => {
6+
await withFakeSentryServer((port) => {
7+
// Run bundler with fake server - should succeed despite server errors
8+
runBundler({
9+
FAKE_SENTRY_PORT: port,
10+
SENTRY_HTTP_MAX_RETRIES: "1", // Only retry once to avoid timeout
11+
});
12+
13+
// If we get here, the build succeeded (didn't throw)
14+
expect(true).toBe(true);
15+
});
16+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
2+
import { defineConfig } from "rolldown";
3+
import { getErrorHandlingConfig } from "../configs/errorhandling.config.js";
4+
5+
const FAKE_SENTRY_PORT = process.env.FAKE_SENTRY_PORT || "9876";
6+
7+
export default defineConfig({
8+
input: "src/basic.js",
9+
output: {
10+
file: "out/errorhandling/basic.js",
11+
format: "cjs",
12+
sourcemap: true,
13+
},
14+
plugins: [sentryRollupPlugin(getErrorHandlingConfig(FAKE_SENTRY_PORT))],
15+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
import { withFakeSentryServer } from "../utils";
4+
5+
test(import.meta.url, async ({ runBundler }) => {
6+
await withFakeSentryServer((port) => {
7+
// Run bundler with fake server - should succeed despite server errors
8+
runBundler({
9+
FAKE_SENTRY_PORT: port,
10+
SENTRY_HTTP_MAX_RETRIES: "1", // Only retry once to avoid timeout
11+
});
12+
13+
// If we get here, the build succeeded (didn't throw)
14+
expect(true).toBe(true);
15+
});
16+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
2+
import { defineConfig } from "rollup";
3+
import { getErrorHandlingConfig } from "../configs/errorhandling.config.js";
4+
5+
const FAKE_SENTRY_PORT = process.env.FAKE_SENTRY_PORT || "9876";
6+
7+
export default defineConfig({
8+
input: "src/basic.js",
9+
output: {
10+
file: "out/errorhandling/basic.js",
11+
format: "cjs",
12+
sourcemap: true,
13+
},
14+
plugins: [sentryRollupPlugin(getErrorHandlingConfig(FAKE_SENTRY_PORT))],
15+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
import { withFakeSentryServer } from "../utils";
4+
5+
test(import.meta.url, async ({ runBundler }) => {
6+
await withFakeSentryServer((port) => {
7+
// Run bundler with fake server - should succeed despite server errors
8+
runBundler({
9+
FAKE_SENTRY_PORT: port,
10+
SENTRY_HTTP_MAX_RETRIES: "1", // Only retry once to avoid timeout
11+
});
12+
13+
// If we get here, the build succeeded (didn't throw)
14+
expect(true).toBe(true);
15+
});
16+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
2+
import { defineConfig } from "rollup";
3+
import { getErrorHandlingConfig } from "../configs/errorhandling.config.js";
4+
5+
const FAKE_SENTRY_PORT = process.env.FAKE_SENTRY_PORT || "9876";
6+
7+
export default defineConfig({
8+
input: "src/basic.js",
9+
output: {
10+
file: "out/errorhandling/basic.js",
11+
format: "cjs",
12+
sourcemap: true,
13+
},
14+
plugins: [sentryRollupPlugin(getErrorHandlingConfig(FAKE_SENTRY_PORT))],
15+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
import { withFakeSentryServer } from "../utils";
4+
5+
test(import.meta.url, async ({ runBundler }) => {
6+
await withFakeSentryServer((port) => {
7+
// Run bundler with fake server - should succeed despite server errors
8+
runBundler({
9+
FAKE_SENTRY_PORT: port,
10+
SENTRY_HTTP_MAX_RETRIES: "1", // Only retry once to avoid timeout
11+
});
12+
13+
// If we get here, the build succeeded (didn't throw)
14+
expect(true).toBe(true);
15+
});
16+
});

packages/integration-tests-next/fixtures/utils.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,50 @@ process.on("exit", () => {
9797
rmSync(dir, { recursive: true, force: true });
9898
}
9999
});
100+
101+
/**
102+
* Runs a callback with a fake Sentry server running on an auto-allocated port.
103+
* The server returns 503 errors for all requests.
104+
* Automatically starts and stops the server.
105+
* The allocated port is passed to the callback.
106+
*/
107+
export async function withFakeSentryServer(
108+
callback: (port: string) => void | Promise<void>
109+
): Promise<void> {
110+
const { createServer } = await import("node:http");
111+
112+
const server = createServer((req, res) => {
113+
if (DEBUG) {
114+
// eslint-disable-next-line no-console
115+
console.log("[FAKE SENTRY] incoming request", req.url);
116+
}
117+
res.statusCode = 503;
118+
res.end("Error: Sentry unreachable");
119+
});
120+
121+
// Listen on port 0 to get an auto-allocated port
122+
await new Promise<void>((resolve) => {
123+
server.listen(0, () => {
124+
resolve();
125+
});
126+
});
127+
128+
const address = server.address();
129+
if (!address || typeof address === "string") {
130+
throw new Error("Failed to get server port");
131+
}
132+
const port = address.port.toString();
133+
134+
if (DEBUG) {
135+
// eslint-disable-next-line no-console
136+
console.log(`[FAKE SENTRY] running on http://localhost:${port}/`);
137+
}
138+
139+
try {
140+
await callback(port);
141+
} finally {
142+
await new Promise<void>((resolve) => {
143+
server.close(() => resolve());
144+
});
145+
}
146+
}

0 commit comments

Comments
 (0)