Files

29 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

/**
* Smoke test against the native RTCPeerConnection adapter when the
* runtime exposes one (browsers / Deno / Bun X). Skipped otherwise so
* Bun's own test runner stays green without third-party native modules.
*/
import { describe, test, expect } from 'bun:test';
import { isNativeRtcAvailable, nativeRtcFactory } from '../src/native-rtc.js';
describe('native RTC adapter', () => {
test('isNativeRtcAvailable() returns false in plain Bun', () => {
// This may flip to true in future Bun releases; the test is mostly a
// belt-and-suspenders against accidental globalThis pollution by
// earlier tests.
expect(typeof isNativeRtcAvailable()).toBe('boolean');
});
test('nativeRtcFactory()-built PC throws a clear error if RTCPeerConnection is missing', () => {
if (isNativeRtcAvailable()) {
const f = nativeRtcFactory();
const pc = f.createPeerConnection({});
expect(typeof pc.createDataChannel).toBe('function');
pc.close();
} else {
const f = nativeRtcFactory();
expect(() => f.createPeerConnection({})).toThrow(/RTCPeerConnection/);
}
});
});