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 { Geometry, run } from './dist/main.js'; const here = dirname(fileURLToPath(import.meta.url)); test('namespace 生成 IIFE,嵌套 namespace 是嵌套对象', () => { const out = []; const ret = run((msg) => out.push(msg)); assert.deepEqual(ret, ['3.14', 'circle', '3.14159']); assert.deepEqual(out, ret); assert.equal(Geometry.area(2).toFixed(2), '12.57'); const emitted = readFileSync(join(here, 'dist', 'main.js'), 'utf8'); assert.ok(emitted.includes('(function (Geometry)'), 'namespace 产物是 IIFE'); });