mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Patrick Kollitsch
10 hours ago c70b22c0c65d21fc25eda46a8182eb042da11da0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { test } from "node:test";
 
function check(script, html) {
  const root = mkdtempSync(join(tmpdir(), "ananke-static-gate-"));
  try {
    writeFileSync(join(root, "index.html"), html);
    return spawnSync(process.execPath, [script, root], { encoding: "utf8" });
  } finally {
    rmSync(root, { recursive: true, force: true });
  }
}
 
test("invalid markup fails the markup gate", () => {
  const result = check(
    "tests/support/check-markup.mjs",
    '<!doctype html><html lang="en"><head><title>Invalid</title></head><body><ul><p>Invalid list child</p></ul></body></html>',
  );
  assert.equal(result.status, 1);
  assert.match(result.stderr, /element-permitted-content/);
});
test("missing internal files fail the link gate", () => {
  const result = check(
    "tests/support/check-links.mjs",
    '<a href="http://localhost:4321/missing/">Missing page</a>',
  );
  assert.equal(result.status, 2);
  assert.match(result.stdout + result.stderr, /File not found/);
});
test("missing fragments fail the link gate", () => {
  const result = check(
    "tests/support/check-links.mjs",
    '<a href="#missing">Missing anchor</a>',
  );
  assert.equal(result.status, 2);
  assert.match(result.stdout + result.stderr, /[Ff]ragment/);
});