runtime-backends.test.mjs (1900B)
1 import {readFile} from 'node:fs/promises'; 2 import test from 'node:test'; 3 import assert from 'node:assert/strict'; 4 import {backend,backends,runtimeStats} from '../dist/runtime-backends.js'; 5 import {createRuntimeSession} from '../dist/runtime-session.js'; 6 7 test('runtime selection is explicit, fixed and fails without fallback',async()=>{ 8 assert.deepEqual(Object.keys(backends),['haskell-wasm']); 9 assert.equal(backend('haskell-wasm'),'haskell-wasm'); 10 assert.deepEqual(Object.values(backends).map(x=>x.label),['Haskell']); 11 for(const name of ['js','zig-wasm','toString','constructor','unknown'])assert.throws(()=>backend(name),/Unknown/); 12 for(const name of [null,'js','zig-wasm','unknown'])await assert.rejects(createRuntimeSession(name,false),/Unsupported/); 13 }); 14 test('runtime diagnostics do not invent graph counters for WASM',()=>{ 15 const value=runtimeStats({backend:'haskell-wasm',linearMemoryBytes:12*1048576}); 16 assert.equal(value,'12.0 MiB WASM linear memory'); 17 assert.doesNotMatch(value,/work|heap nodes|allocated/); 18 }); 19 20 test('the page uses Haskell directly without a runtime selector',async()=>{ 21 const html=await readFile(new URL('../index.html',import.meta.url),'utf8'); 22 const app=await readFile(new URL('../src/app.ts',import.meta.url),'utf8'); 23 assert.doesNotMatch(html,/runtime-backend|toolbar-runtime/); 24 assert.match(app,/const selectedBackend = 'haskell-wasm'/); 25 assert.doesNotMatch(app,/backendPicker|['"]runtime-backend['"]/); 26 }); 27 28 test('production editor has no checkpoint restore or JS Worker branch',async()=>{ 29 const app=await readFile(new URL('../src/app.ts',import.meta.url),'utf8'); 30 assert.doesNotMatch(app,/CompiledDraft|compiledDraft|persistentDefinitions|type: 'restore'|compiler-worker\.js/); 31 const protocol=await readFile(new URL('../src/compiler-protocol.ts',import.meta.url),'utf8'); 32 assert.doesNotMatch(protocol,/GraphCheckpoint|CompiledDraft|restore/); 33 });