test: micro-optimize hot unit test files

This commit is contained in:
Peter Steinberger
2026-03-02 05:30:25 +00:00
parent 1de3200973
commit 656121a12b
7 changed files with 146 additions and 104 deletions

View File

@@ -1,9 +1,13 @@
import { describe, expect, it, vi } from "vitest";
import { beforeAll, describe, expect, it } from "vitest";
let validateConfigObject: typeof import("./config.js").validateConfigObject;
beforeAll(async () => {
({ validateConfigObject } = await import("./config.js"));
});
describe("meta.lastTouchedAt numeric timestamp coercion", () => {
it("accepts a numeric Unix timestamp and coerces it to an ISO string", async () => {
vi.resetModules();
const { validateConfigObject } = await import("./config.js");
it("accepts a numeric Unix timestamp and coerces it to an ISO string", () => {
const numericTimestamp = 1770394758161;
const res = validateConfigObject({
meta: {
@@ -17,9 +21,7 @@ describe("meta.lastTouchedAt numeric timestamp coercion", () => {
}
});
it("still accepts a string ISO timestamp unchanged", async () => {
vi.resetModules();
const { validateConfigObject } = await import("./config.js");
it("still accepts a string ISO timestamp unchanged", () => {
const isoTimestamp = "2026-02-07T01:39:18.161Z";
const res = validateConfigObject({
meta: {
@@ -32,9 +34,7 @@ describe("meta.lastTouchedAt numeric timestamp coercion", () => {
}
});
it("rejects out-of-range numeric timestamps without throwing", async () => {
vi.resetModules();
const { validateConfigObject } = await import("./config.js");
it("rejects out-of-range numeric timestamps without throwing", () => {
const res = validateConfigObject({
meta: {
lastTouchedAt: 1e20,
@@ -43,9 +43,7 @@ describe("meta.lastTouchedAt numeric timestamp coercion", () => {
expect(res.ok).toBe(false);
});
it("passes non-date strings through unchanged (backwards-compatible)", async () => {
vi.resetModules();
const { validateConfigObject } = await import("./config.js");
it("passes non-date strings through unchanged (backwards-compatible)", () => {
const res = validateConfigObject({
meta: {
lastTouchedAt: "not-a-date",
@@ -57,9 +55,7 @@ describe("meta.lastTouchedAt numeric timestamp coercion", () => {
}
});
it("accepts meta with only lastTouchedVersion (no lastTouchedAt)", async () => {
vi.resetModules();
const { validateConfigObject } = await import("./config.js");
it("accepts meta with only lastTouchedVersion (no lastTouchedAt)", () => {
const res = validateConfigObject({
meta: {
lastTouchedVersion: "2026.2.6",