Files
bare-operating-system/packages/bare-os-booter/test.bare-discord-load.js
T
2026-08-18 18:11:34 -04:00

51 lines
1.8 KiB
JavaScript

/**
* Regression: vendored `bare-discord-js` must resolve on the Bare host the same way as
* `executeKernel` (ctx.bare.discordJS). Executed by **brittle-bare** only — see package.json
* `test` / `test:bare`. Skips under plain Node if accidentally invoked.
*/
import test from 'brittle'
import { ensureGlobalRequireForCtxBareHostImports } from './lib/ctx/bare-os-ctx-bare.js'
import { loadBareDiscordJs } from './lib/services/bare-discord-js-loader.js'
function bareRuntime() {
if (typeof globalThis.Bare !== 'undefined') return true
const v = globalThis.process?.versions
return !!(v && typeof v.bare === 'string')
}
test('boot parity: ctx.bare.discordJS loads (ensureGlobalRequire + loadBareDiscordJs)', async (t) => {
if (!bareRuntime()) {
t.pass('skip — Bare runtime only (npm run test:bare -w bare-os-booter)')
return
}
await ensureGlobalRequireForCtxBareHostImports()
/** @type {Record<string, unknown>} */
const bareLibrary = {}
if (bareLibrary.discordJS === undefined) {
const dj = await loadBareDiscordJs(null)
if (dj !== undefined) bareLibrary.discordJS = dj
}
t.ok(
bareLibrary.discordJS != null,
'bare-discord-js resolved (mirrors executeKernel after ensureGlobalRequire)'
)
const d = /** @type {Record<string, unknown>} */ (bareLibrary.discordJS)
t.ok(
typeof d.Client === 'function',
'discord.js Client is exposed on ctx.bare.discordJS'
)
t.ok(
d.GatewayIntentBits && d.Events && d.Events.ClientReady,
'GatewayIntentBits and Events.ClientReady are present'
)
const client = new d.Client({
intents: [d.GatewayIntentBits.Guilds]
})
t.ok(
client && typeof client.login === 'function',
'Client instance can login'
)
t.ok(typeof client.destroy === 'function', 'Client instance can destroy')
await client.destroy()
})