mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-01 02:51:45 +00:00
test: micro-optimize hot unit test files
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user