mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-07 00:28:39 +01:00
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.
51 lines
1.0 KiB
TypeScript
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(),
|
|
}));
|