openpencil/packages/op-web-sdk/vitest.config.ts
Kayshen-X 20971e04b4 feat(sdk): add @zseven-w/op-web-sdk TS core (read-only web viewer)
Plan 2 of the web embedding SDK: a self-contained, framework-agnostic
TypeScript core wrapping the Plan-1 wasm Viewer. createViewer -> OpViewer with
load, read-only snapshots (document/pages/pageCount/activePage), pan/zoom
navigation (+ wheel), SVG export, load/viewportchange events, and destroy.

Read-only: no .op editing/mutation. Self-contained: zero @zseven-w/pen-* deps
(types vendored from jian-ops-schema ts-rs), tsup build, vitest+jsdom tests
that mock the wasm seam. 10/10 tests; tsc clean; post-destroy use-after-free
guarded. React+Vue adapters follow in Plan 3.
2026-06-19 19:01:14 +08:00

34 lines
1 KiB
TypeScript

import { defineConfig, type Plugin } from 'vitest/config';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
// Absolute path to the committed test stub.
const wasmStubPath = path.resolve(__dirname, 'test/wasm-stub.ts');
// The virtual module specifier used in src/wasm.ts and test files.
const VIRTUAL_WASM_ID = 'virtual:op_web_sdk_wasm';
/**
* Vite plugin that resolves the virtual wasm specifier to the committed test
* stub during tests, so import-analysis succeeds on a fresh clone with no
* wasm/ dir present. The real bundle is resolved differently at build time
* (by tsup/externals or by sync-wasm.sh populating wasm/).
*/
function wasmStubPlugin(): Plugin {
return {
name: 'wasm-stub',
enforce: 'pre',
resolveId(id) {
if (id === VIRTUAL_WASM_ID) return wasmStubPath;
return null;
},
};
}
export default defineConfig({
plugins: [wasmStubPlugin()],
test: { environment: 'jsdom', globals: true },
});