chore: Upgrade to Vitest 4 and regroup tests for performance (#2618)
This commit is contained in:
+2
-2
@@ -7,7 +7,7 @@ class FakeMediaSource extends EventTarget {
|
||||
|
||||
public addSourceBuffer = vi.fn();
|
||||
public setLiveSeekableRange = vi.fn();
|
||||
public static isTypeSupported = vi.fn<[string], boolean>(() => true);
|
||||
public static isTypeSupported = vi.fn<(mimeType: string) => boolean>(() => true);
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -19,7 +19,7 @@ class FakeManagedMediaSource extends EventTarget {
|
||||
public addSourceBuffer = vi.fn();
|
||||
public setLiveSeekableRange = vi.fn();
|
||||
public readyState: 'closed' | 'open' | 'ended' = 'closed';
|
||||
public static isTypeSupported = vi.fn<[string], boolean>(() => true);
|
||||
public static isTypeSupported = vi.fn<(mimeType: string) => boolean>(() => true);
|
||||
}
|
||||
|
||||
const createObjectURL = vi.fn(() => 'blob:fake-url');
|
||||
|
||||
@@ -100,7 +100,7 @@ describe('Go2RTCSessionController', () => {
|
||||
cardWideConfig?: CardWideConfig | null;
|
||||
}) => {
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
@@ -1060,7 +1060,7 @@ describe('Go2RTCSessionController', () => {
|
||||
|
||||
it('should ignore callbacks fired while a binary source is constructed', () => {
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
@@ -1095,7 +1095,7 @@ describe('Go2RTCSessionController', () => {
|
||||
|
||||
it('should ignore callbacks fired while a WebRTC source is constructed', () => {
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
@@ -1129,7 +1129,7 @@ describe('Go2RTCSessionController', () => {
|
||||
|
||||
it('should use the default binary source factory when none is injected', () => {
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
@@ -1160,7 +1160,7 @@ describe('Go2RTCSessionController', () => {
|
||||
it('should use the default WebRTC source factory when none is injected', () => {
|
||||
vi.stubGlobal('RTCPeerConnection', FakeRTCPeerConnection);
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
@@ -1187,7 +1187,7 @@ describe('Go2RTCSessionController', () => {
|
||||
|
||||
it('should create an off-screen video with the default factory when none is injected', () => {
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('SignalingChannel', () => {
|
||||
disconnectCallback?: () => void;
|
||||
}) => {
|
||||
const websockets: FakeWebSocket[] = [];
|
||||
const createWebSocket = vi.fn<[string], WebSocket>(() => {
|
||||
const createWebSocket = vi.fn<(url: string) => WebSocket>(() => {
|
||||
const websocket = new FakeWebSocket();
|
||||
websockets.push(websocket);
|
||||
return websocket.asWebSocket();
|
||||
@@ -238,7 +238,11 @@ describe('SignalingChannel', () => {
|
||||
});
|
||||
|
||||
it('should construct a real websocket by default', () => {
|
||||
const webSocketConstructor = vi.fn(() => new FakeWebSocket().asWebSocket());
|
||||
// A mock implementation must be callable with `new`, so it cannot be an
|
||||
// arrow function.
|
||||
const webSocketConstructor = vi.fn(function () {
|
||||
return new FakeWebSocket().asWebSocket();
|
||||
});
|
||||
vi.stubGlobal('WebSocket', webSocketConstructor);
|
||||
const channel = new SignalingChannel('ws://host/api/ws', {});
|
||||
channel.connect();
|
||||
|
||||
@@ -14,7 +14,7 @@ describe('MJPEGStreamSource', () => {
|
||||
const channel = new FakeStreamSourceChannel();
|
||||
const loadedCallback = vi.fn();
|
||||
const failedCallback = vi.fn();
|
||||
const showFrame = vi.fn<[Blob], Promise<void>>(() => Promise.resolve());
|
||||
const showFrame = vi.fn<(blob: Blob) => Promise<void>>(() => Promise.resolve());
|
||||
|
||||
const context: StreamSourceContext<ImageStreamTarget> = {
|
||||
target: { kind: 'image', showFrame },
|
||||
|
||||
@@ -32,7 +32,7 @@ describe('MP4StreamSource', () => {
|
||||
const channel = new FakeStreamSourceChannel();
|
||||
const loadedCallback = vi.fn();
|
||||
const failedCallback = vi.fn();
|
||||
const showFrame = vi.fn<[Blob], Promise<void>>(() => Promise.resolve());
|
||||
const showFrame = vi.fn<(blob: Blob) => Promise<void>>(() => Promise.resolve());
|
||||
const context: StreamSourceContext<ImageStreamTarget> = {
|
||||
target: { kind: 'image', showFrame },
|
||||
channel,
|
||||
@@ -65,6 +65,7 @@ describe('MP4StreamSource', () => {
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('should request the mp4 stream on start', () => {
|
||||
@@ -217,6 +218,12 @@ describe('MP4StreamSource', () => {
|
||||
callbacks: { loadedCallback: vi.fn(), failedCallback: vi.fn() },
|
||||
});
|
||||
|
||||
// This is the only test that reaches a real canvas element. jsdom does not
|
||||
// implement `getContext` and writes an error to the console when it is
|
||||
// called; the source treats a missing context as nothing to draw to avoid
|
||||
// console spam.
|
||||
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(null);
|
||||
|
||||
const createElement = vi.spyOn(document, 'createElement');
|
||||
source.start();
|
||||
channel.binaryCallback?.(frame());
|
||||
|
||||
@@ -125,7 +125,7 @@ class FakeRTCTransceiver {
|
||||
public currentDirection: string;
|
||||
public sender: {
|
||||
track: FakeMediaStreamTrack | null;
|
||||
replaceTrack: Mock<[MediaStreamTrack | null], Promise<void>>;
|
||||
replaceTrack: Mock<(track: MediaStreamTrack | null) => Promise<void>>;
|
||||
};
|
||||
public receiver: { track: FakeMediaStreamTrack };
|
||||
|
||||
@@ -134,7 +134,7 @@ class FakeRTCTransceiver {
|
||||
this.currentDirection = direction;
|
||||
this.sender = {
|
||||
track,
|
||||
replaceTrack: vi.fn<[MediaStreamTrack | null], Promise<void>>(() =>
|
||||
replaceTrack: vi.fn<(track: MediaStreamTrack | null) => Promise<void>>(() =>
|
||||
Promise.resolve(),
|
||||
),
|
||||
};
|
||||
@@ -241,9 +241,9 @@ export class FakeMediaSourceInstance implements MediaSourceInterface {
|
||||
public attach = vi.fn();
|
||||
public detach = vi.fn();
|
||||
public setLiveSeekableRange = vi.fn();
|
||||
public isOpen = vi.fn<[], boolean>(() => true);
|
||||
public isTypeSupported = vi.fn<[string], boolean>(() => true);
|
||||
public addSourceBuffer = vi.fn<[string], SourceBuffer>(() =>
|
||||
public isOpen = vi.fn<() => boolean>(() => true);
|
||||
public isTypeSupported = vi.fn<(mimeType: string) => boolean>(() => true);
|
||||
public addSourceBuffer = vi.fn<(mimeType: string) => SourceBuffer>(() =>
|
||||
this.sourceBuffer.asSourceBuffer(),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user