Files
bentopdf/src/tests/setup.ts
T
alam00000 aee3e0a65a test: cover the text editor engine and FreeText flattening
Adds a node-side harness that drives the engine wasm directly, fixtures
that build PDFs in-memory, and cases for font fallback and flattening.
The engine loader now tolerates a runtime without import.meta.resolve so
the suite can load it outside a browser.
2026-08-21 12:50:07 +05:30

51 lines
1.0 KiB
TypeScript

import { afterEach, vi } from 'vitest';
class TestDOMMatrix {
a = 1;
b = 0;
c = 0;
d = 1;
e = 0;
f = 0;
}
if (typeof globalThis.DOMMatrix === 'undefined') {
globalThis.DOMMatrix = TestDOMMatrix as unknown as typeof DOMMatrix;
}
const hasDom = typeof window !== 'undefined';
afterEach(() => {
if (!hasDom) return;
document.body.innerHTML = '';
document.head.innerHTML = '';
});
global.ResizeObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));
if (hasDom) {
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation((query) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
}
global.IntersectionObserver = vi.fn().mockImplementation(() => ({
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
}));