style: format plugin install test
This commit is contained in:
@@ -14,18 +14,38 @@ function makeTempDir() {
|
|||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function packToArchive({ pkgDir, outDir, outName }: { pkgDir: string; outDir: string; outName: string }) {
|
function packToArchive({
|
||||||
const res = spawnSync("npm", ["pack", "--silent", "--pack-destination", outDir, pkgDir], {
|
pkgDir,
|
||||||
encoding: "utf-8",
|
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);
|
expect(res.status).toBe(0);
|
||||||
if (res.status !== 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) {
|
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);
|
const src = path.join(outDir, packed);
|
||||||
@@ -82,7 +102,11 @@ describe("installPluginFromArchive", () => {
|
|||||||
"utf-8",
|
"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 result = await withStateDir(stateDir, async () => {
|
||||||
const { installPluginFromArchive } = await import("./install.js");
|
const { installPluginFromArchive } = await import("./install.js");
|
||||||
@@ -122,7 +146,11 @@ describe("installPluginFromArchive", () => {
|
|||||||
"utf-8",
|
"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 { first, second } = await withStateDir(stateDir, async () => {
|
||||||
const { installPluginFromArchive } = await import("./install.js");
|
const { installPluginFromArchive } = await import("./install.js");
|
||||||
@@ -148,7 +176,11 @@ describe("installPluginFromArchive", () => {
|
|||||||
"utf-8",
|
"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 result = await withStateDir(stateDir, async () => {
|
||||||
const { installPluginFromArchive } = await import("./install.js");
|
const { installPluginFromArchive } = await import("./install.js");
|
||||||
|
|||||||
Reference in New Issue
Block a user