copy-assets.test.mjs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import assert from "node:assert/strict";
  2. import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
  3. import { tmpdir } from "node:os";
  4. import { dirname, join } from "node:path";
  5. import test from "node:test";
  6. import { copyCodingAgentAssets } from "./copy-assets.mjs";
  7. test("copies coding-agent runtime assets without relying on shell commands", async () => {
  8. const root = await mkdtemp(join(tmpdir(), "pi-copy-assets-"));
  9. const sourceRoot = join(root, "src");
  10. const distRoot = join(root, "dist");
  11. try {
  12. const fixtures = [
  13. ["modes/interactive/theme/dark.json", "theme"],
  14. ["modes/interactive/assets/logo.png", "image"],
  15. ["core/export-html/template.html", "html"],
  16. ["core/export-html/template.css", "css"],
  17. ["core/export-html/template.js", "script"],
  18. ["core/export-html/vendor/highlight.js", "vendor"],
  19. ];
  20. for (const [relativePath, contents] of fixtures) {
  21. const path = join(sourceRoot, relativePath);
  22. await mkdir(dirname(path), { recursive: true });
  23. await writeFile(path, contents);
  24. }
  25. await writeFile(join(sourceRoot, "modes/interactive/theme/ignored.txt"), "ignored");
  26. await copyCodingAgentAssets({ sourceRoot, distRoot });
  27. for (const [relativePath, contents] of fixtures) {
  28. assert.equal(await readFile(join(distRoot, relativePath), "utf8"), contents);
  29. }
  30. await assert.rejects(readFile(join(distRoot, "modes/interactive/theme/ignored.txt")));
  31. } finally {
  32. await rm(root, { recursive: true, force: true });
  33. }
  34. });
  35. test("the package copy-assets command does not require shx", async () => {
  36. const packageJson = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
  37. assert.equal(packageJson.scripts["copy-assets"], "node scripts/copy-assets.mjs");
  38. });