Files
boos e0a5f57793 feat(desktop): embed BoosAPI Desktop client as a subproject
Vendor the rebranded BoosAPI Desktop client (Tauri + Vue) into metapi as
a monorepo subdirectory under desktop/. Source only — node_modules,
dist, Cargo target and the upstream .git history are excluded.

desktop/ keeps its own independent Cargo workspace (desktop/src-tauri
with crates/*); it is not part of the backend boosapi crate, so a
`cargo check` at the metapi root still compiles only the backend. Build
the desktop app from desktop/src-tauri per desktop/README.md.

Note: app icons are still placeholder assets pending the final BoosAPI
logo. The updater signing keys live outside the repo and are not
included.
2026-06-22 11:32:57 +08:00

83 lines
2.6 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { buildKaTeXCDNWorkerSource, createKaTeXWorkerFromCDN } from '../../src/workers/katexCdnWorker'
describe('katex CDN worker factory', () => {
it('builds classic worker source with importScripts', () => {
const src = buildKaTeXCDNWorkerSource({
katexUrl: 'https://cdn.example.com/katex.min.js',
mhchemUrl: 'https://cdn.example.com/mhchem.min.js',
mode: 'classic',
})
expect(src).toContain('importScripts(')
expect(src).toContain('katex.min.js')
expect(src).toContain('mhchem.min.js')
})
it('builds module worker source with dynamic import(url)', () => {
const src = buildKaTeXCDNWorkerSource({
katexUrl: 'https://cdn.example.com/katex.mjs',
mhchemUrl: 'https://cdn.example.com/mhchem.mjs',
mode: 'module',
workerOptions: { type: 'module' },
})
expect(src).toContain('await import(')
expect(src).toContain('katex.mjs')
expect(src).toContain('mhchem.mjs')
})
it('is SSR-safe and returns null worker when Worker is unavailable', () => {
const prev = (globalThis as any).Worker
try {
;(globalThis as any).Worker = undefined
const handle = createKaTeXWorkerFromCDN({
katexUrl: 'https://cdn.example.com/katex.min.js',
mode: 'classic',
})
expect(handle.worker).toBeNull()
expect(typeof handle.dispose).toBe('function')
}
finally {
;(globalThis as any).Worker = prev
}
})
it('creates a Worker instance when Worker exists (stubbed in tests)', () => {
const handle = createKaTeXWorkerFromCDN({
katexUrl: 'https://cdn.example.com/katex.min.js',
mode: 'classic',
debug: true,
})
expect(handle.worker).toBeTruthy()
expect(typeof handle.dispose).toBe('function')
})
it('defaults module workerOptions.type to "module"', () => {
const prev = (globalThis as any).Worker
const calls: any[] = []
class CaptureWorker {
onmessage: ((event: MessageEvent) => void) | null = null
onerror: ((event: ErrorEvent) => void) | null = null
constructor(_url: string, opts?: WorkerOptions) {
calls.push({ opts })
}
addEventListener() {}
removeEventListener() {}
postMessage() {}
terminate() {}
}
try {
;(globalThis as any).Worker = CaptureWorker as any
const handle = createKaTeXWorkerFromCDN({
katexUrl: 'https://cdn.example.com/katex.mjs',
mode: 'module',
})
expect(handle.worker).toBeTruthy()
expect(calls[0]?.opts?.type).toBe('module')
}
finally {
;(globalThis as any).Worker = prev
}
})
})