diff --git a/package.json b/package.json index af38c2be..ff3428a6 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "/tests/", "node_modules/", "coverage/", - "", + "dist/", "package-lock.json" ], "overrides": [ diff --git a/src/logger.ts b/src/logger.ts index 526f0da4..563a451d 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -14,7 +14,7 @@ import { isDebugEnabled } from "./utils"; -// source: https://github.com/csquared/node-logfmt/blob/master/lib/stringify +// source: https://github.com/csquared/node-logfmt/blob/master/lib/stringify.js function fmtData(data: any): string { var line = ""; diff --git a/tests/awaitResult.spec.ts b/tests/awaitResult.test.ts similarity index 92% rename from tests/awaitResult.spec.ts rename to tests/awaitResult.test.ts index 4b36c095..d9720d86 100644 --- a/tests/awaitResult.spec.ts +++ b/tests/awaitResult.test.ts @@ -1,9 +1,9 @@ import { awaitResult, defer } from "../src"; -import { DeferError } from "../src/errors"; -import { makeHTTPClient } from "../src/httpClient"; +import { DeferError } from "../src/backend"; +import { makeHTTPClient } from "../src/backend/remote/httpClient"; import { jitter } from "../src/jitter"; -jest.mock("../src/httpClient"); +jest.mock("../src/backend/remote/httpClient"); jest.mock("../src/jitter"); jest.setTimeout(20000); @@ -57,7 +57,7 @@ describe("awaitResult(deferFn)", () => { const awaitable = awaitResult(deferred); const result = await awaitable(""); - expect(result).toEqual("coucou"); + expect(result).toEqual("Hello World!"); expect(myFunction).not.toHaveBeenCalled(); }); }); diff --git a/tests/next/asNextRoute.spec.ts b/tests/next/asNextRoute.test.ts similarity index 91% rename from tests/next/asNextRoute.spec.ts rename to tests/next/asNextRoute.test.ts index 2e72152c..e15a03fa 100644 --- a/tests/next/asNextRoute.spec.ts +++ b/tests/next/asNextRoute.test.ts @@ -3,7 +3,7 @@ import helloWorld from "./fixtures/helloWorld"; import { POST, GET } from "./fixtures/route"; import { POST as POSTWithProxy } from "./fixtures/routeWithProxy"; import { getExecution } from "../../src/index"; -import { APIError } from "../../src/errors"; +import { ExecutionNotFound } from "../../src/backend"; jest.mock("./fixtures/helloWorld"); jest.mock("../../src/index", () => { @@ -19,7 +19,7 @@ describe("asNextRoute()", () => { describe("POST() - background function invocation", () => { describe("valid empty params, without proxy", () => { beforeEach(() => - jest.mocked(helloWorld).mockResolvedValue({ id: "test-id" }) + jest.mocked(helloWorld).mockResolvedValue({ id: "test-id" } as any) ); test("properly call the background function and forward the execution ID", async () => { @@ -36,13 +36,13 @@ describe("asNextRoute()", () => { expect(helloWorld).toHaveBeenCalledWith(); expect(res.status).toBe(200); - expect(await reson()).toEqual({ id: "test-id" }); + expect(await res.json()).toEqual({ id: "test-id" }); }); }); describe("valid params, without proxy", () => { beforeEach(() => - jest.mocked(helloWorld).mockResolvedValue({ id: "test-id" }) + jest.mocked(helloWorld).mockResolvedValue({ id: "test-id" } as any) ); afterEach(() => { jest.mocked(helloWorld).mockReset(); @@ -62,13 +62,13 @@ describe("asNextRoute()", () => { expect(helloWorld).toHaveBeenCalledWith("charly"); expect(res.status).toBe(200); - expect(await reson()).toEqual({ id: "test-id" }); + expect(await res.json()).toEqual({ id: "test-id" }); }); }); describe("valid params, with proxy", () => { beforeEach(() => - jest.mocked(helloWorld).mockResolvedValue({ id: "test-id" }) + jest.mocked(helloWorld).mockResolvedValue({ id: "test-id" } as any) ); test("properly call the background function with params and forward the execution ID", async () => { @@ -85,7 +85,7 @@ describe("asNextRoute()", () => { expect(helloWorld).toHaveBeenCalledWith("prefix-charly"); expect(res.status).toBe(200); - expect(await reson()).toEqual({ id: "test-id" }); + expect(await res.json()).toEqual({ id: "test-id" }); }); }); }); @@ -104,7 +104,7 @@ describe("asNextRoute()", () => { "valid query params, invalid execution ID", "?id=not-found-id", "not-found-id", - new APIError("execution not found", ""), + new ExecutionNotFound("execution not found"), [500, { error: "Error: execution not found", id: "not-found-id" }], ], [ @@ -129,8 +129,7 @@ describe("asNextRoute()", () => { throw executionResult; }); } else { - // @ts-expect-error unflexible TS \o/ - jest.mocked(getExecution).mockResolvedValue(executionResult); + jest.mocked(getExecution).mockResolvedValue(executionResult as any); } }); afterEach(() => { @@ -152,7 +151,7 @@ describe("asNextRoute()", () => { } expect(res.status).toBe(expectedResponseStatus); - expect(await reson()).toEqual(expectedResponseBody); + expect(await res.json()).toEqual(expectedResponseBody); }); } ); diff --git a/tests/next/fixtures/routeWithProxy.ts b/tests/next/fixtures/routeWithProxy.ts index f3e12a49..ea0bf2c5 100644 --- a/tests/next/fixtures/routeWithProxy.ts +++ b/tests/next/fixtures/routeWithProxy.ts @@ -4,7 +4,7 @@ import helloWorld from "./helloWorld"; const { GetHandler, PostHandler } = asNextRoute(helloWorld, { // @ts-expect-error too strict return type async proxy(request) { - const args = await requeston(); + const args = await request.json(); return [`prefix-${args[0]}`]; }, }); diff --git a/tests/next/useDeferRoute.spec.ts b/tests/next/useDeferRoute.test.ts similarity index 100% rename from tests/next/useDeferRoute.spec.ts rename to tests/next/useDeferRoute.test.ts diff --git a/tsconfig.build.json b/tsconfig.build.json index ce570190..d01964e6 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,10 +1,9 @@ { - "extends": "./tsconfig.json", - "exclude": [ - "src/**/*.spec.ts", - "src/**/*.test.ts", - "src/test/**/*", - "scripts/**/*" - ] - } - \ No newline at end of file + "extends": "./tsconfig.json", + "exclude": [ + "src/**/*.spec.ts", + "src/**/*.test.ts", + "src/test/**/*", + "scripts/**/*" + ] +} \ No newline at end of file