mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
101 lines
2.8 KiB
TypeScript
101 lines
2.8 KiB
TypeScript
// Bundle tests are tests concerning bundling bugs that only occur in DevServer.
|
|
import { devTest, emptyHtmlFile, 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("/").equals("Hello, 123!");
|
|
await dev.write("db.ts", `export const abc = "456";`);
|
|
await dev.fetch("/").equals("Hello, 456!");
|
|
await dev.patch("routes/index.ts", {
|
|
find: "Hello",
|
|
replace: "Bun",
|
|
});
|
|
await dev.fetch("/").equals("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("/").equals("Hello, 123, 987!");
|
|
await dev.write("db.ts", `export const abc = "456";`);
|
|
await dev.fetch("/").equals("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("/").equals("Environment: development");
|
|
},
|
|
});
|
|
devTest("importing a file before it is created", {
|
|
files: {
|
|
"index.html": emptyHtmlFile({
|
|
styles: [],
|
|
scripts: ["index.ts"],
|
|
}),
|
|
"index.ts": `
|
|
import { abc } from './second';
|
|
console.log('value: ' + abc);
|
|
`,
|
|
},
|
|
async test(dev) {
|
|
const c = await dev.client("/", {
|
|
errors: [`index.ts:1:21: error: Could not resolve: "./second"`],
|
|
});
|
|
|
|
await c.expectReload(async () => {
|
|
await dev.write("second.ts", `export const abc = "456";`);
|
|
});
|
|
|
|
await c.expectMessage("value: 456");
|
|
},
|
|
});
|