": [`ModuleNotFound resolving "entry". Did you mean: "./entry"`],
+ run: {
+ file: "/out.js",
+ stdout: "123",
},
});
itBundled("default/MultipleEntryPointsSameNameCollision", {
@@ -2750,7 +2806,7 @@ describe("bundler", () => {
file: "/test.js",
stdout: "foo bar",
},
- mode: "transform",
+ external: ["*"],
});
itBundled("default/ImportMetaCommonJS", {
files: {
@@ -3452,6 +3508,7 @@ describe("bundler", () => {
mode: "transform",
});
itBundled("default/TopLevelAwaitForbiddenRequire", {
+ notImplemented: true,
files: {
"/entry.js": /* js */ `
require('./a')
@@ -3585,6 +3642,7 @@ describe("bundler", () => {
},
});
itBundled("default/AssignToImportNoBundle", {
+ notImplemented: true,
files: {
"/bad0.js": `import x from "foo"; x = 1`,
"/bad1.js": `import x from "foo"; x++`,
@@ -4486,6 +4544,7 @@ describe("bundler", () => {
},
});
itBundled("default/CharFreqIgnoreComments", {
+ notImplemented: true,
files: {
"/a.js": /* js */ `
export default function(one, two, three, four) {
@@ -4689,7 +4748,6 @@ describe("bundler", () => {
// mode: "transform",
// external: ["a", "b", "c", "react/jsx-dev-runtime"],
// });
- if (!RUN_UNCHECKED_TESTS) return;
// I cant get bun to use `this` as the JSX runtime. It's a pretty silly idea anyways.
// itBundled("default/JSXThisValueCommonJS", {
// files: {
@@ -4928,13 +4986,13 @@ describe("bundler", () => {
// `, */
// });
0;
-
itBundled("default/BundlingFilesOutsideOfOutbase", {
- // GENERATED
+ notImplemented: true,
files: {
"/src/entry.js": `console.log('test')`,
},
splitting: true,
+ outdir: "/out",
format: "esm",
outbase: "/some/nested/directory",
});
@@ -5009,17 +5067,14 @@ describe("bundler", () => {
const relocateEntries = ["/top-level.js", "/nested.js", "/let.js", "/function.js", "/function-nested.js"];
itBundled("default/VarRelocatingBundle", {
- // GENERATED
files: relocateFiles,
entryPoints: relocateEntries,
format: "esm",
});
itBundled("default/VarRelocatingNoBundle", {
- // GENERATED
files: relocateFiles,
entryPoints: relocateEntries,
format: "esm",
- mode: "convertformat",
});
itBundled("default/ImportNamespaceThisValue", {
// GENERATED
@@ -5038,11 +5093,12 @@ describe("bundler", () => {
console.log(new def(), new foo())
`,
},
+ external: ["external"],
entryPoints: ["/a.js", "/b.js", "/c.js"],
format: "cjs",
});
+ // esbuild and bun do not give the warning. this is still set to undefined
itBundled("default/ThisUndefinedWarningESM", {
- // GENERATED
files: {
"/entry.js": /* js */ `
import x from './file1.js'
@@ -5052,35 +5108,42 @@ describe("bundler", () => {
"/file1.js": `export default [this, this]`,
"/node_modules/pkg/file2.js": `export default [this, this]`,
},
- /* TODO FIX expectedScanLog: `file1.js: DEBUG: Top-level "this" will be replaced with undefined since this file is an ECMAScript module
- file1.js: NOTE: This file is considered to be an ECMAScript module because of the "export" keyword here:
- node_modules/pkg/file2.js: DEBUG: Top-level "this" will be replaced with undefined since this file is an ECMAScript module
- node_modules/pkg/file2.js: NOTE: This file is considered to be an ECMAScript module because of the "export" keyword here:
- `, */
+ run: {
+ stdout: "[ null, null ] [ null, null ]",
+ },
});
itBundled("default/QuotedProperty", {
- // GENERATED
+ notImplemented: true,
files: {
"/entry.js": /* js */ `
import * as ns from 'ext'
console.log(ns.mustBeUnquoted, ns['mustBeQuoted'])
`,
},
- format: "cjs",
+ external: ["ext"],
+ onAfterBundle(api) {
+ const code = api.readFile("/out.js");
+ expect(code).not.toContain(`"mustBeUnquoted"`);
+ expect(code).toContain(`"mustBeQuoted"`);
+ },
});
itBundled("default/QuotedPropertyMangle", {
- // GENERATED
files: {
"/entry.js": /* js */ `
import * as ns from 'ext'
console.log(ns.mustBeUnquoted, ns['mustBeUnquoted2'])
`,
},
- format: "cjs",
minifySyntax: true,
+ external: ["ext"],
+ onAfterBundle(api) {
+ const code = api.readFile("/out.js");
+ expect(code).toContain(`.mustBeUnquoted`);
+ expect(code).toContain(`.mustBeUnquoted2`);
+ },
});
itBundled("default/DuplicatePropertyWarning", {
- // GENERATED
+ notImplemented: true,
files: {
"/entry.js": /* js */ `
import './outside-node-modules'
@@ -5091,19 +5154,17 @@ describe("bundler", () => {
"/node_modules/inside-node-modules/index.jsx": `console.log({ c: 1, c: 2 }, )`,
"/node_modules/inside-node-modules/package.json": `{ "d": 1, "d": 2 }`,
},
- /* TODO FIX expectedScanLog: `outside-node-modules/index.jsx: WARNING: Duplicate key "a" in object literal
- outside-node-modules/index.jsx: NOTE: The original key "a" is here:
- outside-node-modules/index.jsx: WARNING: Duplicate "a2" attribute in JSX element
- outside-node-modules/index.jsx: NOTE: The original "a2" attribute is here:
- outside-node-modules/package.json: WARNING: Duplicate key "b" in object literal
- outside-node-modules/package.json: NOTE: The original key "b" is here:
- `, */
+ external: ["react"],
+ bundleWarnings: {
+ "/outside-node-modules/index.jsx": ['Duplicate key "a" in object literal', 'Duplicate key "a2" in JSX element'],
+ "/outside-node-modules/package.json": ['Duplicate key "b" in object literal'],
+ },
});
- itBundled("default/RequireShimSubstitution", {
- // GENERATED
+ const RequireShimSubstitutionBrowser = itBundled("default/RequireShimSubstitutionBrowser", {
+ notImplemented: true,
files: {
"/entry.js": /* js */ `
- console.log([
+ Promise.all([
require,
typeof require,
require('./example.json'),
@@ -5116,14 +5177,84 @@ describe("bundler", () => {
require.resolve(window.SOME_PATH),
import('some-path'),
import(window.SOME_PATH),
- ])
+ ]).then(results => {
+ for (let result of results) {
+ if (typeof result === 'string' && result.startsWith(dirname)) {
+ result = result.slice(dirname.length)
+ }
+ console.log(typeof result, JSON.stringify(result))
+ }
+ })
`,
"/example.json": `{ "works": true }`,
},
- external: ["some-path"],
+ runtimeFiles: {
+ "/test.mjs": `
+ import { createRequire } from "module";
+ const require = createRequire(import.meta.url);
+ import { fileURLToPath } from "url";
+ import { dirname } from "path";
+ globalThis.dirname = dirname(fileURLToPath(import.meta.url));
+ globalThis.window = globalThis
+ window.SOME_PATH = 'second-path'
+ window.require = require
+ window.module = { require: (x) => 'dynamic req: ' + x }
+ await import('./out.mjs')
+ `,
+ "/node_modules/some-path/index.js": `module.exports = 123`,
+ "/node_modules/second-path/index.js": `module.exports = 567`,
+ },
+ external: ["*"],
+ platform: "browser",
+ format: "esm",
+ outfile: "/out.mjs",
+ run: {
+ runtime: "node",
+ file: "/test.mjs",
+ stdout: `
+ function undefined
+ string "function"
+ object {"works":true}
+ object {"works":true}
+ number 567
+ object {"works":true}
+ object {"works":true}
+ number 567
+ string "/node_modules/some-path/index.js"
+ string "/node_modules/second-path/index.js"
+ object {"default":123}
+ object {"default":567}
+ `,
+ },
+ });
+ itBundled("default/RequireShimSubstitutionNode", {
+ notImplemented: true,
+ files: RequireShimSubstitutionBrowser.options.files,
+ runtimeFiles: RequireShimSubstitutionBrowser.options.runtimeFiles,
+ external: ["*"],
+ platform: "node",
+ format: "esm",
+ outfile: "/out.mjs",
+ run: {
+ runtime: "node",
+ file: "/test.mjs",
+ stdout: `
+ function undefined
+ string "function"
+ object {"works":true}
+ object {"works":true}
+ number 567
+ object {"works":true}
+ object {"works":true}
+ number 567
+ string "/node_modules/some-path/index.js"
+ string "/node_modules/second-path/index.js"
+ object {"default":123}
+ object {"default":567}
+ `,
+ },
});
itBundled("default/StrictModeNestedFnDeclKeepNamesVariableInliningESBuildIssue1552", {
- // GENERATED
files: {
"/entry.js": /* js */ `
export function outer() {
@@ -5139,10 +5270,11 @@ describe("bundler", () => {
`,
},
keepNames: true,
- mode: "passthrough",
+ minifySyntax: true,
});
itBundled("default/BuiltInNodeModulePrecedence", {
// GENERATED
+ notImplemented: true,
files: {
"/entry.js": /* js */ `
console.log([
@@ -5161,7 +5293,6 @@ describe("bundler", () => {
"/node_modules/fs/promises.js": `throw 'DO NOT INCLUDE THIS'`,
},
platform: "node",
- format: "cjs",
});
itBundled("default/EntryNamesNoSlashAfterDir", {
// GENERATED
@@ -5170,59 +5301,60 @@ describe("bundler", () => {
"/src/app2/main.ts": `console.log(2)`,
"/src/app3/main.ts": `console.log(3)`,
},
- entryPointsAdvanced: [
- { input: "/src/app1/main.ts" },
- { input: "/src/app2/main.ts" },
- { input: "/src/app3/main.ts", output: "customPath" },
- ],
+ entryPoints: ["/src/app1/main.ts", "/src/app2/main.ts", "/src/app3/main.ts"],
+ outputPaths: ["/out/app1-main.js", "/out/app2-main.js", "/out/app3-main.js"],
entryNames: "[dir]-[name].[ext]",
- mode: "passthrough",
- });
- itBundled("default/EntryNamesNonPortableCharacter", {
- // GENERATED
- // TODO: I think this is impossible with the CLI. and also very unsafe with paths.
- files: {
- "/entry1-*.ts": `console.log(1)`,
- "/entry2-*.ts": `console.log(2)`,
- },
- entryPointsAdvanced: [
- // The "*" should turn into "_" for cross-platform Windows portability
- { input: "/entry1-*.ts" },
- // The "*" should be preserved since the user _really_ wants it
- { input: "/entry2-*.ts", output: "entry2-*" },
- ],
- mode: "passthrough",
- });
- itBundled("default/EntryNamesChunkNamesExtPlaceholder", {
- // GENERATED
- files: {
- "/src/entries/entry1.js": `import "../lib/shared.js"; import "./entry1.css"; console.log('entry1')`,
- "/src/entries/entry2.js": `import "../lib/shared.js"; import "./entry2.css"; console.log('entry2')`,
- "/src/entries/entry1.css": `a:after { content: "entry1" }`,
- "/src/entries/entry2.css": `a:after { content: "entry2" }`,
- "/src/lib/shared.js": `console.log('shared')`,
- },
- entryPoints: ["/src/entries/entry1.js", "/src/entries/entry2.js"],
- outbase: "/src",
- splitting: true,
- entryNames: "main/[ext]/[name]-[hash].[ext]",
});
+ // itBundled("default/EntryNamesNonPortableCharacter", {
+ // // GENERATED
+ // // TODO: I think this is impossible with the CLI. and also very unsafe with paths.
+ // files: {
+ // "/entry1-*.ts": `console.log(1)`,
+ // "/entry2-*.ts": `console.log(2)`,
+ // },
+ // entryPointsAdvanced: [
+ // // The "*" should turn into "_" for cross-platform Windows portability
+ // { input: "/entry1-*.ts" },
+ // // The "*" should be preserved since the user _really_ wants it
+ // { input: "/entry2-*.ts", output: "entry2-*" },
+ // ],
+ // mode: "passthrough",
+ // });
+ // itBundled("default/EntryNamesChunkNamesExtPlaceholder", {
+ // files: {
+ // "/src/entries/entry1.js": `import "../lib/shared.js"; import "./entry1.css"; console.log('entry1')`,
+ // "/src/entries/entry2.js": `import "../lib/shared.js"; import "./entry2.css"; console.log('entry2')`,
+ // "/src/entries/entry1.css": `a:after { content: "entry1" }`,
+ // "/src/entries/entry2.css": `a:after { content: "entry2" }`,
+ // "/src/lib/shared.js": `console.log('shared')`,
+ // },
+ // entryPoints: ["/src/entries/entry1.js", "/src/entries/entry2.js"],
+ // outbase: "/src",
+ // splitting: true,
+ // entryNames: "main/[ext]/[name]-[hash].[ext]",
+ // });
itBundled("default/MinifyIdentifiersImportPathFrequencyAnalysis", {
- // GENERATED
files: {
"/import.js": /* js */ `
import foo from "./WWWWWWWWWWXXXXXXXXXXYYYYYYYYYYZZZZZZZZZZ"
- console.log(foo, 'no identifier in this file should be named W, X, Y, or Z')
+ console.log(foo, remove('no identifier in this file should be named W, X, Y, or Z'))
`,
"/WWWWWWWWWWXXXXXXXXXXYYYYYYYYYYZZZZZZZZZZ.js": `export default 123`,
"/require.js": /* js */ `
const foo = require("./AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD")
- console.log(foo, 'no identifier in this file should be named A, B, C, or D')
+ console.log(foo, remove('no identifier in this file should be named A, B, C, or D'))
`,
"/AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDD.js": `module.exports = 123`,
},
entryPoints: ["/import.js", "/require.js"],
minifyWhitespace: true,
+ minifyIdentifiers: true,
+ onAfterBundle(api) {
+ let importFile = api.readFile("/out/import.js").replace(/remove\(.*?\)/g, "remove()");
+ let requireFile = api.readFile("/out/require.js").replace(/remove\(.*?\)/g, "remove()");
+ assert(!["W", "X", "Y", "Z"].some(x => importFile.includes(x)));
+ assert(!["A", "B", "C", "D"].some(x => requireFile.includes(x)));
+ },
});
itBundled("default/ToESMWrapperOmission", {
// GENERATED
@@ -5260,67 +5392,19 @@ describe("bundler", () => {
`,
},
format: "cjs",
- mode: "convertformat",
+ external: ["*"],
});
itBundled("default/NamedFunctionExpressionArgumentCollision", {
- // GENERATED
files: {
"/entry.js": /* js */ `
let x = function foo(foo) {
var foo;
return foo;
}
+ console.log(x(123))
`,
},
- mode: "passthrough",
- });
- itBundled("default/NoWarnCommonJSExportsInESMPassThrough", {
- // GENERATED
- files: {
- "/cjs-in-esm.js": /* js */ `
- export let foo = 1
- exports.foo = 2
- module.exports = 3
- `,
- "/import-in-cjs.js": /* js */ `
- import { foo } from 'bar'
- exports.foo = foo
- module.exports = foo
- `,
- "/no-warnings-here.js": `console.log(module, exports)`,
- },
- entryPoints: ["/cjs-in-esm.js", "/import-in-cjs.js", "/no-warnings-here.js"],
- mode: "passthrough",
- });
- itBundled("default/WarnCommonJSExportsInESMConvert", {
- // GENERATED
- files: {
- "/cjs-in-esm.js": /* js */ `
- export let foo = 1
- exports.foo = 2
- module.exports = 3
- `,
- "/cjs-in-esm2.js": /* js */ `
- export let foo = 1
- module.exports.bar = 3
- `,
- "/import-in-cjs.js": /* js */ `
- import { foo } from 'bar'
- exports.foo = foo
- module.exports = foo
- module.exports.bar = foo
- `,
- "/no-warnings-here.js": `console.log(module, exports)`,
- },
- entryPoints: ["/cjs-in-esm.js", "/cjs-in-esm2.js", "/import-in-cjs.js", "/no-warnings-here.js"],
- mode: "convertformat",
- /* TODO FIX expectedScanLog: `cjs-in-esm.js: WARNING: The CommonJS "exports" variable is treated as a global variable in an ECMAScript module and may not work as expected
- cjs-in-esm.js: NOTE: This file is considered to be an ECMAScript module because of the "export" keyword here:
- cjs-in-esm.js: WARNING: The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected
- cjs-in-esm.js: NOTE: This file is considered to be an ECMAScript module because of the "export" keyword here:
- cjs-in-esm2.js: WARNING: The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected
- cjs-in-esm2.js: NOTE: This file is considered to be an ECMAScript module because of the "export" keyword here:
- `, */
+ minifySyntax: true,
});
itBundled("default/WarnCommonJSExportsInESMBundle", {
// GENERATED
@@ -5344,6 +5428,7 @@ describe("bundler", () => {
cjs-in-esm.js: WARNING: The CommonJS "module" variable is treated as a global variable in an ECMAScript module and may not work as expected
cjs-in-esm.js: NOTE: This file is considered to be an ECMAScript module because of the "export" keyword here:
`, */
+ external: ["bar"],
});
itBundled("default/MangleProps", {
// GENERATED
@@ -5389,7 +5474,8 @@ describe("bundler", () => {
`,
},
entryPoints: ["/entry1.js", "/entry2.js"],
- mode: "passthrough",
+ external: ["*"],
+ mangleProps: /_$/,
});
itBundled("default/ManglePropsMinify", {
// GENERATED
@@ -5437,7 +5523,7 @@ describe("bundler", () => {
entryPoints: ["/entry1.js", "/entry2.js"],
mangleProps: /_$/,
minifyIdentifiers: true,
- mode: "passthrough",
+ external: ["*"],
});
itBundled("default/ManglePropsKeywordPropertyMinify", {
// GENERATED
@@ -5451,7 +5537,7 @@ describe("bundler", () => {
mangleProps: /./,
minifyIdentifiers: true,
minifySyntax: true,
- mode: "passthrough",
+ external: ["*"],
});
itBundled("default/ManglePropsOptionalChain", {
// GENERATED
@@ -5469,7 +5555,8 @@ describe("bundler", () => {
}
`,
},
- mode: "passthrough",
+ mangleProps: /_$/,
+ external: ["*"],
});
itBundled("default/ManglePropsLoweredOptionalChain", {
// GENERATED
@@ -5488,7 +5575,7 @@ describe("bundler", () => {
`,
},
mangleProps: /_$/,
- mode: "passthrough",
+ external: ["*"],
});
itBundled("default/ReserveProps", {
// GENERATED
@@ -5501,7 +5588,7 @@ describe("bundler", () => {
`,
},
mangleProps: /_$/,
- mode: "passthrough",
+ external: ["*"],
});
itBundled("default/ManglePropsImportExport", {
// GENERATED
@@ -5516,7 +5603,8 @@ describe("bundler", () => {
`,
},
entryPoints: ["/esm.js", "/cjs.js"],
- mode: "passthrough",
+ mangleProps: /_$/,
+ external: ["*"],
});
itBundled("default/ManglePropsImportExportBundled", {
// GENERATED
@@ -5545,9 +5633,11 @@ describe("bundler", () => {
"/cjs.js": `exports.cjs_foo_ = 'foo'`,
},
entryPoints: ["/entry-esm.js", "/entry-cjs.js"],
+ mangleProps: /_$/,
});
itBundled("default/ManglePropsJSXTransform", {
// GENERATED
+ notImplemented: true,
files: {
"/entry.jsx": /* jsx */ `
let Foo = {
@@ -5566,10 +5656,10 @@ describe("bundler", () => {
`,
},
mangleProps: /_$/,
- mode: "passthrough",
});
itBundled("default/ManglePropsJSXPreserve", {
// GENERATED
+ notImplemented: true,
files: {
"/entry.jsx": /* jsx */ `
let Foo = {
@@ -5583,10 +5673,10 @@ describe("bundler", () => {
},
outfile: "/out.jsx",
mangleProps: /_$/,
- mode: "passthrough",
});
itBundled("default/ManglePropsJSXTransformNamespace", {
// GENERATED
+ notImplemented: true,
files: {
"/entry.jsx": /* jsx */ `
export default [
@@ -5596,10 +5686,8 @@ describe("bundler", () => {
]
`,
},
- mode: "passthrough",
});
itBundled("default/ManglePropsAvoidCollisions", {
- // GENERATED
files: {
"/entry.js": /* js */ `
export default {
@@ -5611,10 +5699,9 @@ describe("bundler", () => {
}
`,
},
- mode: "passthrough",
+ mangleProps: /_$/,
});
itBundled("default/ManglePropsTypeScriptFeatures", {
- // GENERATED
files: {
"/parameter-properties.ts": /* ts */ `
class Foo {
@@ -5694,10 +5781,9 @@ describe("bundler", () => {
`,
},
entryPoints: ["/parameter-properties.ts", "/namespace-exports.ts", "/enum-values.ts"],
- mode: "passthrough",
+ mangleProps: /_$/,
});
itBundled("default/ManglePropsShorthand", {
- // GENERATED
files: {
"/entry.js": /* js */ `
// This should print as "({ y }) => ({ y })" not "({ y: y }) => ({ y: y })"
@@ -5705,10 +5791,8 @@ describe("bundler", () => {
`,
},
mangleProps: /x/,
- mode: "passthrough",
});
itBundled("default/ManglePropsNoShorthand", {
- // GENERATED
files: {
"/entry.js": /* js */ `
// This should print as "({ y }) => ({ y: y })" not "({ y: y }) => ({ y: y })"
@@ -5717,10 +5801,8 @@ describe("bundler", () => {
},
mangleProps: /x/,
minifyIdentifiers: true,
- mode: "passthrough",
});
itBundled("default/ManglePropsLoweredClassFields", {
- // GENERATED
files: {
"/entry.js": /* js */ `
class Foo {
@@ -5731,10 +5813,9 @@ describe("bundler", () => {
`,
},
mangleProps: /_$/,
- mode: "passthrough",
+ unsupportedJSFeatures: ["class-field", "class-static-field"],
});
itBundled("default/ManglePropsSuperCall", {
- // GENERATED
files: {
"/entry.js": /* js */ `
class Foo {}
@@ -5745,10 +5826,9 @@ describe("bundler", () => {
}
`,
},
- mode: "passthrough",
+ mangleProps: /./,
});
itBundled("default/MangleNoQuotedProps", {
- // GENERATED
files: {
"/entry.js": /* js */ `
x['_doNotMangleThis'];
@@ -5766,7 +5846,7 @@ describe("bundler", () => {
`,
},
mangleProps: /_/,
- mode: "passthrough",
+ mangleQuoted: false,
});
itBundled("default/MangleNoQuotedPropsMinifySyntax", {
// GENERATED
@@ -5788,10 +5868,9 @@ describe("bundler", () => {
},
mangleProps: /_/,
mangleQuoted: false,
- mode: "passthrough",
+ minifySyntax: true,
});
itBundled("default/MangleQuotedProps", {
- // GENERATED
files: {
"/keep.js": /* js */ `
foo("_keepThisProperty");
@@ -5830,10 +5909,9 @@ describe("bundler", () => {
},
entryPoints: ["/keep.js", "/mangle.js"],
mangleProps: /_/,
- mode: "passthrough",
+ mangleQuoted: true,
});
itBundled("default/MangleQuotedPropsMinifySyntax", {
- // GENERATED
files: {
"/keep.js": /* js */ `
foo("_keepThisProperty");
@@ -5873,42 +5951,42 @@ describe("bundler", () => {
entryPoints: ["/keep.js", "/mangle.js"],
mangleProps: /_/,
mangleQuoted: true,
- mode: "passthrough",
- });
- itBundled("default/IndirectRequireMessage", {
- // GENERATED
- files: {
- "/array.js": `let x = [require]`,
- "/assign.js": `require = x`,
- "/ident.js": `let x = require`,
- "/dot.js": `let x = require.cache`,
- "/index.js": `let x = require[cache]`,
- },
- entryPoints: ["/array.js", "/assign.js", "/dot.js", "/ident.js", "/index.js"],
- /* TODO FIX expectedScanLog: `array.js: DEBUG: Indirect calls to "require" will not be bundled
- assign.js: DEBUG: Indirect calls to "require" will not be bundled
- ident.js: DEBUG: Indirect calls to "require" will not be bundled
- `, */
- });
- itBundled("default/AmbiguousReexportMsg", {
- // GENERATED
- files: {
- "/entry.js": /* js */ `
- export * from './a'
- export * from './b'
- export * from './c'
- `,
- "/a.js": `export let a = 1, x = 2`,
- "/b.js": `export let b = 3; export { b as x }`,
- "/c.js": `export let c = 4, x = 5`,
- },
- /* TODO FIX expectedCompileLog: `DEBUG: Re-export of "x" in "entry.js" is ambiguous and has been removed
- a.js: NOTE: One definition of "x" comes from "a.js" here:
- b.js: NOTE: Another definition of "x" comes from "b.js" here:
- `, */
+ minifySyntax: true,
});
+ // we dont check debug messages
+ // itBundled("default/IndirectRequireMessage", {
+ // // GENERATED
+ // files: {
+ // "/array.js": `let x = [require]`,
+ // "/assign.js": `require = x`,
+ // "/ident.js": `let x = require`,
+ // "/dot.js": `let x = require.cache`,
+ // "/index.js": `let x = require[cache]`,
+ // },
+ // entryPoints: ["/array.js", "/assign.js", "/dot.js", "/ident.js", "/index.js"],
+ // /* TODO FIX expectedScanLog: `array.js: DEBUG: Indirect calls to "require" will not be bundled
+ // assign.js: DEBUG: Indirect calls to "require" will not be bundled
+ // ident.js: DEBUG: Indirect calls to "require" will not be bundled
+ // `, */
+ // });
+ // itBundled("default/AmbiguousReexportMsg", {
+ // // GENERATED
+ // files: {
+ // "/entry.js": /* js */ `
+ // export * from './a'
+ // export * from './b'
+ // export * from './c'
+ // `,
+ // "/a.js": `export let a = 1, x = 2`,
+ // "/b.js": `export let b = 3; export { b as x }`,
+ // "/c.js": `export let c = 4, x = 5`,
+ // },
+ // /* TODO FIX expectedCompileLog: `DEBUG: Re-export of "x" in "entry.js" is ambiguous and has been removed
+ // a.js: NOTE: One definition of "x" comes from "a.js" here:
+ // b.js: NOTE: Another definition of "x" comes from "b.js" here:
+ // `, */
+ // });
itBundled("default/NonDeterminismESBuildIssue2537", {
- // GENERATED
files: {
"/entry.ts": /* ts */ `
export function aap(noot: boolean, wim: number) {
@@ -5933,35 +6011,40 @@ describe("bundler", () => {
}
`,
},
+ minifyIdentifiers: true,
});
- itBundled("default/MinifiedJSXPreserveWithObjectSpread", {
- // GENERATED
- files: {
- "/entry.jsx": /* jsx */ `
- const obj = {
- before,
- ...{ [key]: value },
- ...{ key: value },
- after,
- };
- ;
- ;
- `,
- },
- minifySyntax: true,
- });
+ // itBundled("default/MinifiedJSXPreserveWithObjectSpread", {
+ // // GENERATED
+ // files: {
+ // "/entry.jsx": /* jsx */ `
+ // const obj = {
+ // before,
+ // ...{ [key]: value },
+ // ...{ key: value },
+ // after,
+ // };
+ // ;
+ // ;
+ // `,
+ // },
+ // jsx: {
+ // // preserve: true,
+ // },
+ // // minifySyntax: true,
+ // external: ["*"],
+ // });
itBundled("default/PackageAlias", {
files: {
"/entry.js": /* js */ `
@@ -5991,22 +6074,21 @@ describe("bundler", () => {
"/node_modules/prefix-foo/index.js": `console.log(10)`,
"/node_modules/@scope/prefix-foo/index.js": `console.log(11)`,
},
- bundleErrors: {
- "/entry.js": [
- 'Could not resolve: "pkg1". Maybe you need to "bun install"?',
- 'Could not resolve: "pkg2/foo". Maybe you need to "bun install"?',
- 'Could not resolve: "@scope/pkg4". Maybe you need to "bun install"?',
- 'Could not resolve: "@scope/pkg5/foo". Maybe you need to "bun install"?',
- 'Could not resolve: "@abs-path/pkg6". Maybe you need to "bun install"?',
- 'Could not resolve: "@abs-path/pkg6/foo". Maybe you need to "bun install"?',
- 'Could not resolve: "@scope-only/pkg8". Maybe you need to "bun install"?',
- 'Could not resolve: "slash/" Maybe. you need to "bun install"?',
- 'Could not resolve: "pkg3". Maybe you need to "bun install"?',
- ],
+ alias: {
+ "pkg1": "alias1",
+ "pkg2": "alias2",
+ "pkg3": "alias3",
+ "@scope/pkg4": "alias4",
+ "@scope/pkg5": "alias5",
+ "@abs-path/pkg6": `/alias6/dir`,
+ "@abs-path/pkg7": `/alias7/dir`,
+ "@scope-only": "/alias8/dir",
+ "slash": "/alias9/some/file.js",
+ "prefix": "alias10",
+ "@scope/prefix": "alias11",
},
});
itBundled("default/PackageAliasMatchLongest", {
- // GENERATED
files: {
"/entry.js": /* js */ `
import "pkg"
@@ -6023,100 +6105,101 @@ describe("bundler", () => {
"pkg/foo/bar": "alias/pkg_foo_bar",
},
});
- itBundled("default/ErrorsForAssertTypeJSON", {
- // GENERATED
- files: {
- "/js-entry.js": /* js */ `
- import all from './foo.json' assert { type: 'json' }
- import { default as def } from './foo.json' assert { type: 'json' }
- import { unused } from './foo.json' assert { type: 'json' }
- import { used } from './foo.json' assert { type: 'json' }
- import * as ns from './foo.json' assert { type: 'json' }
- use(used, ns.prop)
- export { exported } from './foo.json' assert { type: 'json' }
- import text from './foo.text' assert { type: 'json' }
- import file from './foo.file' assert { type: 'json' }
- import copy from './foo.copy' assert { type: 'json' }
- `,
- "/ts-entry.ts": /* ts */ `
- import all from './foo.json' assert { type: 'json' }
- import { default as def } from './foo.json' assert { type: 'json' }
- import { unused } from './foo.json' assert { type: 'json' }
- import { used } from './foo.json' assert { type: 'json' }
- import * as ns from './foo.json' assert { type: 'json' }
- use(used, ns.prop)
- export { exported } from './foo.json' assert { type: 'json' }
- import text from './foo.text' assert { type: 'json' }
- import file from './foo.file' assert { type: 'json' }
- import copy from './foo.copy' assert { type: 'json' }
- `,
- "/foo.json": `{}`,
- "/foo.text": `{}`,
- "/foo.file": `{}`,
- "/foo.copy": `{}`,
- },
- entryPoints: ["/js-entry.js", "/ts-entry.ts"],
- /* TODO FIX expectedScanLog: `js-entry.js: ERROR: Cannot use non-default import "unused" with a standard JSON module
- js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "unused" import (which is non-standard behavior).
- js-entry.js: ERROR: Cannot use non-default import "used" with a standard JSON module
- js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "used" import (which is non-standard behavior).
- js-entry.js: WARNING: Non-default import "prop" is undefined with a standard JSON module
- js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
- js-entry.js: ERROR: Cannot use non-default import "exported" with a standard JSON module
- js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "exported" import (which is non-standard behavior).
- js-entry.js: ERROR: The file "foo.text" was loaded with the "text" loader
- js-entry.js: NOTE: This import assertion requires the loader to be "json" instead:
- NOTE: You need to either reconfigure esbuild to ensure that the loader for this file is "json" or you need to remove this import assertion.
- js-entry.js: ERROR: The file "foo.file" was loaded with the "file" loader
- js-entry.js: NOTE: This import assertion requires the loader to be "json" instead:
- NOTE: You need to either reconfigure esbuild to ensure that the loader for this file is "json" or you need to remove this import assertion.
- ts-entry.ts: ERROR: Cannot use non-default import "used" with a standard JSON module
- ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "used" import (which is non-standard behavior).
- ts-entry.ts: WARNING: Non-default import "prop" is undefined with a standard JSON module
- ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
- ts-entry.ts: ERROR: Cannot use non-default import "exported" with a standard JSON module
- ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "exported" import (which is non-standard behavior).
- `, */
- });
- itBundled("default/OutputForAssertTypeJSON", {
- // GENERATED
- files: {
- "/js-entry.js": /* js */ `
- import all from './foo.json' assert { type: 'json' }
- import copy from './foo.copy' assert { type: 'json' }
- import { default as def } from './foo.json' assert { type: 'json' }
- import * as ns from './foo.json' assert { type: 'json' }
- use(all, copy, def, ns.prop)
- export { default } from './foo.json' assert { type: 'json' }
- `,
- "/ts-entry.ts": /* ts */ `
- import all from './foo.json' assert { type: 'json' }
- import copy from './foo.copy' assert { type: 'json' }
- import { default as def } from './foo.json' assert { type: 'json' }
- import { unused } from './foo.json' assert { type: 'json' }
- import * as ns from './foo.json' assert { type: 'json' }
- use(all, copy, def, ns.prop)
- export { default } from './foo.json' assert { type: 'json' }
- `,
- "/foo.json": `{}`,
- "/foo.copy": `{}`,
- },
- entryPoints: ["/js-entry.js", "/ts-entry.ts"],
- /* TODO FIX expectedScanLog: `js-entry.js: WARNING: Non-default import "prop" is undefined with a standard JSON module
- js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
- ts-entry.ts: WARNING: Non-default import "prop" is undefined with a standard JSON module
- ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
- NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
- `, */
- });
+ // itBundled("default/ErrorsForAssertTypeJSON", {
+ // notImplemented: true,
+ // files: {
+ // "/js-entry.js": /* js */ `
+ // import all from './foo.json' assert { type: 'json' }
+ // import { default as def } from './foo.json' assert { type: 'json' }
+ // import { unused } from './foo.json' assert { type: 'json' }
+ // import { used } from './foo.json' assert { type: 'json' }
+ // import * as ns from './foo.json' assert { type: 'json' }
+ // use(used, ns.prop)
+ // export { exported } from './foo.json' assert { type: 'json' }
+ // import text from './foo.text' assert { type: 'json' }
+ // import file from './foo.file' assert { type: 'json' }
+ // import copy from './foo.copy' assert { type: 'json' }
+ // `,
+ // "/ts-entry.ts": /* ts */ `
+ // import all from './foo.json' assert { type: 'json' }
+ // import { default as def } from './foo.json' assert { type: 'json' }
+ // import { unused } from './foo.json' assert { type: 'json' }
+ // import { used } from './foo.json' assert { type: 'json' }
+ // import * as ns from './foo.json' assert { type: 'json' }
+ // use(used, ns.prop)
+ // export { exported } from './foo.json' assert { type: 'json' }
+ // import text from './foo.text' assert { type: 'json' }
+ // import file from './foo.file' assert { type: 'json' }
+ // import copy from './foo.copy' assert { type: 'json' }
+ // `,
+ // "/foo.json": `{ "used": 0, "unused": 0, "prop": 0, "exported": 0 }`,
+ // "/foo.text": `{ "used": 0, "unused": 0, "prop": 0, "exported": 0 }`,
+ // "/foo.file": `{ "used": 0, "unused": 0, "prop": 0, "exported": 0 }`,
+ // "/foo.copy": `{ "used": 0, "unused": 0, "prop": 0, "exported": 0 }`,
+ // },
+ // entryPoints: ["/js-entry.js", "/ts-entry.ts"],
+ // /* TODO FIX expectedScanLog: `js-entry.js: ERROR: Cannot use non-default import "unused" with a standard JSON module
+ // js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "unused" import (which is non-standard behavior).
+ // js-entry.js: ERROR: Cannot use non-default import "used" with a standard JSON module
+ // js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "used" import (which is non-standard behavior).
+ // js-entry.js: WARNING: Non-default import "prop" is undefined with a standard JSON module
+ // js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
+ // js-entry.js: ERROR: Cannot use non-default import "exported" with a standard JSON module
+ // js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "exported" import (which is non-standard behavior).
+ // js-entry.js: ERROR: The file "foo.text" was loaded with the "text" loader
+ // js-entry.js: NOTE: This import assertion requires the loader to be "json" instead:
+ // NOTE: You need to either reconfigure esbuild to ensure that the loader for this file is "json" or you need to remove this import assertion.
+ // js-entry.js: ERROR: The file "foo.file" was loaded with the "file" loader
+ // js-entry.js: NOTE: This import assertion requires the loader to be "json" instead:
+ // NOTE: You need to either reconfigure esbuild to ensure that the loader for this file is "json" or you need to remove this import assertion.
+ // ts-entry.ts: ERROR: Cannot use non-default import "used" with a standard JSON module
+ // ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "used" import (which is non-standard behavior).
+ // ts-entry.ts: WARNING: Non-default import "prop" is undefined with a standard JSON module
+ // ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
+ // ts-entry.ts: ERROR: Cannot use non-default import "exported" with a standard JSON module
+ // ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "exported" import (which is non-standard behavior).
+ // `, */
+ // });
+ // itBundled("default/OutputForAssertTypeJSON", {
+ // // GENERATED
+ // files: {
+ // "/js-entry.js": /* js */ `
+ // import all from './foo.json' assert { type: 'json' }
+ // import copy from './foo.copy' assert { type: 'json' }
+ // import { default as def } from './foo.json' assert { type: 'json' }
+ // import * as ns from './foo.json' assert { type: 'json' }
+ // use(all, copy, def, ns.prop)
+ // export { default } from './foo.json' assert { type: 'json' }
+ // `,
+ // "/ts-entry.ts": /* ts */ `
+ // import all from './foo.json' assert { type: 'json' }
+ // import copy from './foo.copy' assert { type: 'json' }
+ // import { default as def } from './foo.json' assert { type: 'json' }
+ // import { unused } from './foo.json' assert { type: 'json' }
+ // import * as ns from './foo.json' assert { type: 'json' }
+ // use(all, copy, def, ns.prop)
+ // export { default } from './foo.json' assert { type: 'json' }
+ // `,
+ // "/foo.json": `{}`,
+ // "/foo.copy": `{}`,
+ // },
+ // entryPoints: ["/js-entry.js", "/ts-entry.ts"],
+ // /* TODO FIX expectedScanLog: `js-entry.js: WARNING: Non-default import "prop" is undefined with a standard JSON module
+ // js-entry.js: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
+ // ts-entry.ts: WARNING: Non-default import "prop" is undefined with a standard JSON module
+ // ts-entry.ts: NOTE: This is considered an import of a standard JSON module because of the import assertion here:
+ // NOTE: You can either keep the import assertion and only use the "default" import, or you can remove the import assertion and use the "prop" import (which is non-standard behavior).
+ // `, */
+ // });
+ return;
itBundled("default/ExternalPackages", {
// GENERATED
files: {
diff --git a/test/bundler/esbuild/lower.test.ts b/test/bundler/esbuild/lower.test.ts
index d03c4a27f6261..df68a6f5187dc 100644
--- a/test/bundler/esbuild/lower.test.ts
+++ b/test/bundler/esbuild/lower.test.ts
@@ -1,4 +1,4 @@
-import { RUN_UNCHECKED_TESTS, itBundled, testForFile } from "../expectBundled";
+import { itBundled, testForFile } from "../expectBundled";
var { describe, test, expect } = testForFile(import.meta.path);
// Tests ported from:
@@ -7,7 +7,7 @@ var { describe, test, expect } = testForFile(import.meta.path);
// For debug, all files are written to $TEMP/bun-bundle-tests/lower
describe("bundler", () => {
- if (!RUN_UNCHECKED_TESTS) return;
+ return;
itBundled("lower/LowerOptionalCatchNameCollisionNoBundle", {
// GENERATED
files: {
diff --git a/test/bundler/esbuild/ts.test.ts b/test/bundler/esbuild/ts.test.ts
index a3b3ce9252ecd..2eb894cfe1ce0 100644
--- a/test/bundler/esbuild/ts.test.ts
+++ b/test/bundler/esbuild/ts.test.ts
@@ -1470,7 +1470,6 @@ describe("bundler", () => {
},
});
itBundled("ts/ThisInsideFunctionTSNoBundleUseDefineForClassFields", {
- // GENERATED
files: {
"/entry.ts": /* ts */ `
function foo(x = this) { return [x, this]; }
diff --git a/test/bundler/expectBundled.ts b/test/bundler/expectBundled.ts
index e625cb5004099..e029787c8e512 100644
--- a/test/bundler/expectBundled.ts
+++ b/test/bundler/expectBundled.ts
@@ -27,7 +27,7 @@ export function testForFile(file: string): BunTestExports {
}
/** Use `esbuild` instead of `bun build` */
-const ESBUILD = process.env.BUN_BUNDLER_TEST_USE_ESBUILD;
+export const ESBUILD = process.env.BUN_BUNDLER_TEST_USE_ESBUILD;
/** Write extra files to disk and log extra info. */
const DEBUG = process.env.BUN_BUNDLER_TEST_DEBUG;
/** Set this to the id of a bundle test to run just that test */
@@ -95,6 +95,7 @@ export interface BundlerTestInput {
fragment?: string;
automaticRuntime?: boolean;
development?: boolean;
+ preserve?: boolean;
};
outbase?: string;
/** Defaults to `/out.js` */
@@ -392,7 +393,7 @@ function expectBundled(
const entryPaths = entryPoints.map(file => path.join(root, file));
if (external) {
- external = external.map(x => x.replace(/\{\{root\}\}/g, root));
+ external = external.map(x => (typeof x !== "string" ? x : x.replace(/\{\{root\}\}/g, root)));
}
outfile = useOutFile ? path.join(root, outfile ?? "/out.js") : undefined;
@@ -404,7 +405,7 @@ function expectBundled(
: entryPaths.map(file => path.join(outdir!, path.basename(file)))
).map(x => x.replace(/\.ts$/, ".js"));
- if (mode === "transform" && !outfile) {
+ if (mode === "transform" && !outfile && !ESBUILD) {
throw new Error("transform mode requires one single outfile");
}
if (cjs2esm && !outfile && !minifySyntax && !minifyWhitespace) {
@@ -475,6 +476,7 @@ function expectBundled(
minifyWhitespace && `--minify-whitespace`,
globalName && `--global-name=${globalName}`,
// inject && inject.map(x => ["--inject", path.join(root, x)]),
+ jsx.preserve && "--jsx=preserve",
jsx.automaticRuntime === false && "--jsx=classic",
jsx.factory && `--jsx-factory=${jsx.factory}`,
jsx.fragment && `--jsx-fragment=${jsx.fragment}`,
@@ -508,6 +510,7 @@ function expectBundled(
inject && inject.map(x => `--inject:${path.join(root, x)}`),
define && Object.entries(define).map(([k, v]) => `--define:${k}=${v}`),
jsx.automaticRuntime && "--jsx=automatic",
+ jsx.preserve && "--jsx=preserve",
jsx.factory && `--jsx-factory=${jsx.factory}`,
jsx.fragment && `--jsx-fragment=${jsx.fragment}`,
jsx.development && `--jsx-dev`,
@@ -579,7 +582,7 @@ function expectBundled(
}
}
- const { stdout, stderr, success } = Bun.spawnSync({
+ const { stdout, stderr, success, exitCode } = Bun.spawnSync({
cmd,
cwd: root,
stdio: ["ignore", "pipe", "pipe"],
@@ -785,6 +788,7 @@ function expectBundled(
writeFileSync(path.join(root, "run.js"), debugFile);
} else {
console.log("TODO: generate run.js, currently only works if options are wrapped in a function");
+ console.log("options:", buildConfig);
}
}