|
| 1 | +import * as path from "path"; |
| 2 | +import * as fs from "fs"; |
| 3 | +import * as os from "os"; |
| 4 | +import { describeNode18Plus } from "../../utils/testIf"; |
| 5 | +import { execSync } from "child_process"; |
| 6 | + |
| 7 | +function createTempDir() { |
| 8 | + return fs.mkdtempSync(path.join(os.tmpdir(), "sentry-bundler-plugin-upload-")); |
| 9 | +} |
| 10 | + |
| 11 | +const SPEC_DEBUG_ID_REGEX = /\/\/# debugId=([a-fA-F0-9-]+)/g; |
| 12 | + |
| 13 | +function countDebugIdComments(source: string): number { |
| 14 | + const matches = source.match(SPEC_DEBUG_ID_REGEX); |
| 15 | + if (matches) { |
| 16 | + return matches.length; |
| 17 | + } |
| 18 | + return 0; |
| 19 | +} |
| 20 | + |
| 21 | +function getSingleJavaScriptSourceFileFromDirectory( |
| 22 | + dir: string, |
| 23 | + fileExtension = ".js" |
| 24 | +): string | undefined { |
| 25 | + const files = fs.readdirSync(dir); |
| 26 | + const jsFiles = files.filter((file) => file.endsWith(fileExtension)); |
| 27 | + if (jsFiles.length === 1) { |
| 28 | + return fs.readFileSync(path.join(dir, jsFiles[0] as string), "utf-8"); |
| 29 | + } |
| 30 | + return undefined; |
| 31 | +} |
| 32 | + |
| 33 | +describeNode18Plus("vite 6 bundle", () => { |
| 34 | + const viteRoot = path.join(__dirname, "input", "vite6"); |
| 35 | + const tempDir = createTempDir(); |
| 36 | + |
| 37 | + beforeEach(() => { |
| 38 | + execSync("yarn install", { cwd: viteRoot, stdio: "inherit" }); |
| 39 | + execSync("yarn vite build", { |
| 40 | + cwd: viteRoot, |
| 41 | + stdio: "inherit", |
| 42 | + env: { ...process.env, SENTRY_TEST_OVERRIDE_TEMP_DIR: tempDir }, |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + test("check vite 6 bundle", () => { |
| 47 | + const source = getSingleJavaScriptSourceFileFromDirectory(tempDir); |
| 48 | + expect(source).toBeDefined(); |
| 49 | + const debugIds = countDebugIdComments(source as string); |
| 50 | + expect(debugIds).toBe(1); |
| 51 | + }); |
| 52 | + |
| 53 | + afterEach(() => { |
| 54 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describeNode18Plus("webpack 5 bundle", () => { |
| 59 | + const viteRoot = path.join(__dirname, "input", "webpack5"); |
| 60 | + const tempDir = createTempDir(); |
| 61 | + |
| 62 | + beforeEach(() => { |
| 63 | + execSync("yarn install", { cwd: viteRoot, stdio: "inherit" }); |
| 64 | + execSync("yarn webpack build", { |
| 65 | + cwd: viteRoot, |
| 66 | + stdio: "inherit", |
| 67 | + env: { ...process.env, SENTRY_TEST_OVERRIDE_TEMP_DIR: tempDir }, |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + test("check webpack 5 bundle", () => { |
| 72 | + const source = getSingleJavaScriptSourceFileFromDirectory(tempDir); |
| 73 | + expect(source).toBeDefined(); |
| 74 | + const debugIds = countDebugIdComments(source as string); |
| 75 | + expect(debugIds).toBe(1); |
| 76 | + }); |
| 77 | + |
| 78 | + afterEach(() => { |
| 79 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 80 | + }); |
| 81 | +}); |
| 82 | + |
| 83 | +describeNode18Plus("rollup bundle", () => { |
| 84 | + const viteRoot = path.join(__dirname, "input", "rollup4"); |
| 85 | + const tempDir = createTempDir(); |
| 86 | + |
| 87 | + beforeEach(() => { |
| 88 | + execSync("yarn install", { cwd: viteRoot, stdio: "inherit" }); |
| 89 | + execSync("yarn rollup --config rollup.config.js", { |
| 90 | + cwd: viteRoot, |
| 91 | + stdio: "inherit", |
| 92 | + env: { ...process.env, SENTRY_TEST_OVERRIDE_TEMP_DIR: tempDir }, |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + test("check rollup bundle", () => { |
| 97 | + const source = getSingleJavaScriptSourceFileFromDirectory(tempDir); |
| 98 | + expect(source).toBeDefined(); |
| 99 | + const debugIds = countDebugIdComments(source as string); |
| 100 | + expect(debugIds).toBe(1); |
| 101 | + }); |
| 102 | + |
| 103 | + afterEach(() => { |
| 104 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 105 | + }); |
| 106 | +}); |
0 commit comments