From a1bb79f4403bbff0ae8a25acffcf079ce6d40f3b Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Tue, 13 Jun 2023 22:28:31 -0700 Subject: [PATCH] `mock` type changes (#3305) * Update mock types and set bun-types@latest in bun init * Remove mockfn methods from toplevel mock * Remove comments --- packages/bun-types/bun-test.d.ts | 34 +----------------------- packages/bun-types/tests/mocks.test-d.ts | 16 ++++++++++- src/cli/init_command.zig | 8 +----- 3 files changed, 17 insertions(+), 41 deletions(-) diff --git a/packages/bun-types/bun-test.d.ts b/packages/bun-types/bun-test.d.ts index bf89b808df..d6bc062c0c 100644 --- a/packages/bun-types/bun-test.d.ts +++ b/packages/bun-types/bun-test.d.ts @@ -27,43 +27,11 @@ declare module "bun:test" { export const mock: { (Function: T): Mock; - - mockClear(): typeof mock; - mockReset(): typeof mock; - mockRestore(): void; - mockReturnValue( - value: ReturnType, - ): JestMock.MockInstance; - mockReturnValueOnce< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: ReturnType, - ): JestMock.MockInstance; - mockResolvedValue< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.ResolveType, - ): JestMock.MockInstance; - mockResolvedValueOnce< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.ResolveType, - ): JestMock.MockInstance; - mockRejectedValue< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.RejectType, - ): JestMock.MockInstance; - mockRejectedValueOnce< - T extends JestMock.FunctionLike = JestMock.UnknownFunction, - >( - value: JestMock.RejectType, - ): JestMock.MockInstance; }; interface Jest { restoreAllMocks(): void; - fn(func: T): Mock; + fn(func?: T): Mock; } export const jest: Jest; export namespace jest { diff --git a/packages/bun-types/tests/mocks.test-d.ts b/packages/bun-types/tests/mocks.test-d.ts index f4fe47d4fe..9bb8a90703 100644 --- a/packages/bun-types/tests/mocks.test-d.ts +++ b/packages/bun-types/tests/mocks.test-d.ts @@ -14,4 +14,18 @@ declare var arg2: arg2; arg2.mock.calls[0]; mock; -type _arg3 = jest.Mock<() => number>; +// @ts-expect-error +jest.fn<() => Promise>().mockReturnValue("asdf"); +// @ts-expect-error +jest.fn<() => string>().mockReturnValue(24); +jest.fn<() => string>().mockReturnValue("24"); + +jest.fn<() => Promise>().mockResolvedValue("asdf"); +// @ts-expect-error +jest.fn<() => string>().mockResolvedValue(24); +// @ts-expect-error +jest.fn<() => string>().mockResolvedValue("24"); + +jest.fn().mockClear(); +jest.fn().mockReset(); +jest.fn().mockRejectedValueOnce(new Error()); diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index bc8867368d..c7f5668360 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -300,13 +300,7 @@ pub const InitCommand = struct { if (needs_dev_dependencies) { var dev_dependencies = fields.object.get("devDependencies") orelse js_ast.Expr.init(js_ast.E.Object, js_ast.E.Object{}, logger.Loc.Empty); - const version = comptime brk: { - var base = Global.version; - base.patch = 0; - break :brk base; - }; - - try dev_dependencies.data.e_object.putString(alloc, "bun-types", comptime std.fmt.comptimePrint("^{any}", .{version.fmt("")})); + try dev_dependencies.data.e_object.putString(alloc, "bun-types", "latest"); try fields.object.put(alloc, "devDependencies", dev_dependencies); }