openreader/tests/unit/whisper-alignment-mapping.spec.ts
Richard R 50c4330ab1 refactor(core,config,tests): update ONNX model manifest loading and test imports
- Replace static JSON imports with runtime manifest loading in pdf and whisper model modules for compatibility with ESM and bundlers
- Refactor Next.js config to clarify compute mode logic and improve worker bundling conditions
- Update test imports to use package entrypoints instead of relative paths
- Remove redundant whisper alignment/model tests now covered elsewhere or by integration
- No breaking changes to public API or model handling logic
2026-05-21 23:49:56 -06:00

21 lines
882 B
TypeScript

import { test, expect } from '@playwright/test';
import {
mapWordsToSentenceOffsets,
} from '@openreader/compute-core';
test.describe('whisper alignment mapping', () => {
test('maps words to sentence offsets with punctuation and repeated spaces', () => {
const aligned = mapWordsToSentenceOffsets('Hello, world again.', [
{ word: 'Hello', start: 0, end: 0.25 },
{ word: 'world', start: 0.25, end: 0.5 },
{ word: 'again', start: 0.5, end: 1.0 },
]);
expect(aligned.words).toHaveLength(3);
expect(aligned.words[0].charStart).toBe(0);
expect(aligned.words[0].charEnd).toBe(5);
expect(aligned.words[1].charStart).toBeGreaterThan(aligned.words[0].charEnd);
expect(aligned.words[2].charStart).toBeGreaterThan(aligned.words[1].charEnd);
expect(aligned.words[2].charEnd).toBeLessThanOrEqual('Hello, world again.'.length);
});
});