Skip to content

Commit 9411c62

Browse files
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?
1 parent 8614b98 commit 9411c62

File tree

8 files changed

+38
-2
lines changed

8 files changed

+38
-2
lines changed

src/interchange/json.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn JSONLikeParser_(
170170
try p.lexer.next();
171171
var is_single_line = !p.lexer.has_newline_before;
172172
var exprs = std.ArrayList(Expr).init(p.list_allocator);
173+
errdefer exprs.deinit();
173174

174175
while (p.lexer.token != .t_close_bracket) {
175176
if (exprs.items.len > 0) {
@@ -203,6 +204,7 @@ fn JSONLikeParser_(
203204
try p.lexer.next();
204205
var is_single_line = !p.lexer.has_newline_before;
205206
var properties = std.ArrayList(G.Property).init(p.list_allocator);
207+
errdefer properties.deinit();
206208

207209
const DuplicateNodeType = comptime if (opts.json_warn_duplicate_keys) *HashMapPool.LinkedList.Node else void;
208210
const HashMapType = comptime if (opts.json_warn_duplicate_keys) HashMapPool.HashMap else void;

test/bundler/bundler_compile.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe("bundler", () => {
106106
run: { stdout: "Hello, world!" },
107107
});
108108
itBundled("compile/WorkerRelativePathNoExtension", {
109+
backend: "cli",
109110
compile: true,
110111
files: {
111112
"/entry.ts": /* js */ `
@@ -125,6 +126,7 @@ describe("bundler", () => {
125126
run: { stdout: "Hello, world!\nWorker loaded!\n", file: "dist/out", setCwd: true },
126127
});
127128
itBundled("compile/WorkerRelativePathTSExtension", {
129+
backend: "cli",
128130
compile: true,
129131
files: {
130132
"/entry.ts": /* js */ `
@@ -143,6 +145,7 @@ describe("bundler", () => {
143145
run: { stdout: "Hello, world!\nWorker loaded!\n", file: "dist/out", setCwd: true },
144146
});
145147
itBundled("compile/WorkerRelativePathTSExtensionBytecode", {
148+
backend: "cli",
146149
compile: true,
147150
bytecode: true,
148151
files: {
@@ -558,6 +561,7 @@ describe("bundler", () => {
558561
});
559562
itBundled("compile/ImportMetaMain", {
560563
compile: true,
564+
backend: "cli",
561565
files: {
562566
"/entry.ts": /* js */ `
563567
// test toString on function to observe what the inlined value was

test/bundler/bundler_edgecase.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ describe("bundler", () => {
274274
"/entry.js": /* js */ `console.log(1)`,
275275
},
276276
outdir: "/out",
277+
backend: "cli",
277278
loader: {
278279
".cool": "wtf",
279280
},
@@ -2071,6 +2072,7 @@ describe("bundler", () => {
20712072
});
20722073

20732074
itBundled("edgecase/OutWithTwoFiles", {
2075+
backend: "cli",
20742076
files: {
20752077
"/entry.ts": `
20762078
import index from './index.html' with { type: 'file' }

test/bundler/bundler_footer.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { itBundled } from "./expectBundled";
44
describe("bundler", () => {
55
itBundled("footer/CommentFooter", {
66
footer: "// developed with love in SF",
7+
backend: "cli",
78
files: {
89
"/a.js": `console.log("Hello, world!")`,
910
},
@@ -16,6 +17,7 @@ describe("bundler", () => {
1617
* This is copyright of [...] ${new Date().getFullYear()}
1718
* do not redistribute without consent of [...]
1819
*/`,
20+
backend: "cli",
1921
files: {
2022
"index.js": `console.log("Hello, world!")`,
2123
},

test/bundler/bundler_regressions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ describe("bundler", () => {
216216
});
217217

218218
itBundled("regression/WindowsBackslashAssertion1#9974", {
219+
backend: "cli",
219220
files: {
220221
"/test/entry.ts": `
221222
import { loadFonts } from "../base";

test/bundler/compile-argv.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe("bundler", () => {
77
compile: {
88
execArgv: ["--title=CompileExecArgvDualBehavior", "--smol"],
99
},
10+
backend: "cli",
1011
files: {
1112
"/entry.ts": /* js */ `
1213
// Test that --compile-exec-argv both processes flags AND populates execArgv
@@ -52,6 +53,7 @@ describe("bundler", () => {
5253
compile: {
5354
execArgv: ["--user-agent=test-agent", "--smol"],
5455
},
56+
backend: "cli",
5557
files: {
5658
"/entry.ts": /* js */ `
5759
// Test that compile-exec-argv options don't appear in process.argv
@@ -115,6 +117,7 @@ describe("bundler", () => {
115117
compile: {
116118
execArgv: ["--user-agent=test-agent", "--smol"],
117119
},
120+
backend: "cli",
118121
files: {
119122
"/entry.ts": /* js */ `
120123
// Test that user arguments are properly included when exec argv is present

test/bundler/esbuild/dce.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ describe("bundler", () => {
12411241
},
12421242
minifyWhitespace: minify,
12431243
emitDCEAnnotations: emitDCEAnnotations,
1244+
backend: "cli",
12441245
onAfterBundle(api) {
12451246
const code = api.readFile("/out.js");
12461247
expect(code).not.toContain("_yes"); // should not contain any *_yes variables

test/bundler/expectBundled.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,22 @@ function expectBundled(
572572

573573
return (async () => {
574574
if (!backend) {
575-
backend = plugins !== undefined ? "api" : "cli";
575+
backend =
576+
dotenv ||
577+
jsx.factory ||
578+
jsx.fragment ||
579+
jsx.runtime ||
580+
jsx.importSource ||
581+
typeof production !== "undefined" ||
582+
bundling === false ||
583+
(run && target === "node") ||
584+
emitDCEAnnotations ||
585+
bundleWarnings ||
586+
env ||
587+
run?.validate ||
588+
define
589+
? "cli"
590+
: "api";
576591
}
577592

578593
let root = path.join(
@@ -1107,7 +1122,13 @@ for (const [key, blob] of build.outputs) {
11071122
configRef = buildConfig;
11081123
let build: BuildOutput;
11091124
try {
1110-
build = await Bun.build(buildConfig);
1125+
const cwd = process.cwd();
1126+
process.chdir(root);
1127+
try {
1128+
build = await Bun.build(buildConfig);
1129+
} finally {
1130+
process.chdir(cwd);
1131+
}
11111132
} catch (e) {
11121133
if (e instanceof AggregateError) {
11131134
build = {

0 commit comments

Comments
 (0)