import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dirname, join } from 'node:path'; import { run } from './dist/main.js'; const here = dirname(fileURLToPath(import.meta.url)); test('namespace 产物是 IIFE;运行时提供对象', () => { globalThis.LegacyUI = { version: '1.0.0', boot: () => 'boot:1.0.0', Theme: { name: 'light' }, }; const out = []; const ret = run((msg) => out.push(msg)); assert.deepEqual(ret, ['1.0.0', 'boot:1.0.0', 'light']); assert.deepEqual(out, ret); const emitted = readFileSync(join(here, 'dist-script', 'ui.js'), 'utf8'); assert.ok(emitted.includes('var LegacyUI'), 'namespace 产物声明对象'); assert.ok(emitted.includes('(function (LegacyUI)'), 'namespace 产物是 IIFE'); });