refactor(test): share internal hook and npm pack assertions

This commit is contained in:
Peter Steinberger
2026-02-18 16:59:38 +00:00
parent 72a4d83334
commit f05395ae00
6 changed files with 57 additions and 48 deletions

View File

@@ -6,7 +6,10 @@ import JSZip from "jszip";
import * as tar from "tar";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import * as skillScanner from "../security/skill-scanner.js";
import { expectSingleNpmInstallIgnoreScriptsCall } from "../test-utils/exec-assertions.js";
import {
expectSingleNpmInstallIgnoreScriptsCall,
expectSingleNpmPackIgnoreScriptsCall,
} from "../test-utils/exec-assertions.js";
vi.mock("../process/exec.js", () => ({
runCommandWithTimeout: vi.fn(),
@@ -506,18 +509,10 @@ describe("installPluginFromNpmSpec", () => {
});
expect(result.ok).toBe(true);
const packCalls = run.mock.calls.filter(
(c) => Array.isArray(c[0]) && c[0][0] === "npm" && c[0][1] === "pack",
);
expect(packCalls.length).toBe(1);
const packCall = packCalls[0];
if (!packCall) {
throw new Error("expected npm pack call");
}
const [argv, options] = packCall;
expect(argv).toEqual(["npm", "pack", "@openclaw/voice-call@0.0.1", "--ignore-scripts"]);
const commandOptions = typeof options === "number" ? undefined : options;
expect(commandOptions?.env).toMatchObject({ NPM_CONFIG_IGNORE_SCRIPTS: "true" });
expectSingleNpmPackIgnoreScriptsCall({
calls: run.mock.calls,
expectedSpec: "@openclaw/voice-call@0.0.1",
});
expect(packTmpDir).not.toBe("");
expect(fs.existsSync(packTmpDir)).toBe(false);