aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/bundler/__snapshots__/api.test.ts.snap (renamed from test/bundler/__snapshots__/build.test.ts.snap)20
-rw-r--r--test/bundler/api.test.ts (renamed from test/bundler/build.test.ts)49
-rw-r--r--test/bundler/cli.test.ts16
-rw-r--r--test/bundler/fixtures/jsx-warning/index.jsx1
4 files changed, 60 insertions, 26 deletions
diff --git a/test/bundler/__snapshots__/build.test.ts.snap b/test/bundler/__snapshots__/api.test.ts.snap
index e8ed56034..a91436aa3 100644
--- a/test/bundler/__snapshots__/build.test.ts.snap
+++ b/test/bundler/__snapshots__/api.test.ts.snap
@@ -42,7 +42,15 @@ NS.then(({ fn: fn2 }) => {
"
`;
-exports[`Bun.build new Response(BuildArtifact): response text 1`] = `
+exports[`Bun.build BuildArtifact properties: hash 1`] = `"0b00cce4004e6308"`;
+
+exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"0aa19aefb10c4ad2"`;
+
+exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"0b00cce4004e6308"`;
+
+exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`;
+
+exports[`Bun.build Bun.write(BuildArtifact) 1`] = `
"var __create = Object.create;
var __descs = Object.getOwnPropertyDescriptors;
var __defProp = Object.defineProperty;
@@ -84,15 +92,7 @@ NS.then(({ fn: fn2 }) => {
"
`;
-exports[`Bun.build BuildArtifact properties: hash 1`] = `"0b00cce4004e6308"`;
-
-exports[`Bun.build BuildArtifact properties + entry.naming: hash 1`] = `"0aa19aefb10c4ad2"`;
-
-exports[`Bun.build BuildArtifact properties sourcemap: hash index.js 1`] = `"0b00cce4004e6308"`;
-
-exports[`Bun.build BuildArtifact properties sourcemap: hash index.js.map 1`] = `"0000000000000000"`;
-
-exports[`Bun.build Bun.write(BuildArtifact) 1`] = `
+exports[`Bun.build new Response(BuildArtifact) sets content type: response text 1`] = `
"var __create = Object.create;
var __descs = Object.getOwnPropertyDescriptors;
var __defProp = Object.defineProperty;
diff --git a/test/bundler/build.test.ts b/test/bundler/api.test.ts
index 921481a4b..dee37dad5 100644
--- a/test/bundler/build.test.ts
+++ b/test/bundler/api.test.ts
@@ -198,15 +198,20 @@ describe("Bun.build", () => {
Bun.gc(true);
});
- test.skip("new Response(BuildArtifact)", async () => {
+ test("new Response(BuildArtifact) sets content type", async () => {
const x = await Bun.build({
entrypoints: [join(import.meta.dir, "./fixtures/trivial/index.js")],
});
- const response = new Response(x.outputs.values().next().value!);
- expect(await response.text()).toMatchSnapshot("response text");
+ const response = new Response(x.outputs[0]);
expect(response.headers.get("content-type")).toBe("text/javascript;charset=utf-8");
- expect(response.headers.get("content-length")).toBeGreaterThan(1);
- expect(response.headers.get("content-length")).toMatchSnapshot("content-length");
+ expect(await response.text()).toMatchSnapshot("response text");
+ });
+
+ test("new Response(BuildArtifact) sets etag", async () => {
+ const x = await Bun.build({
+ entrypoints: [join(import.meta.dir, "./fixtures/trivial/index.js")],
+ });
+ const response = new Response(x.outputs[0]);
expect(response.headers.get("etag")).toBeTruthy();
expect(response.headers.get("etag")).toMatchSnapshot("content-etag");
});
@@ -234,15 +239,27 @@ describe("Bun.build", () => {
// throw new Error("test was not fully written");
// });
- // test("errors are returned as an array", async () => {
- // const x = await Bun.build({
- // entrypoints: [join(import.meta.dir, "does-not-exist.ts")],
- // });
- // expect(x.errors).toHaveLength(1);
- // expect(x.errors[0].message).toMatch(/ModuleNotFound/);
- // expect(x.errors[0].name).toBe("BuildMessage");
- // expect(x.errors[0].position).toEqual(null);
- // expect(x.warnings).toHaveLength(0);
- // expect(x.logs).toHaveLength(0);
- // });
+ test("errors are returned as an array", async () => {
+ const x = await Bun.build({
+ entrypoints: [join(import.meta.dir, "does-not-exist.ts")],
+ });
+ expect(x.success).toBe(false);
+ expect(x.logs).toHaveLength(1);
+ expect(x.logs[0].message).toMatch(/ModuleNotFound/);
+ expect(x.logs[0].name).toBe("BuildMessage");
+ expect(x.logs[0].position).toEqual(null);
+ });
+
+ test("warnings do not fail a build", async () => {
+ const x = await Bun.build({
+ entrypoints: [join(import.meta.dir, "./fixtures/jsx-warning/index.jsx")],
+ });
+ expect(x.success).toBe(true);
+ expect(x.logs).toHaveLength(1);
+ expect(x.logs[0].message).toBe(
+ '"key" prop before a {...spread} is deprecated in JSX. Falling back to classic runtime.',
+ );
+ expect(x.logs[0].name).toBe("BuildMessage");
+ expect(x.logs[0].position).toBeTruthy();
+ });
});
diff --git a/test/bundler/cli.test.ts b/test/bundler/cli.test.ts
new file mode 100644
index 000000000..e2f99a9ed
--- /dev/null
+++ b/test/bundler/cli.test.ts
@@ -0,0 +1,16 @@
+import { bunEnv, bunExe } from "harness";
+import path from "path";
+import { describe, expect, test } from "bun:test";
+
+describe("bun build", () => {
+ test("warnings dont return exit code 1", () => {
+ const { stderr, exitCode } = Bun.spawnSync({
+ cmd: [bunExe(), "build", path.join(import.meta.dir, "./fixtures/jsx-warning/index.jsx")],
+ env: bunEnv,
+ });
+ expect(exitCode).toBe(0);
+ expect(stderr.toString("utf8")).toContain(
+ 'warn: "key" prop before a {...spread} is deprecated in JSX. Falling back to classic runtime.',
+ );
+ });
+});
diff --git a/test/bundler/fixtures/jsx-warning/index.jsx b/test/bundler/fixtures/jsx-warning/index.jsx
new file mode 100644
index 000000000..22f02712d
--- /dev/null
+++ b/test/bundler/fixtures/jsx-warning/index.jsx
@@ -0,0 +1 @@
+console.log(<div key={"123"} {...props} />);