Files
openclaw/scripts/test-extension.mjs
T

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2026-03-16 01:47:52 -07:00
#!/usr/bin/env node
2026-04-07 04:09:30 +01:00
import { formatErrorMessage } from "./lib/error-format.mjs";
2026-04-03 13:04:31 +01:00
import { resolveExtensionTestPlan } from "./lib/extension-test-plan.mjs";
import { isDirectScriptRun, runVitestBatch } from "./lib/vitest-batch-runner.mjs";
2026-03-16 01:47:52 -07:00
function printUsage() {
console.error("Usage: pnpm test:extension <extension-name|path> [vitest args...]");
console.error(" node scripts/test-extension.mjs [extension-name|path] [vitest args...]");
2026-03-18 17:52:28 -07:00
}
function printNoTestsMessage(plan) {
console.log(`[test-extension] No tests found for ${plan.extensionDir}. Skipping.`);
2026-03-16 01:47:52 -07:00
}
async function run() {
const rawArgs = process.argv.slice(2);
if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
printUsage();
2026-03-16 08:40:06 -07:00
return;
}
const passthroughArgs = rawArgs.filter((arg) => arg !== "--");
2026-03-16 01:47:52 -07:00
let targetArg;
2026-03-16 02:28:45 -07:00
if (passthroughArgs[0] && !passthroughArgs[0].startsWith("-")) {
targetArg = passthroughArgs.shift();
2026-03-16 01:47:52 -07:00
}
let plan;
try {
plan = resolveExtensionTestPlan({ cwd: process.cwd(), targetArg });
} catch (error) {
printUsage();
2026-04-07 04:09:30 +01:00
console.error(formatErrorMessage(error));
2026-03-16 01:47:52 -07:00
process.exit(1);
}
2026-04-03 12:58:46 +01:00
if (!plan.hasTests) {
printNoTestsMessage(plan);
return;
2026-03-18 17:52:28 -07:00
}
console.log(`[test-extension] Running ${plan.testFileCount} test files for ${plan.extensionId}`);
const exitCode = await runVitestBatch({
args: passthroughArgs,
config: plan.config,
env: process.env,
2026-04-03 12:58:46 +01:00
targets: plan.roots,
});
process.exit(exitCode);
2026-03-16 01:47:52 -07:00
}
if (isDirectScriptRun(import.meta.url)) {
2026-03-16 01:47:52 -07:00
await run();
}