UNPKG

create-lite-jest-runner

Version:
66 lines 3.06 kB
import { jest } from "@jest/globals"; describe("Create Lite Jest Runner", () => { it("exports as expected", async () => { const module_ = await import("./index"); expect(module_).toMatchSnapshot(); }); describe("runner creation function", () => { it("creates a valid runner class when executed", async () => { const { default: create } = await import("./index"); const runner = create(jest.fn()); expect(runner).toMatchSnapshot(); const instance = new runner({}); expect(instance).toMatchSnapshot(); expect(instance.runTests).toMatchSnapshot(); }); }); describe("runner class", () => { it("calls the onStart function and later onSuccess function when the runner function resolves", async () => { const { default: create } = await import("./index"); const runnerFunction = jest.fn(() => Promise.resolve()); const runnerClass = create(runnerFunction); const runnerInstance = new runnerClass({ maxWorkers: 1 }); const onStart = jest.fn(); const onSuccess = jest.fn(); const onFailure = jest.fn(); await runnerInstance.runTests([ { context: {}, path: "/test.js", }, ], undefined, onStart, onSuccess, onFailure); expect(runnerFunction.mock).toMatchSnapshot(); expect(runnerFunction).toBeCalledTimes(1); expect(onStart.mock).toMatchSnapshot(); expect(onStart).toBeCalledTimes(1); expect(onSuccess.mock).toMatchSnapshot(); expect(onSuccess).toBeCalledTimes(1); expect(onFailure.mock).toMatchSnapshot(); expect(onFailure).toBeCalledTimes(0); }); it("calls the onStart function and later onFailure function when the runner function rejects", async () => { const { default: create } = await import("./index"); const runnerFunction = jest.fn(() => Promise.reject("Test Throw")); const runnerClass = create(runnerFunction); const runnerInstance = new runnerClass({ maxWorkers: 1 }); const onStart = jest.fn(); const onSuccess = jest.fn(); const onFailure = jest.fn(); await runnerInstance.runTests([ { context: {}, path: "/test.js", }, ], undefined, onStart, onSuccess, onFailure); expect(runnerFunction.mock).toMatchSnapshot(); expect(runnerFunction).toBeCalledTimes(1); expect(onStart.mock).toMatchSnapshot(); expect(onStart).toBeCalledTimes(1); expect(onSuccess.mock).toMatchSnapshot(); expect(onSuccess).toBeCalledTimes(0); expect(onFailure.mock).toMatchSnapshot(); expect(onFailure).toBeCalledTimes(1); }); }); }); //# sourceMappingURL=index.test.js.map