-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathdebug-ids-already-injected.test.ts
More file actions
106 lines (90 loc) · 3.03 KB
/
debug-ids-already-injected.test.ts
File metadata and controls
106 lines (90 loc) · 3.03 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as path from "path";
import * as fs from "fs";
import * as os from "os";
import { describeNode18Plus } from "../../utils/testIf";
import { execSync } from "child_process";
function createTempDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), "sentry-bundler-plugin-upload-"));
}
const SPEC_DEBUG_ID_REGEX = /\/\/# debugId=([a-fA-F0-9-]+)/g;
function countDebugIdComments(source: string): number {
const matches = source.match(SPEC_DEBUG_ID_REGEX);
if (matches) {
return matches.length;
}
return 0;
}
function getSingleJavaScriptSourceFileFromDirectory(
dir: string,
fileExtension = ".js"
): string | undefined {
const files = fs.readdirSync(dir);
const jsFiles = files.filter((file) => file.endsWith(fileExtension));
if (jsFiles.length === 1) {
return fs.readFileSync(path.join(dir, jsFiles[0] as string), "utf-8");
}
return undefined;
}
describeNode18Plus("vite 6 bundle", () => {
const viteRoot = path.join(__dirname, "input", "vite6");
const tempDir = createTempDir();
beforeEach(() => {
execSync("yarn install", { cwd: viteRoot, stdio: "inherit" });
execSync("yarn vite build", {
cwd: viteRoot,
stdio: "inherit",
env: { ...process.env, SENTRY_TEST_OVERRIDE_TEMP_DIR: tempDir },
});
});
test("check vite 6 bundle", () => {
const source = getSingleJavaScriptSourceFileFromDirectory(tempDir);
expect(source).toBeDefined();
const debugIds = countDebugIdComments(source as string);
expect(debugIds).toBe(1);
});
afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
});
describeNode18Plus("webpack 5 bundle", () => {
const webpackRoot = path.join(__dirname, "input", "webpack5");
const tempDir = createTempDir();
beforeEach(() => {
execSync("yarn install", { cwd: webpackRoot, stdio: "inherit" });
execSync("yarn webpack build", {
cwd: webpackRoot,
stdio: "inherit",
env: { ...process.env, SENTRY_TEST_OVERRIDE_TEMP_DIR: tempDir },
});
});
test("check webpack 5 bundle", () => {
const source = getSingleJavaScriptSourceFileFromDirectory(tempDir);
expect(source).toBeDefined();
const debugIds = countDebugIdComments(source as string);
expect(debugIds).toBe(1);
});
afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
});
describeNode18Plus("rollup bundle", () => {
const rollupRoot = path.join(__dirname, "input", "rollup4");
const tempDir = createTempDir();
beforeEach(() => {
execSync("yarn install", { cwd: rollupRoot, stdio: "inherit" });
execSync("yarn rollup --config rollup.config.js", {
cwd: rollupRoot,
stdio: "inherit",
env: { ...process.env, SENTRY_TEST_OVERRIDE_TEMP_DIR: tempDir },
});
});
test("check rollup bundle", () => {
const source = getSingleJavaScriptSourceFileFromDirectory(tempDir);
expect(source).toBeDefined();
const debugIds = countDebugIdComments(source as string);
expect(debugIds).toBe(1);
});
afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
});