// The commands people run live in pixi.toml; the README's table lists them. core/ is pplus-core, a project of its // own with its own pixi.toml and this same test. These tests keep the // two in step, and keep every `pixi run ` mentioned anywhere pointing at a task that exists. import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; const ROOT = new URL('..', import.meta.url).pathname; const read = (p) => fs.readFileSync(path.join(ROOT, p), 'utf8'); /** Task names in pixi.toml's [tasks] table: `name = {` at the start of a line, until the next table. */ function pixiTasks() { const text = read('pixi.toml'); const body = text.slice(text.indexOf('\n[tasks]') + 1).split(/\n\[(?!tasks\])/)[0]; return [...body.matchAll(/^([a-z][a-z0-9-]*)\s*=\s*\{/gm)].map((m) => m[1]); } /** Task names in the README's Commands table: the first cell, a backticked name with optional arguments. */ function readmeTasks() { const readme = read('README.md'); const section = readme.slice(readme.indexOf('## Commands'), readme.indexOf('\n## ', readme.indexOf('## Commands') + 1)); return [...section.matchAll(/^\| `([a-z][a-z0-9-]*)(?: [^`]*)?` \|/gm)].map((m) => m[1]); } test('the README lists every pixi task, once, and nothing else', () => { const tasks = pixiTasks(); assert.ok(tasks.length > 15, `only ${tasks.length} tasks read from pixi.toml`); const listed = readmeTasks(); assert.deepEqual([...listed].sort(), [...tasks].sort()); assert.equal(new Set(listed).size, listed.length, 'a task is listed twice'); }); test('every pixi task has a description', () => { const text = read('pixi.toml'); for (const t of pixiTasks()) { const line = text.split('\n').find((l) => l.startsWith(`${t} = {`)); assert.match(line, /description = "[^"]+"/, `${t} has no description`); } }); test('every `pixi run ` in the docs, scripts and sources names a real task', () => { const tasks = new Set(pixiTasks()); const files = []; const walk = (dir) => { for (const e of fs.readdirSync(path.join(ROOT, dir), { withFileTypes: true })) { const p = path.join(dir, e.name); if (e.isDirectory()) { if (!['node_modules', 'dist', 'site', '.git', '.pixi', 'corpus', 'golden', 'vendor', 'scratch'].includes(e.name) && p !== 'core') walk(p); } else if (/\.(md|mjs|ts|py|lua|yml|toml)$/.test(e.name)) files.push(p); } }; walk('.'); const unknown = []; for (const f of files) { for (const m of read(f).matchAll(/pixi run ([a-z][a-z0-9-]*)/g)) if (!tasks.has(m[1])) unknown.push(`${f}: pixi run ${m[1]}`); } assert.deepEqual(unknown, []); }); test('package.json keeps only what CI and a machine without pixi need', () => { const pkg = JSON.parse(read('package.json')); assert.deepEqual(Object.keys(pkg.scripts).sort(), ['build', 'check', 'dev', 'test', 'watch']); }); test('every document the README points to exists', () => { const readme = read('README.md'); for (const m of readme.matchAll(/\]\(((?:docs|quarto|styles)\/[^)#]+)\)/g)) assert.ok(fs.existsSync(path.join(ROOT, m[1])), `${m[1]} is linked from the README but missing`); for (const m of read('docs/app.md').matchAll(/`(docs\/[\w.-]+\.md)`/g)) assert.ok(fs.existsSync(path.join(ROOT, m[1])), `${m[1]} is named in docs/app.md but missing`); });