Skip to main content
Home

latest
It is unknown whether this package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
76%
Published
5 months ago (0.1.18)
import { assertSpyCall, assertSpyCalls, spy } from "jsr:/@std/testing@^1.0.5/mock"; import { TestConfig } from "../config.ts"; import { assertEquals } from "jsr:/@std/assert@^1.0.8/equals"; import { run, type RunParams } from "./run.ts"; import { _ } from "./run.ts"; Deno.test("It should run part 1 if solve is true", async () => { const params = { part1: { solve: true, solver: () => `part1`, tests: [ { input: "input", expected: "part1" }, ], }, part2: { solve: false, solver: () => `part2`, }, day: 1, input: "input", } satisfies RunParams; using runTestsSpy = spy(_, "runTests"); using runSolverSpy = spy(_, "runSolver"); await run(params, new TestConfig()); assertSpyCall(runTestsSpy, 0, { args: [params.part1], returned: ["part1"], }); assertSpyCall(runSolverSpy, 0, { args: [params.part1, params.input], returned: { result: "part1", runtime: 0 }, }); }); Deno.test("It should run part 2 if solve is true", async () => { const params = { part1: { solve: true, solver: () => `part1`, tests: [ { input: "input", expected: "part1" }, ], }, part2: { solve: true, solver: () => `part2`, }, day: 1, input: "input", } satisfies RunParams; using runTestsSpy = spy(_, "runTests"); using runSolverSpy = spy(_, "runSolver"); await run(params, new TestConfig()); assertSpyCall(runTestsSpy, 0, { args: [params.part1], returned: ["part1"], }); assertSpyCalls(runTestsSpy, 1); // part 2 has no tests assertSpyCall(runSolverSpy, 1, { args: [params.part2, params.input], returned: { result: "part2", runtime: 0 }, }); }); Deno.test("It should update config for returning result", async () => { const params = { part1: { solve: true, solver: () => `part1`, tests: [ { input: "input", expected: "part1" }, ], }, part2: { solve: false, solver: () => undefined, }, day: 1, input: "input", } satisfies RunParams; const config = new TestConfig({ year: "2024", days: { "1": { part1: { solved: false, result: "test", tries: 1 }, part2: { solved: false, tries: 0 }, }, }, }); assertEquals(config.getDay(1).part1.tries, 1); using runTestsSpy = spy(_, "runTests"); await run(params, config); assertSpyCall(runTestsSpy, 0, { args: [params.part1], returned: ["part1"], }); assertSpyCalls(runTestsSpy, 1); // part 2 has no tests assertEquals(config.getDay(1), { part1: { solved: false, result: "part1", // not "test" tries: 2, // +1 from existing config runtime: 0, }, part2: { solved: false, tries: 0, // not incremented because we did not call part 2 }, }); }); Deno.test("It should update config (tries) if no result is returned from solver", async () => { const params = { part1: { solve: true, solver: () => `part1`, tests: [ { input: "input", expected: "part1" }, ], }, part2: { solve: true, solver: () => undefined, }, day: 1, input: "input", } satisfies RunParams; const config = new TestConfig({ year: "2024", days: { "1": { part1: { solved: false, result: "test", tries: 1 }, part2: { solved: false, tries: 0 }, }, }, }); assertEquals(config.getDay(1).part1.tries, 1); using runTestsSpy = spy(_, "runTests"); using runSolverSpy = spy(_, "runSolver"); await run(params, config); assertSpyCall(runTestsSpy, 0, { args: [params.part1], returned: ["part1"], }); assertSpyCalls(runTestsSpy, 1); // part 2 has no tests assertSpyCalls(runSolverSpy, 2); assertEquals(config.getDay(1).part1.result, "part1"); assertEquals(config.getDay(1).part2.result, undefined); assertEquals(config.getDay(1).part2.tries, 1); });