import { test } from 'node:test'; import assert from 'node:assert/strict'; import { run, sumWith } from './dist/main.js'; test('注入 api 时可在 Node 断言;不注入则需要浏览器全局', () => { const out = []; const fake = { version: 'test', add: (a, b) => a + b }; const ret = run((msg) => out.push(msg), fake); assert.deepEqual(ret, ['3', 'test']); assert.deepEqual(out, ret); assert.equal(sumWith({ add: (a, b) => a * b }, 2, 3), 6); assert.throws(() => run(() => {}), ReferenceError); });