mirror of
https://github.com/pratikwayal01/datacloak.git
synced 2026-10-26 06:59:34 +01:00
17 lines
683 B
TypeScript
17 lines
683 B
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { OnnxNerProvider } from '../src/onnx.js';
|
|
|
|
describe('onnx provider', () => {
|
|
it('throws install hint without a model file', () => {
|
|
expect(() => new OnnxNerProvider('/nonexistent/model.onnx')).toThrow(/model file not found/);
|
|
});
|
|
it('maps label spans to Span[] with a mocked session', async () => {
|
|
const fakeSession = {
|
|
run: vi.fn(async () => ({ labels: ['B-PER', 'I-PER', 'O'] })),
|
|
};
|
|
const p = new OnnxNerProvider('/model.onnx', fakeSession as never);
|
|
const spans = await p.detectNamesAsync('Alice Johnson ran');
|
|
expect(spans.map((s) => s.value)).toContain('Alice Johnson');
|
|
});
|
|
});
|