mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
Co-authored-by: paperdave <paperdave@users.noreply.github.com> Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
78 lines
2.2 KiB
TypeScript
78 lines
2.2 KiB
TypeScript
// Bundle tests are tests concerning bundling bugs that only occur in DevServer.
|
|
import { devTest, minimalFramework } from "../dev-server-harness";
|
|
|
|
devTest("import identifier doesnt get renamed", {
|
|
framework: minimalFramework,
|
|
files: {
|
|
"db.ts": `export const abc = "123";`,
|
|
"routes/index.ts": `
|
|
import { abc } from '../db';
|
|
export default function (req, meta) {
|
|
let v1 = "";
|
|
const v2 = v1
|
|
? abc.toFixed(2)
|
|
: abc.toString();
|
|
return new Response('Hello, ' + v2 + '!');
|
|
}
|
|
`,
|
|
},
|
|
async test(dev) {
|
|
await dev.fetch("/").expect("Hello, 123!");
|
|
await dev.write("db.ts", `export const abc = "456";`);
|
|
await dev.fetch("/").expect("Hello, 456!");
|
|
await dev.patch("routes/index.ts", {
|
|
find: "Hello",
|
|
replace: "Bun",
|
|
});
|
|
await dev.fetch("/").expect("Bun, 456!");
|
|
},
|
|
});
|
|
devTest("symbol collision with import identifier", {
|
|
framework: minimalFramework,
|
|
files: {
|
|
"db.ts": `export const abc = "123";`,
|
|
"routes/index.ts": `
|
|
let import_db = 987;
|
|
import { abc } from '../db';
|
|
export default function (req, meta) {
|
|
let v1 = "";
|
|
const v2 = v1
|
|
? abc.toFixed(2)
|
|
: abc.toString();
|
|
return new Response('Hello, ' + v2 + ', ' + import_db + '!');
|
|
}
|
|
`,
|
|
},
|
|
async test(dev) {
|
|
await dev.fetch("/").expect("Hello, 123, 987!");
|
|
await dev.write("db.ts", `export const abc = "456";`);
|
|
await dev.fetch("/").expect("Hello, 456, 987!");
|
|
},
|
|
});
|
|
devTest("uses \"development\" condition", {
|
|
framework: minimalFramework,
|
|
files: {
|
|
"node_modules/example/package.json": JSON.stringify({
|
|
name: "example",
|
|
version: "1.0.0",
|
|
exports: {
|
|
".": {
|
|
development: "./development.js",
|
|
default: "./production.js",
|
|
},
|
|
},
|
|
}),
|
|
"node_modules/example/development.js": `export default "development";`,
|
|
"node_modules/example/production.js": `export default "production";`,
|
|
"routes/index.ts": `
|
|
import environment from 'example';
|
|
export default function (req, meta) {
|
|
return new Response('Environment: ' + environment);
|
|
}
|
|
`,
|
|
},
|
|
async test(dev) {
|
|
await dev.fetch("/").expect("Environment: development");
|
|
},
|
|
});
|