57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
import { callCore, loadCore } from '../src/index'
|
|
import { coreBuilt } from './helpers/core'
|
|
|
|
const CORE_MANIFEST = new URL(
|
|
'../../../crates/core/Cargo.toml',
|
|
import.meta.url,
|
|
)
|
|
const WORKSPACE_MANIFEST = new URL('../../../Cargo.toml', import.meta.url)
|
|
|
|
describe.skipIf(!coreBuilt)('core facade (wasm)', () => {
|
|
it('reports the workspace version of the core', async () => {
|
|
const core = await loadCore()
|
|
const workspace = readFileSync(fileURLToPath(WORKSPACE_MANIFEST), 'utf8')
|
|
const version = /\[workspace\.package\][^[]*?version = "([^"]+)"/s.exec(
|
|
workspace,
|
|
)?.[1]
|
|
expect(version).toBeDefined()
|
|
expect(readFileSync(fileURLToPath(CORE_MANIFEST), 'utf8')).toContain(
|
|
'version.workspace = true',
|
|
)
|
|
expect(core.core_version()).toBe(version)
|
|
})
|
|
|
|
it('answers with a closed outcome envelope', async () => {
|
|
const core = await loadCore()
|
|
expect(callCore(core, 'core_version', '')).toEqual({
|
|
ok: true,
|
|
value: core.core_version(),
|
|
})
|
|
expect(callCore(core, 'nope', '{}')).toMatchObject({
|
|
ok: false,
|
|
kind: 'unknown_op',
|
|
})
|
|
expect(callCore(core, 'pretty_json', '{ not json')).toMatchObject({
|
|
ok: false,
|
|
kind: 'invalid_json',
|
|
})
|
|
})
|
|
|
|
it('exposes exactly the documented functions', async () => {
|
|
const core = await loadCore()
|
|
for (const name of [
|
|
'core_version',
|
|
'call',
|
|
'panic_for_test',
|
|
'recurse_for_test',
|
|
]) {
|
|
expect(typeof (core as unknown as Record<string, unknown>)[name]).toBe(
|
|
'function',
|
|
)
|
|
}
|
|
})
|
|
})
|