stock-bot/scripts/test/native-bindings.test.ts
2026-10-20 12:39:38 -04:00

18 lines
768 B
TypeScript

import { createRequire } from 'node:module';
import { describe, expect, it } from 'bun:test';
import { IncrementalSMA, TechnicalIndicators } from '@stock-bot/engine';
describe('generated native bindings', () => {
it('ESM loads the generated artifact and exposes the documented constructor aliases', () => {
const sma = new IncrementalSMA(2);
sma.update(10);
expect(sma.update(12)).toBe(11);
expect(new TechnicalIndicators().calculateSma([1, 2, 3], 2)).toEqual([1.5, 2.5]);
});
it('CommonJS exposes the same native constructors', () => {
const binding = createRequire(import.meta.url)('@stock-bot/engine');
expect(binding.TechnicalIndicators).toBe(TechnicalIndicators);
expect(binding.IncrementalSMA).toBe(IncrementalSMA);
});
});