import { test } from 'node:test'; import assert from 'node:assert/strict'; import { groupBySlot, normalizeSlotName, run } from './main.js'; test('slot 名字规范化:null/undefined 视为默认插槽', () => { assert.equal(normalizeSlotName(null), ''); assert.equal(normalizeSlotName(undefined), ''); assert.equal(normalizeSlotName('title'), 'title'); }); test('按插槽分组', () => { assert.deepEqual( groupBySlot([ { slot: 'title', label: 'a' }, { slot: null, label: 'b' }, { slot: 'title', label: 'c' }, ]), { title: ['a', 'c'], '': ['b'] }, ); }); test('空列表返回空对象', () => { assert.deepEqual(groupBySlot([]), {}); }); test('Node 里调用 run 给出环境错误', () => { assert.throws(() => run(() => {}), /需要浏览器环境/); });