silverbullet/cmd/test/plug_run.test.ts

48 lines
1.4 KiB
TypeScript
Raw Normal View History

import { AssetBundle } from "$lib/asset_bundle/bundle.ts";
import { compileManifest } from "../compile.ts";
import * as esbuild from "esbuild";
2024-07-30 21:17:34 +08:00
import assets from "../../dist/plug_asset_bundle.json" with { type: "json" };
2024-07-30 23:24:17 +08:00
import { assertEquals } from "@std/assert";
import { dirname, join } from "@std/path";
import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts";
import { runPlug } from "../plug_run.ts";
2024-11-14 04:08:24 +08:00
import { fileURLToPath } from "node:url";
2023-08-05 00:56:55 +08:00
Deno.test("Test plug run", {
sanitizeResources: false,
sanitizeOps: false,
}, async () => {
2023-08-05 00:56:55 +08:00
const assetBundle = new AssetBundle(assets);
2024-11-14 04:08:24 +08:00
const testFolder = dirname(fileURLToPath(new URL(import.meta.url)));
const testSpaceFolder = join(testFolder, "test_space");
2023-08-05 00:56:55 +08:00
const plugFolder = join(testSpaceFolder, "_plug");
2023-08-05 00:56:55 +08:00
await Deno.mkdir(plugFolder, { recursive: true });
2024-08-05 15:20:35 +08:00
await Deno.writeFile(
`${testSpaceFolder}/SETTINGS.md`,
new TextEncoder().encode("```space-config\nindexPage: index\n```"),
);
2023-08-05 00:56:55 +08:00
await compileManifest(
join(testFolder, "test_plug_run.plug.yaml"),
2023-08-05 00:56:55 +08:00
plugFolder,
2024-07-30 20:26:02 +08:00
{
2024-11-14 04:08:24 +08:00
configPath: fileURLToPath(new URL("../../deno.json", import.meta.url)),
2024-07-30 20:26:02 +08:00
},
2023-08-05 00:56:55 +08:00
);
assertEquals(
await runPlug(
testSpaceFolder,
"test.run",
[],
assetBundle,
new MemoryKvPrimitives(),
2023-08-05 00:56:55 +08:00
),
"Hello",
);
// await Deno.remove(tempDir, { recursive: true });
esbuild.stop();
});