mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:30:43 +00:00
test: share plugin install archive fixtures
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import * as tar from "tar";
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { expectSingleNpmPackIgnoreScriptsCall } from "../test-utils/exec-assertions.js";
|
||||
import {
|
||||
@@ -8,6 +7,7 @@ import {
|
||||
mockNpmPackMetadataResult,
|
||||
} from "../test-utils/npm-spec-install-test-helpers.js";
|
||||
import { installPluginFromNpmSpec, PLUGIN_INSTALL_ERROR_CODE } from "./install.js";
|
||||
import { packToArchive } from "./test-helpers/archive-fixtures.js";
|
||||
import { createSuiteTempRootTracker } from "./test-helpers/fs-fixtures.js";
|
||||
|
||||
const runCommandWithTimeoutMock = vi.fn();
|
||||
@@ -24,26 +24,6 @@ function readVoiceCallArchiveBuffer(version: string): Buffer {
|
||||
return fs.readFileSync(path.join(pluginFixturesDir, `voice-call-${version}.tgz`));
|
||||
}
|
||||
|
||||
async function packToArchive(params: {
|
||||
pkgDir: string;
|
||||
outDir: string;
|
||||
outName: string;
|
||||
flatRoot?: boolean;
|
||||
}) {
|
||||
const dest = path.join(params.outDir, params.outName);
|
||||
fs.rmSync(dest, { force: true });
|
||||
const entries = params.flatRoot ? fs.readdirSync(params.pkgDir) : [path.basename(params.pkgDir)];
|
||||
await tar.c(
|
||||
{
|
||||
gzip: true,
|
||||
file: dest,
|
||||
cwd: params.flatRoot ? params.pkgDir : path.dirname(params.pkgDir),
|
||||
},
|
||||
entries,
|
||||
);
|
||||
return dest;
|
||||
}
|
||||
|
||||
function buildDynamicArchiveTemplateKey(params: {
|
||||
packageJson: Record<string, unknown>;
|
||||
withDistIndex: boolean;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import * as tar from "tar";
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import { expectSingleNpmInstallIgnoreScriptsCall } from "../test-utils/exec-assertions.js";
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
installPluginFromPath,
|
||||
PLUGIN_INSTALL_ERROR_CODE,
|
||||
} from "./install.js";
|
||||
import { packToArchive } from "./test-helpers/archive-fixtures.js";
|
||||
import { createSuiteTempRootTracker } from "./test-helpers/fs-fixtures.js";
|
||||
|
||||
vi.mock("../process/exec.js", () => ({
|
||||
@@ -19,26 +19,6 @@ vi.mock("../process/exec.js", () => ({
|
||||
|
||||
const suiteTempRootTracker = createSuiteTempRootTracker("openclaw-plugin-install-path");
|
||||
|
||||
async function packToArchive(params: {
|
||||
pkgDir: string;
|
||||
outDir: string;
|
||||
outName: string;
|
||||
flatRoot?: boolean;
|
||||
}) {
|
||||
const dest = path.join(params.outDir, params.outName);
|
||||
fs.rmSync(dest, { force: true });
|
||||
const entries = params.flatRoot ? fs.readdirSync(params.pkgDir) : [path.basename(params.pkgDir)];
|
||||
await tar.c(
|
||||
{
|
||||
gzip: true,
|
||||
file: dest,
|
||||
cwd: params.flatRoot ? params.pkgDir : path.dirname(params.pkgDir),
|
||||
},
|
||||
entries,
|
||||
);
|
||||
return dest;
|
||||
}
|
||||
|
||||
function setupBundleInstallFixture(params: {
|
||||
bundleFormat: "codex" | "claude" | "cursor";
|
||||
name: string;
|
||||
|
||||
23
src/plugins/test-helpers/archive-fixtures.ts
Normal file
23
src/plugins/test-helpers/archive-fixtures.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import * as tar from "tar";
|
||||
|
||||
export async function packToArchive(params: {
|
||||
pkgDir: string;
|
||||
outDir: string;
|
||||
outName: string;
|
||||
flatRoot?: boolean;
|
||||
}) {
|
||||
const dest = path.join(params.outDir, params.outName);
|
||||
fs.rmSync(dest, { force: true });
|
||||
const entries = params.flatRoot ? fs.readdirSync(params.pkgDir) : [path.basename(params.pkgDir)];
|
||||
await tar.c(
|
||||
{
|
||||
gzip: true,
|
||||
file: dest,
|
||||
cwd: params.flatRoot ? params.pkgDir : path.dirname(params.pkgDir),
|
||||
},
|
||||
entries,
|
||||
);
|
||||
return dest;
|
||||
}
|
||||
Reference in New Issue
Block a user