mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 16:34:45 +00:00
fix(test): avoid walking unit-fast candidate roots
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { createCommandsLightVitestConfig } from "./vitest/vitest.commands-light.config.ts";
|
||||
import { createPluginSdkLightVitestConfig } from "./vitest/vitest.plugin-sdk-light.config.ts";
|
||||
@@ -49,6 +50,31 @@ function collectUnroutedForcedFiles(
|
||||
}
|
||||
|
||||
describe("unit-fast vitest lane", () => {
|
||||
it("loads the config without recursively walking repo roots", () => {
|
||||
const script = `
|
||||
import fs from "node:fs";
|
||||
let readdirSyncCalls = 0;
|
||||
const originalReaddirSync = fs.readdirSync;
|
||||
fs.readdirSync = function patchedReaddirSync(...args) {
|
||||
readdirSyncCalls += 1;
|
||||
return originalReaddirSync.apply(this, args);
|
||||
};
|
||||
await import("./test/vitest/vitest.unit-fast.config.ts?io-probe=" + Date.now());
|
||||
console.log(readdirSyncCalls);
|
||||
`;
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
["--import", "tsx", "--input-type=module", "-e", script],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
encoding: "utf8",
|
||||
},
|
||||
);
|
||||
|
||||
expect(result.status, result.stderr).toBe(0);
|
||||
expect(Number(result.stdout.trim())).toBeLessThan(20);
|
||||
});
|
||||
|
||||
it("runs cache-friendly tests without the reset-heavy runner or runtime setup", () => {
|
||||
const config = createUnitFastVitestConfig({});
|
||||
const testConfig = requireTestConfig(config);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import {
|
||||
@@ -309,15 +310,32 @@ function walkFiles(directory, files = []) {
|
||||
|
||||
const walkedTestFilesByCwd = new Map();
|
||||
|
||||
function collectRepoTestFilesFromGit(cwd) {
|
||||
const result = spawnSync("git", ["ls-files", "--", "src", "packages", "test"], {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
return null;
|
||||
}
|
||||
return result.stdout
|
||||
.split("\n")
|
||||
.map((file) => normalizeRepoPath(file.trim()))
|
||||
.filter((file) => file.endsWith(".test.ts"));
|
||||
}
|
||||
|
||||
function collectRepoTestFiles(cwd) {
|
||||
const normalizedCwd = normalizeRepoPath(cwd);
|
||||
const cached = walkedTestFilesByCwd.get(normalizedCwd);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
const files = ["src", "packages", "test"]
|
||||
.flatMap((directory) => walkFiles(path.join(cwd, directory)))
|
||||
.map((file) => normalizeRepoPath(path.relative(cwd, file)));
|
||||
const files =
|
||||
collectRepoTestFilesFromGit(cwd) ??
|
||||
["src", "packages", "test"]
|
||||
.flatMap((directory) => walkFiles(path.join(cwd, directory)))
|
||||
.map((file) => normalizeRepoPath(path.relative(cwd, file)));
|
||||
walkedTestFilesByCwd.set(normalizedCwd, files);
|
||||
return files;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user