Make the bundler tests use the API by default in most cases (#22646)

### What does this PR do?

This branch:
> Ran 1600 tests across 46 files. [63.24s]

Main:
> Ran 1600 tests across 46 files. [137.05s]

This makes the bundler tests run about 60 seconds faster 

### How did you verify your code works?
This commit is contained in:
Jarred Sumner
2025-09-14 02:27:53 -07:00
committed by GitHub
parent 8614b98f6b
commit 9411c62756
8 changed files with 38 additions and 2 deletions

View File

@@ -106,6 +106,7 @@ describe("bundler", () => {
run: { stdout: "Hello, world!" },
});
itBundled("compile/WorkerRelativePathNoExtension", {
backend: "cli",
compile: true,
files: {
"/entry.ts": /* js */ `
@@ -125,6 +126,7 @@ describe("bundler", () => {
run: { stdout: "Hello, world!\nWorker loaded!\n", file: "dist/out", setCwd: true },
});
itBundled("compile/WorkerRelativePathTSExtension", {
backend: "cli",
compile: true,
files: {
"/entry.ts": /* js */ `
@@ -143,6 +145,7 @@ describe("bundler", () => {
run: { stdout: "Hello, world!\nWorker loaded!\n", file: "dist/out", setCwd: true },
});
itBundled("compile/WorkerRelativePathTSExtensionBytecode", {
backend: "cli",
compile: true,
bytecode: true,
files: {
@@ -558,6 +561,7 @@ describe("bundler", () => {
});
itBundled("compile/ImportMetaMain", {
compile: true,
backend: "cli",
files: {
"/entry.ts": /* js */ `
// test toString on function to observe what the inlined value was

View File

@@ -274,6 +274,7 @@ describe("bundler", () => {
"/entry.js": /* js */ `console.log(1)`,
},
outdir: "/out",
backend: "cli",
loader: {
".cool": "wtf",
},
@@ -2071,6 +2072,7 @@ describe("bundler", () => {
});
itBundled("edgecase/OutWithTwoFiles", {
backend: "cli",
files: {
"/entry.ts": `
import index from './index.html' with { type: 'file' }

View File

@@ -4,6 +4,7 @@ import { itBundled } from "./expectBundled";
describe("bundler", () => {
itBundled("footer/CommentFooter", {
footer: "// developed with love in SF",
backend: "cli",
files: {
"/a.js": `console.log("Hello, world!")`,
},
@@ -16,6 +17,7 @@ describe("bundler", () => {
* This is copyright of [...] ${new Date().getFullYear()}
* do not redistribute without consent of [...]
*/`,
backend: "cli",
files: {
"index.js": `console.log("Hello, world!")`,
},

View File

@@ -216,6 +216,7 @@ describe("bundler", () => {
});
itBundled("regression/WindowsBackslashAssertion1#9974", {
backend: "cli",
files: {
"/test/entry.ts": `
import { loadFonts } from "../base";

View File

@@ -7,6 +7,7 @@ describe("bundler", () => {
compile: {
execArgv: ["--title=CompileExecArgvDualBehavior", "--smol"],
},
backend: "cli",
files: {
"/entry.ts": /* js */ `
// Test that --compile-exec-argv both processes flags AND populates execArgv
@@ -52,6 +53,7 @@ describe("bundler", () => {
compile: {
execArgv: ["--user-agent=test-agent", "--smol"],
},
backend: "cli",
files: {
"/entry.ts": /* js */ `
// Test that compile-exec-argv options don't appear in process.argv
@@ -115,6 +117,7 @@ describe("bundler", () => {
compile: {
execArgv: ["--user-agent=test-agent", "--smol"],
},
backend: "cli",
files: {
"/entry.ts": /* js */ `
// Test that user arguments are properly included when exec argv is present

View File

@@ -1241,6 +1241,7 @@ describe("bundler", () => {
},
minifyWhitespace: minify,
emitDCEAnnotations: emitDCEAnnotations,
backend: "cli",
onAfterBundle(api) {
const code = api.readFile("/out.js");
expect(code).not.toContain("_yes"); // should not contain any *_yes variables

View File

@@ -572,7 +572,22 @@ function expectBundled(
return (async () => {
if (!backend) {
backend = plugins !== undefined ? "api" : "cli";
backend =
dotenv ||
jsx.factory ||
jsx.fragment ||
jsx.runtime ||
jsx.importSource ||
typeof production !== "undefined" ||
bundling === false ||
(run && target === "node") ||
emitDCEAnnotations ||
bundleWarnings ||
env ||
run?.validate ||
define
? "cli"
: "api";
}
let root = path.join(
@@ -1107,7 +1122,13 @@ for (const [key, blob] of build.outputs) {
configRef = buildConfig;
let build: BuildOutput;
try {
build = await Bun.build(buildConfig);
const cwd = process.cwd();
process.chdir(root);
try {
build = await Bun.build(buildConfig);
} finally {
process.chdir(cwd);
}
} catch (e) {
if (e instanceof AggregateError) {
build = {