-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy patherror-no-handler.test.ts
More file actions
65 lines (54 loc) · 1.84 KB
/
error-no-handler.test.ts
File metadata and controls
65 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable jest/no-standalone-expect */
/* eslint-disable jest/expect-expect */
import path from "path";
import { spawn } from "child_process";
jest.setTimeout(10_000);
describe("Error throwing by default (no errorHandler)", () => {
const FAKE_SENTRY_PORT = "9876";
const sentryServer = spawn("node", [path.join(__dirname, "fakeSentry.js")], {
cwd: __dirname,
stdio: "ignore", // <-- set to "inherit" to get server logs. Deactivated to avoid test logs.
env: { ...process.env, FAKE_SENTRY_PORT },
shell: true,
});
beforeAll(async () => {
await new Promise<void>((resolve) =>
sentryServer.on("spawn", () => {
resolve();
})
);
});
afterAll(() => {
sentryServer.kill();
});
const bundlersToTest = ["vite", "rollup", "webpack5", "esbuild"];
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (parseInt(process.version.split(".")[0]!.slice(1)) < 18) {
bundlersToTest.push("webpack4");
}
test.each(bundlersToTest)(
"doesn't throw when Sentry server responds with error code for %s",
async (bundler) => {
const buildProcess = spawn("yarn", ["ts-node", path.join(__dirname, `build-${bundler}.ts`)], {
env: {
...process.env,
FAKE_SENTRY_PORT,
// only retry once to avoid the test from timing out due to retries
SENTRY_HTTP_MAX_RETRIES: "1",
},
stdio: "ignore", // <-- set to "inherit" to get build output. Deactivated to avoid spamming test logs.
shell: true,
});
const exitCode = await new Promise<number>((resolve, reject) => {
buildProcess.on("exit", (code) => {
resolve(code ?? 99);
});
buildProcess.on("error", (err) => {
reject(err);
});
});
expect(exitCode).toBe(0);
buildProcess.kill();
}
);
});