docs.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import assert from "node:assert/strict";
  2. import { readFile } from "node:fs/promises";
  3. import test from "node:test";
  4. test("README documents the lifecycle-free immutable Git package workflow", async () => {
  5. const [readme, packageText, gitVerifier] = await Promise.all([
  6. readFile(new URL("../README.md", import.meta.url), "utf8"),
  7. readFile(new URL("../package.json", import.meta.url), "utf8"),
  8. readFile(new URL("../scripts/verify-git-package.mjs", import.meta.url), "utf8"),
  9. ]);
  10. const packageJson = JSON.parse(packageText) as {
  11. bin: Record<string, string>;
  12. files: string[];
  13. scripts: Record<string, string>;
  14. };
  15. for (const script of [
  16. "typecheck",
  17. "compile",
  18. "test",
  19. "verify:runtime",
  20. "verify:git-package",
  21. "verify:package",
  22. "pack:verified",
  23. ]) {
  24. assert.equal(typeof packageJson.scripts[script], "string");
  25. assert.equal(
  26. readme.includes(`npm run ${script}`) || (script === "test" && readme.includes("npm test")),
  27. true,
  28. );
  29. }
  30. assert.equal(
  31. packageJson.bin["codex-app-server-bridge"],
  32. "bin/codex-app-server-bridge.js",
  33. );
  34. assert.deepEqual(packageJson.files, [
  35. "bin/",
  36. "dist/cli.js",
  37. "dist/config.js",
  38. "README.md",
  39. "LICENSE",
  40. ]);
  41. assert.match(readme, /npm install --global/);
  42. assert.doesNotMatch(readme, /npm run build|prepack/);
  43. assert.match(readme, /git\+https:\/\/git\.bodicsek\.host\/bodicsek\/codex-app-server-bridge\.git#v0\.1\.1/);
  44. assert.match(readme, /full 40-character commit/i);
  45. assert.match(readme, /Do not use\s+`#main`/);
  46. assert.match(readme, /end-user install intentionally omits `--prefix`/);
  47. assert.match(readme, /0\.1\.0\.tgz/);
  48. assert.match(readme, /npm uninstall --global codex-app-server-bridge/);
  49. assert.match(readme, /command -v codex-app-server-bridge/);
  50. assert.match(readme, /CODEX_PATH/);
  51. for (const argument of ["--global", "--prefix", "--ignore-scripts", "--cache"]) {
  52. assert.equal(gitVerifier.includes(`"${argument}"`), true, `Git verifier is missing ${argument}`);
  53. }
  54. });