mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:39:35 +00:00
refactor(test): share internal hook and npm pack assertions
This commit is contained in:
@@ -14,3 +14,21 @@ export function expectSingleNpmInstallIgnoreScriptsCall(params: {
|
||||
expect(argv).toEqual(["npm", "install", "--omit=dev", "--silent", "--ignore-scripts"]);
|
||||
expect(opts?.cwd).toBe(params.expectedCwd);
|
||||
}
|
||||
|
||||
export function expectSingleNpmPackIgnoreScriptsCall(params: {
|
||||
calls: Array<[unknown, unknown]>;
|
||||
expectedSpec: string;
|
||||
}) {
|
||||
const packCalls = params.calls.filter(
|
||||
(call) => Array.isArray(call[0]) && call[0][0] === "npm" && call[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", params.expectedSpec, "--ignore-scripts"]);
|
||||
const commandOptions = typeof options === "number" ? undefined : options;
|
||||
expect(commandOptions).toMatchObject({ env: { NPM_CONFIG_IGNORE_SCRIPTS: "true" } });
|
||||
}
|
||||
|
||||
15
src/test-utils/internal-hook-event-payload.ts
Normal file
15
src/test-utils/internal-hook-event-payload.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export function createInternalHookEventPayload(
|
||||
type: string,
|
||||
action: string,
|
||||
sessionKey: string,
|
||||
context: Record<string, unknown>,
|
||||
) {
|
||||
return {
|
||||
type,
|
||||
action,
|
||||
sessionKey,
|
||||
context,
|
||||
timestamp: new Date(),
|
||||
messages: [],
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user