Files
wehub-resource-sync adf0d17497
publish / version_or_publish (push) Waiting to run
storybook-build / changes (push) Waiting to run
storybook-build / :storybook-build (push) Blocked by required conditions
Sync Gradio Skills to Hugging Face / sync-skills (push) Waiting to run
functional / changes (push) Waiting to run
functional / build-frontend (push) Blocked by required conditions
functional / functional-test-SSR=false (push) Blocked by required conditions
functional / functional-reload (push) Blocked by required conditions
functional / functional-test-SSR=true (push) Blocked by required conditions
hygiene / hygiene-test (push) Waiting to run
python / changes (push) Waiting to run
python / build (push) Blocked by required conditions
python / test-ubuntu-latest-flaky (push) Blocked by required conditions
python / test-ubuntu-latest-not-flaky (push) Blocked by required conditions
python / test-windows-latest-flaky (push) Blocked by required conditions
python / test-windows-latest-not-flaky (push) Blocked by required conditions
js / changes (push) Waiting to run
js / js-test (push) Blocked by required conditions
docs-build / changes (push) Waiting to run
docs-build / docs-build (push) Blocked by required conditions
docs-build / website-build (push) Blocked by required conditions
chore: import upstream snapshot with attribution
2026-07-13 13:17:32 +08:00

114 lines
2.3 KiB
TypeScript

import { describe, expect, vi } from "vitest";
import {
get_devices,
get_video_stream,
set_available_devices,
set_local_stream
} from "./stream_utils";
import * as stream_utils from "./stream_utils";
let test_devices: MediaDeviceInfo[] = [
{
deviceId: "",
groupId: "",
kind: "audioinput",
label: "",
toJSON: () => ({
deviceId: "",
groupId: "",
kind: "audioinput",
label: ""
})
},
{
deviceId: "",
groupId: "",
kind: "videoinput",
label: "",
toJSON: () => ({
deviceId: "",
groupId: "",
kind: "videoinput",
label: ""
})
},
{
deviceId: "",
groupId: "",
kind: "audiooutput",
label: "",
toJSON: () => ({
deviceId: "",
groupId: "",
kind: "audiooutput",
label: ""
})
}
];
describe("stream_utils", () => {
test("get_devices should enumerate media devices", async () => {
const devices = await get_devices();
expect(Array.isArray(devices)).toBe(true);
});
test("set_local_stream should set the local stream to the video source", async () => {
const mock_video_source = {
srcObject: null,
muted: false,
play: vi.fn().mockResolvedValue(undefined)
};
// @ts-ignore
await set_local_stream(new MediaStream(), mock_video_source);
expect(mock_video_source.srcObject).toBeInstanceOf(MediaStream);
expect(mock_video_source.muted).toBeTruthy();
expect(mock_video_source.play).toHaveBeenCalled();
});
test("set_available_devices should return only video input devices", () => {
const mockDevices: MediaDeviceInfo[] = [
{
deviceId: "camera1",
kind: "videoinput",
label: "Camera 1",
groupId: "camera",
toJSON: () => ({
deviceId: "camera1",
kind: "videoinput",
label: "Camera 1",
groupId: "camera"
})
},
{
deviceId: "camera2",
kind: "videoinput",
label: "Camera 2",
groupId: "camera",
toJSON: () => ({
deviceId: "camera2",
kind: "videoinput",
label: "Camera 2",
groupId: "camera"
})
},
{
deviceId: "audio1",
kind: "audioinput",
label: "Audio 2",
groupId: "audio",
toJSON: () => ({
deviceId: "audio1",
kind: "audioinput",
label: "Audio 2",
groupId: "audio"
})
}
];
const videoDevices = set_available_devices(mockDevices);
expect(videoDevices).toEqual(mockDevices.splice(0, 2));
});
});