Skip to content

Commit efe8d20

Browse files
committed
Add CJS tests
1 parent a456474 commit efe8d20

24 files changed

Lines changed: 375 additions & 8 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const esbuild = require("esbuild");
2+
const { sentryEsbuildPlugin } = require("@sentry/esbuild-plugin");
3+
const { sentryConfig } = require("../configs/basic.config.js");
4+
5+
esbuild.build({
6+
entryPoints: ["./src/basic.js"],
7+
bundle: true,
8+
outfile: "./out/basic-cjs/basic.js",
9+
minify: false,
10+
format: "iife",
11+
plugins: [sentryEsbuildPlugin(sentryConfig)],
12+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
4+
test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
5+
runBundler();
6+
expect(readOutputFiles()).toMatchInlineSnapshot(`
7+
{
8+
"basic.js": "(() => {
9+
// _sentry-injection-stub
10+
!(function() {
11+
try {
12+
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
13+
e.SENTRY_RELEASE = { id: "CURRENT_SHA" };
14+
} catch (e2) {
15+
}
16+
})();
17+
18+
// sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000
19+
!(function() {
20+
try {
21+
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
22+
var n = new e.Error().stack;
23+
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "00000000-0000-0000-0000-000000000000", e._sentryDebugIdIdentifier = "sentry-dbid-00000000-0000-0000-0000-000000000000");
24+
} catch (e2) {
25+
}
26+
})();
27+
28+
// src/basic.js
29+
console.log("hello world");
30+
31+
// src/basic.js?sentryDebugIdProxy=true
32+
var basic_default = void 0;
33+
})();
34+
",
35+
"sentry-cli-mock.json": "["releases","new","CURRENT_SHA"],
36+
["releases","set-commits","CURRENT_SHA","--auto","--ignore-missing"],
37+
["releases","finalize","CURRENT_SHA"],
38+
["sourcemaps","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path","--ignore","node_modules","--no-rewrite"],
39+
",
40+
}
41+
`);
42+
43+
const output = runFileInNode("basic.js");
44+
expect(output).toBe("hello world\n");
45+
});

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ export function test(url: string, callback: TestCallback) {
3434
// Clear the output directory before running the test
3535
rmSync(outDir, { recursive: true, force: true });
3636

37+
// Detect CJS config files by test name suffix
38+
const configExt = testName.endsWith("-cjs") ? ".config.cjs" : ".config.js";
39+
3740
vitestTest(`esbuild > ${testName}`, (ctx) =>
3841
callback({
3942
outDir,
4043
runBundler: (env) =>
4144
runBundler(
42-
`node ${testName}.config.js`,
45+
`node ${testName}${configExt}`,
4346
{
4447
cwd,
4548
env: {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { sentryRollupPlugin } = require("@sentry/rollup-plugin");
2+
const { defineConfig } = require("rolldown");
3+
const { sentryConfig } = require("../configs/basic.config.js");
4+
5+
module.exports = defineConfig({
6+
input: "src/basic.js",
7+
output: {
8+
file: "out/basic-cjs/basic.js",
9+
},
10+
plugins: [sentryRollupPlugin(sentryConfig)],
11+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
4+
test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
5+
runBundler();
6+
expect(readOutputFiles()).toMatchInlineSnapshot(`
7+
{
8+
"basic.js": "//#region src/basic.js
9+
(function() {
10+
try {
11+
var e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {};
12+
e.SENTRY_RELEASE = { id: "CURRENT_SHA" };
13+
var n = new e.Error().stack;
14+
n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "00000000-0000-0000-0000-000000000000", e._sentryDebugIdIdentifier = "sentry-dbid-00000000-0000-0000-0000-000000000000");
15+
} catch (e) {}
16+
})();
17+
console.log("hello world");
18+
//#endregion
19+
",
20+
"sentry-cli-mock.json": "["releases","new","CURRENT_SHA"],
21+
["releases","set-commits","CURRENT_SHA","--auto","--ignore-missing"],
22+
["releases","finalize","CURRENT_SHA"],
23+
["sourcemaps","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path","--ignore","node_modules","--no-rewrite"],
24+
",
25+
}
26+
`);
27+
28+
const output = runFileInNode("basic.js");
29+
expect(output).toBe("hello world\n");
30+
});

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export function test(url: string, callback: TestCallback) {
2626
// Clear the output directory before running the test
2727
rmSync(outDir, { recursive: true, force: true });
2828

29+
// Detect CJS config files by test name suffix
30+
const configExt = testName.endsWith("-cjs") ? ".config.cjs" : ".config.ts";
31+
2932
// Rolldown requires Node 20+
3033
if (NODE_MAJOR_VERSION < 20) {
3134
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -36,7 +39,7 @@ export function test(url: string, callback: TestCallback) {
3639
outDir,
3740
runBundler: (env) =>
3841
runBundler(
39-
`rolldown --config ${testName}.config.ts`,
42+
`rolldown --config ${testName}${configExt}`,
4043
{
4144
cwd,
4245
env: {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { sentryRollupPlugin } = require("@sentry/rollup-plugin");
2+
const { defineConfig } = require("rollup");
3+
const { sentryConfig } = require("../configs/basic.config.js");
4+
5+
module.exports = defineConfig({
6+
input: "src/basic.js",
7+
output: {
8+
file: "out/basic-cjs/basic.js",
9+
},
10+
plugins: [sentryRollupPlugin(sentryConfig)],
11+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
4+
test(import.meta.url, ({ runBundler, readOutputFiles, runFileInNode }) => {
5+
runBundler();
6+
expect(readOutputFiles()).toMatchInlineSnapshot(`
7+
{
8+
"basic.js": "// eslint-disable-next-line no-console
9+
!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"};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){}}();console.log("hello world");
10+
",
11+
"sentry-cli-mock.json": "["releases","new","CURRENT_SHA"],
12+
["releases","set-commits","CURRENT_SHA","--auto","--ignore-missing"],
13+
["releases","finalize","CURRENT_SHA"],
14+
["sourcemaps","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path","--ignore","node_modules","--no-rewrite"],
15+
",
16+
}
17+
`);
18+
19+
const output = runFileInNode("basic.js");
20+
expect(output).toBe("hello world\n");
21+
});

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ export function test(url: string, callback: TestCallback) {
2525
// Clear the output directory before running the test
2626
rmSync(outDir, { recursive: true, force: true });
2727

28+
// Detect CJS config files by test name suffix
29+
const configExt = testName.endsWith("-cjs") ? ".config.cjs" : ".config.js";
30+
2831
vitestTest(`rollup v3 > ${testName}`, (ctx) =>
2932
callback({
3033
outDir,
3134
runBundler: (env) =>
3235
runBundler(
33-
`rollup --config ${testName}.config.js`,
36+
`rollup --config ${testName}${configExt}`,
3437
{
3538
cwd,
3639
env: {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { sentryRollupPlugin } = require("@sentry/rollup-plugin");
2+
const { defineConfig } = require("rollup");
3+
const { sentryConfig } = require("../configs/basic.config.js");
4+
5+
module.exports = defineConfig({
6+
input: "src/basic.js",
7+
output: {
8+
file: "out/basic-cjs/basic.js",
9+
},
10+
plugins: [sentryRollupPlugin(sentryConfig)],
11+
});

0 commit comments

Comments
 (0)