Import tests/client-loader.test.mjs

This commit is contained in:
QQ 2026-11-12 10:47:01 +08:00
parent 636738377a
commit f079c6ca71
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import vm from 'node:vm'
test('lib/client.js registers the package factory with the module loader', () => {
const code = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
assert.ok(!/^export /m.test(code), 'loader file must not contain ESM export syntax')
let registered
const window = {
__ModuleLoader__: {
load: (entry) => { registered = entry },
},
}
vm.runInNewContext(code, { window, document: undefined, console, setInterval, clearInterval, setTimeout, clearTimeout })
assert.ok(registered, 'expected a __ModuleLoader__.load call')
assert.equal(registered.id, 'dsh-better-chat')
const plugin = registered.factory()
assert.equal(typeof plugin.apply, 'function')
assert.ok(Array.isArray(plugin.inject) && plugin.inject.length === 0, 'inject must be an empty array')
})