Files

16 lines
915 B
JavaScript

import assert from 'node:assert/strict'
import { readdir, readFile } from 'node:fs/promises'
const files = await readdir(new URL('../dist/', import.meta.url))
assert.deepEqual(files.sort(), ['index.html'], 'dist 必须只包含一个可直接运行的入口')
const html = await readFile(new URL('../dist/index.html', import.meta.url), 'utf8')
assert.match(html, /^<!doctype html>/i, '缺少 HTML 文档入口')
assert.match(html, /<script type="module"[^>]*>[^<]+/s, 'JavaScript 未内联')
assert.match(html, /<style[^>]*>[^<]+/s, 'CSS 未内联')
assert.doesNotMatch(html, /<script[^>]+src=/i, '发行版仍依赖外部脚本')
assert.doesNotMatch(html, /__STAR_SEED_TEST__/, '发行版包含调试后门')
assert.doesNotMatch(html, /(?:password|passwd|token|secret)\s*[:=]\s*["'][^"']{6,}["']/i, '发行版包含疑似敏感凭据')
console.log(`DIST_OK ${html.length} bytes, one self-contained index.html`)