mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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' }
|
||||
|
||||
@@ -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!")`,
|
||||
},
|
||||
|
||||
@@ -216,6 +216,7 @@ describe("bundler", () => {
|
||||
});
|
||||
|
||||
itBundled("regression/WindowsBackslashAssertion1#9974", {
|
||||
backend: "cli",
|
||||
files: {
|
||||
"/test/entry.ts": `
|
||||
import { loadFonts } from "../base";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user