import { test } from 'node:test'; import assert from 'node:assert/strict'; import { escapeHtml, setText, run } from './main.js'; test('escapeHtml 转义五个关键字符', () => { assert.equal(escapeHtml(`<&>"'`), '<&>"''); }); test('escapeHtml 不重复转义已经转义的实体', () => { assert.equal(escapeHtml('<'), '&lt;'); }); test('非字符串输入先转成字符串', () => { assert.equal(escapeHtml(42), '42'); assert.equal(escapeHtml(null), 'null'); }); test('setText 写入纯文本并返回读回值', () => { const el = {}; assert.equal(setText(el, 'x'), 'x'); assert.equal(el.textContent, 'x'); }); test('Node 里调用 run 给出环境错误', () => { assert.throws(() => run(() => {}), /需要浏览器环境/); });