UNPKG

gitsite-cli

Version:

Tools for generate static web site from Markdown files in git repository.

31 lines (25 loc) 1.06 kB
import test from 'node:test'; import assert from 'node:assert/strict'; import path from 'node:path'; import { existsSync, readdirSync, mkdirSync, rmSync } from 'node:fs'; import createMarkdown from '../bin/markdown.js'; import { readFile } from 'node:fs/promises'; async function check_file(name) { const src = await readFile(`test/resources/${name}.md`, { encoding: 'utf-8' }); const html = await readFile(`test/resources/${name}.html`, { encoding: 'utf-8' }); const md = await createMarkdown(); assert.equal(md.render(src), html); } process.env.disableCache = true; process.env.cacheDir = path.join(process.cwd(), '.cache'); // clean cache dir: if (existsSync(process.env.cacheDir)) { rmSync(process.env.cacheDir, { recursive: true }); } mkdirSync(process.env.cacheDir); const tests = readdirSync('test/resources').filter(name => name.endsWith('.md')).map(name => name.substring(0, name.length - 3)); for (let name of tests) { test(`test ${name}.md <=> ${name}.html`, async (t) => { await check_file(name); }); }