|
| 1 | +/* eslint-disable jest/no-standalone-expect */ |
| 2 | +/* eslint-disable jest/expect-expect */ |
| 3 | +import childProcess from "child_process"; |
| 4 | +import path from "path"; |
| 5 | +import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf"; |
| 6 | + |
| 7 | +function checkBundle(bundlePath1: string, bundlePath2: string) { |
| 8 | + const process1Output = childProcess.execSync(`node ${bundlePath1}`, { encoding: "utf-8" }); |
| 9 | + const debugIdMap1 = JSON.parse(process1Output) as Record<string, string>; |
| 10 | + const debugIds1 = Object.values(debugIdMap1); |
| 11 | + expect(debugIds1).toHaveLength(0); |
| 12 | + |
| 13 | + const process2Output = childProcess.execSync(`node ${bundlePath2}`, { encoding: "utf-8" }); |
| 14 | + const debugIdMap2 = JSON.parse(process2Output) as Record<string, string>; |
| 15 | + const debugIds2 = Object.values(debugIdMap2); |
| 16 | + expect(debugIds2).toHaveLength(0); |
| 17 | +} |
| 18 | + |
| 19 | +describe("should not inject debug IDs when `sourcemaps.disable` is `true`", () => { |
| 20 | + test("esbuild bundle", () => { |
| 21 | + checkBundle( |
| 22 | + path.join(__dirname, "out", "esbuild", "bundle1.js"), |
| 23 | + path.join(__dirname, "out", "esbuild", "bundle2.js") |
| 24 | + ); |
| 25 | + }); |
| 26 | + |
| 27 | + test("rollup bundle", () => { |
| 28 | + checkBundle( |
| 29 | + path.join(__dirname, "out", "rollup", "bundle1.js"), |
| 30 | + path.join(__dirname, "out", "rollup", "bundle2.js") |
| 31 | + ); |
| 32 | + }); |
| 33 | + |
| 34 | + test("vite bundle", () => { |
| 35 | + checkBundle( |
| 36 | + path.join(__dirname, "out", "vite", "bundle1.js"), |
| 37 | + path.join(__dirname, "out", "vite", "bundle2.js") |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => { |
| 42 | + checkBundle( |
| 43 | + path.join(__dirname, "out", "webpack4", "bundle1.js"), |
| 44 | + path.join(__dirname, "out", "webpack4", "bundle2.js") |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + test("webpack 5 bundle", () => { |
| 49 | + checkBundle( |
| 50 | + path.join(__dirname, "out", "webpack5", "bundle1.js"), |
| 51 | + path.join(__dirname, "out", "webpack5", "bundle2.js") |
| 52 | + ); |
| 53 | + }); |
| 54 | +}); |
0 commit comments