Skip to content

Commit b1d7e9b

Browse files
committed
Add esbuild-inject-compat test
1 parent a658008 commit b1d7e9b

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import * as esbuild from "esbuild";
2+
import * as path from "path";
3+
import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin";
4+
5+
await esbuild.build({
6+
entryPoints: ["./src/inject-compat-index.ts"],
7+
bundle: true,
8+
outfile: "./out/esbuild-inject-compat/index.js",
9+
inject: [path.resolve("./src/inject.ts")],
10+
minify: false,
11+
format: "iife",
12+
plugins: [
13+
sentryEsbuildPlugin({
14+
telemetry: false,
15+
}),
16+
],
17+
});
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
4+
test(import.meta.url, ({ readOutputFiles, runBundler, runFileInNode }) => {
5+
runBundler();
6+
expect(readOutputFiles()).toMatchInlineSnapshot(`
7+
{
8+
"index.js": "(() => {
9+
// src/inject.ts
10+
var process = {
11+
env: {
12+
FOO: "some-injected-value"
13+
}
14+
};
15+
var global2 = globalThis;
16+
17+
// _sentry-injection-stub
18+
!(function() {
19+
try {
20+
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
21+
e.SENTRY_RELEASE = { id: "CURRENT_SHA" };
22+
} catch (e2) {
23+
}
24+
})();
25+
26+
// sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000
27+
!(function() {
28+
try {
29+
var e = "undefined" != typeof window ? window : "undefined" != typeof global2 ? global2 : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
30+
var n = new e.Error().stack;
31+
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "00000000-0000-0000-0000-000000000000", e._sentryDebugIdIdentifier = "sentry-dbid-00000000-0000-0000-0000-000000000000");
32+
} catch (e2) {
33+
}
34+
})();
35+
36+
// src/inject-compat-index.ts
37+
console.log(process.env["FOO"]);
38+
39+
// src/inject-compat-index.ts?sentryDebugIdProxy=true
40+
var inject_compat_index_default = void 0;
41+
})();
42+
",
43+
}
44+
`);
45+
46+
const output = runFileInNode("index.js");
47+
expect(output).toMatchInlineSnapshot(`
48+
"some-injected-value
49+
"
50+
`);
51+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2+
// @ts-ignore just a test file
3+
// eslint-disable-next-line no-console
4+
console.log(process.env["FOO"]);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const process = {
2+
env: {
3+
FOO: "some-injected-value",
4+
},
5+
};
6+
// eslint-disable-next-line no-undef
7+
export const global = globalThis;

0 commit comments

Comments
 (0)