test: speed up browser pw-tools-core suites

This commit is contained in:
Peter Steinberger
2026-03-24 20:37:25 +00:00
parent caa718a554
commit e2acfcf527
4 changed files with 15 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, describe, expect, it, vi } from "vitest";
import {
installPwToolsCoreTestHooks,
setPwToolsCoreCurrentPage,
@@ -9,7 +9,7 @@ installPwToolsCoreTestHooks();
let mod: typeof import("./pw-tools-core.js");
describe("pw-tools-core", () => {
beforeEach(async () => {
beforeAll(async () => {
vi.resetModules();
mod = await import("./pw-tools-core.js");
});

View File

@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
let page: { evaluate: ReturnType<typeof vi.fn> } | null = null;
@@ -34,9 +34,12 @@ vi.mock("./pw-tools-core.snapshot.js", () => ({
let batchViaPlaywright: typeof import("./pw-tools-core.interactions.js").batchViaPlaywright;
describe("batchViaPlaywright", () => {
beforeEach(async () => {
beforeAll(async () => {
vi.resetModules();
({ batchViaPlaywright } = await import("./pw-tools-core.interactions.js"));
});
beforeEach(() => {
vi.clearAllMocks();
page = {
evaluate: vi.fn(async () => "ok"),

View File

@@ -1,7 +1,7 @@
import crypto from "node:crypto";
import fs from "node:fs/promises";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, describe, expect, it, vi } from "vitest";
import { DEFAULT_UPLOAD_DIR } from "./paths.js";
import {
installPwToolsCoreTestHooks,
@@ -12,7 +12,7 @@ installPwToolsCoreTestHooks();
let mod: typeof import("./pw-tools-core.js");
describe("pw-tools-core", () => {
beforeEach(async () => {
beforeAll(async () => {
vi.resetModules();
mod = await import("./pw-tools-core.js");
});

View File

@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import {
getPwToolsCoreSessionMocks,
installPwToolsCoreTestHooks,
@@ -18,13 +18,16 @@ vi.mock("../infra/tmp-openclaw-dir.js", () => tmpDirMocks);
let mod: typeof import("./pw-tools-core.js");
describe("pw-tools-core", () => {
beforeEach(async () => {
beforeAll(async () => {
vi.resetModules();
mod = await import("./pw-tools-core.js");
});
beforeEach(() => {
for (const fn of Object.values(tmpDirMocks)) {
fn.mockClear();
}
tmpDirMocks.resolvePreferredOpenClawTmpDir.mockReturnValue("/tmp/openclaw");
mod = await import("./pw-tools-core.js");
});
async function withTempDir<T>(run: (tempDir: string) => Promise<T>): Promise<T> {