style: format plugin install test

This commit is contained in:
Peter Steinberger
2026-01-12 01:26:57 +00:00
parent b9b0d46773
commit 5bdb9c0e99

View File

@@ -14,18 +14,38 @@ function makeTempDir() {
return dir;
}
function packToArchive({ pkgDir, outDir, outName }: { pkgDir: string; outDir: string; outName: string }) {
const res = spawnSync("npm", ["pack", "--silent", "--pack-destination", outDir, pkgDir], {
encoding: "utf-8",
});
function packToArchive({
pkgDir,
outDir,
outName,
}: {
pkgDir: string;
outDir: string;
outName: string;
}) {
const res = spawnSync(
"npm",
["pack", "--silent", "--pack-destination", outDir, pkgDir],
{
encoding: "utf-8",
},
);
expect(res.status).toBe(0);
if (res.status !== 0) {
throw new Error(`npm pack failed: ${res.stderr || res.stdout || "<no output>"}`);
throw new Error(
`npm pack failed: ${res.stderr || res.stdout || "<no output>"}`,
);
}
const packed = (res.stdout || "").trim().split(/\r?\n/).filter(Boolean).at(-1);
const packed = (res.stdout || "")
.trim()
.split(/\r?\n/)
.filter(Boolean)
.at(-1);
if (!packed) {
throw new Error(`npm pack did not output a filename: ${res.stdout || "<no stdout>"}`);
throw new Error(
`npm pack did not output a filename: ${res.stdout || "<no stdout>"}`,
);
}
const src = path.join(outDir, packed);
@@ -82,7 +102,11 @@ describe("installPluginFromArchive", () => {
"utf-8",
);
const archivePath = packToArchive({ pkgDir, outDir: workDir, outName: "plugin.tgz" });
const archivePath = packToArchive({
pkgDir,
outDir: workDir,
outName: "plugin.tgz",
});
const result = await withStateDir(stateDir, async () => {
const { installPluginFromArchive } = await import("./install.js");
@@ -122,7 +146,11 @@ describe("installPluginFromArchive", () => {
"utf-8",
);
const archivePath = packToArchive({ pkgDir, outDir: workDir, outName: "plugin.tgz" });
const archivePath = packToArchive({
pkgDir,
outDir: workDir,
outName: "plugin.tgz",
});
const { first, second } = await withStateDir(stateDir, async () => {
const { installPluginFromArchive } = await import("./install.js");
@@ -148,7 +176,11 @@ describe("installPluginFromArchive", () => {
"utf-8",
);
const archivePath = packToArchive({ pkgDir, outDir: workDir, outName: "bad.tgz" });
const archivePath = packToArchive({
pkgDir,
outDir: workDir,
outName: "bad.tgz",
});
const result = await withStateDir(stateDir, async () => {
const { installPluginFromArchive } = await import("./install.js");