Skip to content

Commit c182d26

Browse files
committed
more tests
1 parent e93d586 commit c182d26

File tree

8 files changed

+93
-8
lines changed

8 files changed

+93
-8
lines changed

packages/bundler-plugin-core/src/sentry/transports.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import type {
1212
TransportRequest,
1313
TransportRequestExecutor,
1414
} from "@sentry/types";
15+
import { join } from "node:path";
16+
import { appendFileSync } from "node:fs";
1517

1618
// Estimated maximum size for reasonable standalone event
1719
const GZIP_THRESHOLD = 1024 * 32;
@@ -119,6 +121,12 @@ export function makeOptionallyEnabledNodeTransport(
119121
}
120122

121123
if (await shouldSendTelemetry) {
124+
if (process.env["SENTRY_TEST_OUT_DIR"]) {
125+
const path = join(process.env["SENTRY_TEST_OUT_DIR"], "sentry-telemetry.json");
126+
appendFileSync(path, JSON.stringify(request) + ",\n");
127+
return { statusCode: 200 };
128+
}
129+
122130
return nodeTransport.send(request);
123131
}
124132

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
2+
import { defineConfig } from "rolldown";
3+
4+
export default defineConfig({
5+
input: "src/basic.js",
6+
output: {
7+
file: "out/after-upload-deletion/basic.js",
8+
sourcemap: true,
9+
},
10+
plugins: [
11+
sentryRollupPlugin({
12+
telemetry: false,
13+
sourcemaps: {
14+
filesToDeleteAfterUpload: ["out/after-upload-deletion/basic.js.map"],
15+
},
16+
}),
17+
],
18+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
4+
test(import.meta.url, ({ runRolldown, readOutputFiles, runFileInNode }) => {
5+
runRolldown();
6+
expect(readOutputFiles()).toMatchInlineSnapshot(`
7+
{
8+
"basic.js": "//#region src/basic.js
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]="b699d9c1-b033-4536-aa25-233c92609b54",e._sentryDebugIdIdentifier="sentry-dbid-b699d9c1-b033-4536-aa25-233c92609b54");}catch(e){}}();console.log("hello world");
10+
11+
//#endregion
12+
//# sourceMappingURL=basic.js.map",
13+
}
14+
`);
15+
16+
const output = runFileInNode("basic.js");
17+
expect(output).toBe("hello world\n");
18+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { sentryRollupPlugin } from "@sentry/rollup-plugin";
2+
import { defineConfig } from "rolldown";
3+
4+
export default defineConfig({
5+
input: "src/basic.js",
6+
output: {
7+
file: "out/telemetry/basic.js",
8+
},
9+
plugins: [sentryRollupPlugin()],
10+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect } from "vitest";
2+
import { test } from "./utils";
3+
4+
test(import.meta.url, ({ runRolldown, readOutputFiles, runFileInNode }) => {
5+
runRolldown();
6+
expect(readOutputFiles()).toMatchInlineSnapshot(`
7+
{
8+
"basic.js": "//#region src/basic.js
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]="b699d9c1-b033-4536-aa25-233c92609b54",e._sentryDebugIdIdentifier="sentry-dbid-b699d9c1-b033-4536-aa25-233c92609b54");}catch(e){}}();console.log("hello world");
10+
11+
//#endregion",
12+
"sentry-telemetry.json": "[{"sent_at":"TIMESTAMP","sdk":{"name":"sentry.javascript.node","version":"8.30.0"}},[[{"type":"session"},{"sid":"UUID","init":false,"started":"TIMESTAMP","timestamp":"TIMESTAMP","status":"exited","errors":0,"duration":DURATION,"attrs":{"release":"PLUGIN_VERSION","environment":"production"}}]]],
13+
",
14+
}
15+
`);
16+
17+
const output = runFileInNode("basic.js");
18+
expect(output).toBe("hello world\n");
19+
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type TestCallback = (props: {
1414
readOutputFiles: () => Record<string, string>;
1515
runFileInNode: (file: string) => string;
1616
createTempDir: () => string;
17-
}) => void;
17+
}) => void | Promise<void>;
1818

1919
export function test(url: string, callback: TestCallback) {
2020
const filePath = fileURLToPath(url);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type SourceMap = {
1515
export function runBundler(command: string, opt: ExecSyncOptions, outDir?: string): void {
1616
if (outDir) {
1717
// We've patched the sentry-cli helper to write the args to a file instead of actually executing the command
18-
opt.env = { ...opt.env, SENTRY_CLI_FILE_APPEND: join(outDir, "sentry-cli-mock.json") };
18+
opt.env = { ...opt.env, SENTRY_TEST_OUT_DIR: outDir };
1919
}
2020

2121
execSync(command, { stdio: DEBUG ? "inherit" : "ignore", ...opt });
@@ -32,8 +32,9 @@ export function readAllFiles(directory: string): Record<string, string> {
3232
if (stat.isFile()) {
3333
let contents = readFileSync(fullPath, "utf-8");
3434
// We replace the current SHA with a placeholder to make snapshots deterministic
35-
contents = contents.replaceAll(CURRENT_SHA, "CURRENT_SHA");
36-
contents = contents.replaceAll(/"nodeVersion":\d+/g, `"nodeVersion":"NODE_VERSION"`);
35+
contents = contents
36+
.replaceAll(CURRENT_SHA, "CURRENT_SHA")
37+
.replaceAll(/"nodeVersion":\d+/g, `"nodeVersion":"NODE_VERSION"`);
3738

3839
// Normalize Windows stuff in .map paths
3940
if (entry.endsWith(".map")) {
@@ -47,6 +48,16 @@ export function readAllFiles(directory: string): Record<string, string> {
4748
/"[^"]+sentry-bundler-plugin-upload.+?",/g,
4849
'"sentry-bundler-plugin-upload-path",'
4950
);
51+
} else if (entry === "sentry-telemetry.json") {
52+
// Remove the temporary directory path too
53+
contents = contents
54+
.replace(
55+
/\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/g,
56+
"TIMESTAMP"
57+
)
58+
.replace(/[a-f0-9]{32}/g, "UUID")
59+
.replace(/"duration":[\d.]+/g, '"duration":DURATION')
60+
.replace(/"release":"[\d.]+"/g, '"release":"PLUGIN_VERSION"');
5061
} else {
5162
// Normalize Windows line endings for cross-platform snapshots
5263
contents = contents.replace(/\r\n/g, "\n");

patches/@sentry+cli+2.58.5.patch

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
diff --git a/node_modules/@sentry/cli/js/helper.js b/node_modules/@sentry/cli/js/helper.js
2-
index 56f95c9..c70f216 100644
2+
index 56f95c9..b397122 100644
33
--- a/node_modules/@sentry/cli/js/helper.js
44
+++ b/node_modules/@sentry/cli/js/helper.js
5-
@@ -298,6 +298,12 @@ function execute(args_1, live_1, silent_1, configFile_1) {
5+
@@ -298,6 +298,13 @@ function execute(args_1, live_1, silent_1, configFile_1) {
66
if (config.customHeader) {
77
env.CUSTOM_HEADER = config.customHeader;
88
}
99
+
10-
+ if (process.env['SENTRY_CLI_FILE_APPEND']) {
11-
+ fs.appendFileSync(process.env['SENTRY_CLI_FILE_APPEND'], JSON.stringify(args) + ',\n');
10+
+ if (process.env['SENTRY_TEST_OUT_DIR']) {
11+
+ const out = path.join(process.env['SENTRY_TEST_OUT_DIR'], 'sentry-cli-mock.json');
12+
+ fs.appendFileSync(out, JSON.stringify(args) + ',\n');
1213
+ return Promise.resolve();
1314
+ }
1415
+

0 commit comments

Comments
 (0)