示例工程 17-pre-module-globals

17-pre-module-globals/01-global-collision/main.test.mjs

javascript · 0.4 KB

运行:17 · global-collision

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { run } from './dist/main.js';
 
test('最后写入的脚本获胜:全局被覆盖', () => {
  globalThis.config = { theme: 'blue', debug: true };
  const out = [];
  const ret = run((msg) => out.push(msg));
  assert.deepEqual(ret, ['blue', 'true']);
  assert.deepEqual(out, ret);
  delete globalThis.config;
});