mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* `zig fmt` * Fixes #6879 * Update bun-test.d.ts * More tests * Bump WebKit * [autofix.ci] apply automated fixes * woops --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0091 NEW)
|
||||
cmake_policy(SET CMP0067 NEW)
|
||||
|
||||
set(Bun_VERSION "1.0.11")
|
||||
set(WEBKIT_TAG 16badcb5df6b1190051b4b3caa1a5aeb4e2fc441)
|
||||
set(WEBKIT_TAG 63d0e18c06399180e9b3fb63d2b9132af5e79ed4)
|
||||
|
||||
set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}")
|
||||
|
||||
4
packages/bun-types/bun-test.d.ts
vendored
4
packages/bun-types/bun-test.d.ts
vendored
@@ -59,6 +59,10 @@ declare module "bun:test" {
|
||||
* added to existing import statements. This is due to how ESM works.
|
||||
*/
|
||||
module(id: string, factory: () => any): void | Promise<void>;
|
||||
/**
|
||||
* Restore the previous value of mocks.
|
||||
*/
|
||||
restore(): void;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Submodule src/bun.js/WebKit updated: 7cd84abfa7...63d0e18c06
10
test/js/bun/test/mock/6874/A.test.ts
Normal file
10
test/js/bun/test/mock/6874/A.test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { expect, it, mock, describe } from "bun:test";
|
||||
import { a } from "./A.ts";
|
||||
|
||||
mock.module(require.resolve("lodash"), () => ({ trim: () => "mocked" }));
|
||||
|
||||
describe("A", () => {
|
||||
it("should be mocked", () => {
|
||||
expect(a()).toEqual("mocked");
|
||||
});
|
||||
});
|
||||
2
test/js/bun/test/mock/6874/A.ts
Normal file
2
test/js/bun/test/mock/6874/A.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import { trim } from "lodash";
|
||||
export const a = () => trim(" XXX ");
|
||||
10
test/js/bun/test/mock/6874/B.test.ts
Normal file
10
test/js/bun/test/mock/6874/B.test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { expect, it, mock, describe } from "bun:test";
|
||||
import { b } from "./B.ts";
|
||||
|
||||
mock.module(require.resolve("lodash"), () => ({ trim: () => "mocked" }));
|
||||
|
||||
describe("B", () => {
|
||||
it("should be mocked", () => {
|
||||
expect(b()).toEqual("mocked");
|
||||
});
|
||||
});
|
||||
2
test/js/bun/test/mock/6874/B.ts
Normal file
2
test/js/bun/test/mock/6874/B.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import { trim } from "lodash";
|
||||
export const b = () => trim(" XXX ");
|
||||
15
test/js/bun/test/mock/6879/6879.test.ts
Normal file
15
test/js/bun/test/mock/6879/6879.test.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { expect, mock, test } from "bun:test";
|
||||
import { foo } from "./second";
|
||||
import { bar } from "./third";
|
||||
|
||||
test("mocks re-export from export list", () => {
|
||||
expect(foo).toBe("hello");
|
||||
mock.module("./second.ts", () => ({ foo: "world" }));
|
||||
expect(foo).toBe("world"); // success
|
||||
});
|
||||
|
||||
test("mocks named re-export", () => {
|
||||
expect(bar).toBe("hello");
|
||||
mock.module("./third.ts", () => ({ bar: "world" }));
|
||||
expect(bar).toBe("world"); // success
|
||||
});
|
||||
1
test/js/bun/test/mock/6879/first.ts
Normal file
1
test/js/bun/test/mock/6879/first.ts
Normal file
@@ -0,0 +1 @@
|
||||
export default "hello";
|
||||
3
test/js/bun/test/mock/6879/second.ts
Normal file
3
test/js/bun/test/mock/6879/second.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import foo from "./first";
|
||||
|
||||
export { foo };
|
||||
3
test/js/bun/test/mock/6879/third.ts
Normal file
3
test/js/bun/test/mock/6879/third.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import hello from "./first";
|
||||
|
||||
export const bar = hello;
|
||||
7
test/js/bun/test/mock/mock-module-fixture.ts
generated
7
test/js/bun/test/mock/mock-module-fixture.ts
generated
@@ -1,3 +1,5 @@
|
||||
import { rexported } from "./re-export-fixture";
|
||||
|
||||
export function fn() {
|
||||
return 42;
|
||||
}
|
||||
@@ -7,3 +9,8 @@ export function iCallFn() {
|
||||
}
|
||||
|
||||
export const variable = 7;
|
||||
|
||||
export default "original";
|
||||
export { rexported };
|
||||
|
||||
export { rexported as rexportedAs } from "./re-export-fixture";
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// - Write test for import {foo} from "./foo"; export {foo}
|
||||
|
||||
import { expect, mock, spyOn, test } from "bun:test";
|
||||
import { fn, iCallFn, variable } from "./mock-module-fixture";
|
||||
import { fn, iCallFn, variable, default as defaultValue, rexported, rexportedAs } from "./mock-module-fixture";
|
||||
import * as spyFixture from "./spymodule-fixture";
|
||||
|
||||
test("mock.restore", () => {
|
||||
@@ -17,6 +17,7 @@ test("mock.restore", () => {
|
||||
const mocked = spyFixture.iSpy;
|
||||
expect(spyFixture.iSpy).not.toBe(original);
|
||||
expect(spyFixture.iSpy).not.toHaveBeenCalled();
|
||||
// @ts-expect-error
|
||||
spyFixture.iSpy();
|
||||
mock.restore();
|
||||
expect(spyFixture.iSpy).toBe(original);
|
||||
@@ -32,15 +33,24 @@ test("spyOn", () => {
|
||||
test("mocking a local file", async () => {
|
||||
expect(fn()).toEqual(42);
|
||||
expect(variable).toEqual(7);
|
||||
expect(defaultValue).toEqual("original");
|
||||
expect(rexported).toEqual(42);
|
||||
|
||||
mock.module("./mock-module-fixture.ts", () => {
|
||||
return {
|
||||
fn: () => 1,
|
||||
variable: 8,
|
||||
default: 42,
|
||||
rexported: 43,
|
||||
};
|
||||
});
|
||||
expect(fn()).toEqual(1);
|
||||
expect(variable).toEqual(8);
|
||||
// @ts-expect-error
|
||||
// expect(defaultValue).toEqual(42);
|
||||
expect(rexported).toEqual(43);
|
||||
expect(rexportedAs).toEqual(43);
|
||||
expect((await import("./re-export-fixture")).rexported).toEqual(43);
|
||||
mock.module("./mock-module-fixture.ts", () => {
|
||||
return {
|
||||
fn: () => 2,
|
||||
@@ -62,6 +72,15 @@ test("mocking a local file", async () => {
|
||||
expect(iCallFn()).toBe(3);
|
||||
});
|
||||
|
||||
test.todo("adding a default on a module with no default", async () => {
|
||||
mock.module("./re-export-fixture.ts", () => {
|
||||
return {
|
||||
default: 42,
|
||||
};
|
||||
});
|
||||
expect((await import("./re-export-fixture")).default).toBe(42);
|
||||
});
|
||||
|
||||
test("mocking a package", async () => {
|
||||
mock.module("ha-ha-ha", () => {
|
||||
return {
|
||||
|
||||
1
test/js/bun/test/mock/re-export-fixture.ts
generated
Normal file
1
test/js/bun/test/mock/re-export-fixture.ts
generated
Normal file
@@ -0,0 +1 @@
|
||||
export const rexported = 42;
|
||||
Reference in New Issue
Block a user