Skip to content

Commit

Permalink
vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed May 20, 2024
1 parent f3b1a27 commit d82e9e4
Show file tree
Hide file tree
Showing 20 changed files with 2,206 additions and 87 deletions.
2,221 changes: 2,161 additions & 60 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
"version": "0.0.1",
"private": "true",
"description": "WebRTC Implementation for TypeScript (Node.js)",
"keywords": ["WebRTC", "node.js"],
"keywords": [
"WebRTC",
"node.js"
],
"homepage": "https://github.com/shinyoshiaki/werift-webrtc",
"repository": {
"type": "git",
"url": "https://github.com/shinyoshiaki/werift-webrtc.git"
},
"license": "MIT",
"author": "shinyoshiaki <[email protected]>",
"workspaces": ["packages/*", "examples/*"],
"workspaces": [
"packages/*",
"examples/*"
],
"scripts": {
"build": "npm run build --workspaces --if-present",
"ci": "npm run type:all && npm run build && npm run test && npm run e2e && npm run doc",
Expand Down Expand Up @@ -44,7 +50,8 @@
"ts-node-dev": "^2.0.0",
"typedoc": "0.25.5",
"typedoc-plugin-markdown": "3.17.1",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "^1.6.0"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"doc": "rm -rf doc && typedoc --excludePrivate --disableSources --excludeInternal --plugin typedoc-plugin-markdown --out doc ./src/index.ts",
"format": "biome check --apply src tests",
"knip": "knip",
"test": "npm run type && jest --runInBand --forceExit --coverage",
"test": "vitest run ./tests",
"type": "tsc --noEmit --project ./tsconfig.json",
"unused": "organize-imports-cli src/**/*.ts",
"upgrade-interactive": "npx npm-check-updates -i"
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/datachannel/close.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createDataChannelPair } from "../utils";

jest.setTimeout(10_000);


describe.each([{}, { negotiated: true, id: 0 }])(
"datachannel/close",
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/datachannel/send.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { awaitMessage, createDataChannelPair } from "../utils";

jest.setTimeout(15_000);


const helloString = "hello";
const unicodeString = "世界你好";
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/integrate/datachannel.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RTCPeerConnection } from "../../src";

jest.setTimeout(10_000);


describe("datachannel", () => {
test("send some messages at same time", async () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/integrate/mediaChannel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useSdesMid,
} from "../../src";

jest.setTimeout(10_000);


describe("media", () => {
test("test_sendonly_recvonly", async () =>
Expand Down
4 changes: 2 additions & 2 deletions packages/webrtc/tests/integrate/peerConnection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "../../src";
import { SignatureAlgorithm } from "../../src/const";

jest.setTimeout(10_000);


describe("peerConnection", () => {
test("test_connect_datachannel_modern_sdp", async () =>
Expand Down Expand Up @@ -135,7 +135,7 @@ describe("peerConnection", () => {
await assertDataChannelOpen(dc);
}));

xtest("portRange", async () => {
test.skip("portRange", async () => {
const peer = new RTCPeerConnection({ icePortRange: [44444, 44455] });
peer.createDataChannel("test");
const offer = await peer.createOffer();
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/integrate/trickle.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RTCPeerConnection } from "../../src";

jest.setTimeout(10_000);


describe("trickle", () => {
test(
Expand Down
4 changes: 2 additions & 2 deletions packages/webrtc/tests/media/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { RTCRtpSender } from "../../src/media/rtpSender";
import { createDtlsTransport } from "../fixture";

describe("media/router", () => {
test("routeRtp", (done) => {
test("routeRtp", ()=>new Promise<void>((done) => {
const router = new RtpRouter();
const dtls = createDtlsTransport();
const transceiver = new RTCRtpTransceiver(
Expand Down Expand Up @@ -56,5 +56,5 @@ describe("media/router", () => {
done();
});
router.routeRtp(packet);
});
}));
});
3 changes: 2 additions & 1 deletion packages/webrtc/tests/media/rtpReceiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "../../src";
import { RTCRtpReceiver } from "../../src/media/rtpReceiver";
import { createDtlsTransport } from "../fixture";
import {vi} from 'vitest'

describe("packages/webrtc/src/media/rtpReceiver.ts", () => {
test("abort runRtcp", async () =>
Expand All @@ -20,7 +21,7 @@ describe("packages/webrtc/src/media/rtpReceiver.ts", () => {
const receiver = new RTCRtpReceiver(defaultPeerConfig, "audio", 1234);
receiver.setDtlsTransport(dtls);

jest.spyOn(dtls, "sendRtcp");
vi.spyOn(dtls, "sendRtcp");

Promise.any([
setTimeout(200).then(() => false),
Expand Down
7 changes: 4 additions & 3 deletions packages/webrtc/tests/media/rtpSender.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { setTimeout } from "timers/promises";
import { MediaStreamTrack } from "../../src";
import { RTCRtpSender } from "../../src/media/rtpSender";
import { createDtlsTransport, createRtpPacket } from "../fixture";
import {vi} from 'vitest'

describe("media/rtpSender", () => {
test("stop track", () => {
Expand All @@ -11,7 +12,7 @@ describe("media/rtpSender", () => {
const sender = new RTCRtpSender(track);
sender.setDtlsTransport(dtls);

const spy = jest.spyOn(sender, "sendRtp");
const spy = vi.spyOn(sender, "sendRtp");

const rtp = createRtpPacket();

Expand All @@ -31,7 +32,7 @@ describe("media/rtpSender", () => {
const dtls = createDtlsTransport();
const sender = new RTCRtpSender(track1);
sender.setDtlsTransport(dtls);
const spy = jest.spyOn(sender, "sendRtp");
const spy = vi.spyOn(sender, "sendRtp");

const rtp = createRtpPacket();

Expand All @@ -55,7 +56,7 @@ describe("media/rtpSender", () => {
const sender = new RTCRtpSender("audio");
sender.setDtlsTransport(dtls);

jest.spyOn(dtls, "sendRtcp");


Promise.any([
setTimeout(200).then(() => false),
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/transport/dtls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { setTimeout } from "timers/promises";

import { dtlsTransportPair } from "../fixture";

jest.setTimeout(10_000);


describe("RTCDtlsTransportTest", () => {
test("dtls_test_data", async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/webrtc/tests/transport/ice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import inRange from "lodash/inRange";

import { RTCIceGatherer, RTCIceTransport } from "../../src";

jest.setTimeout(10_000);


describe("iceTransport", () => {
test("test_connect", async () => {
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("iceTransport", () => {
expect(transport2.state).toBe("closed");
});

xtest("portRange", async () => {
test.skip("portRange", async () => {
const gatherer = new RTCIceGatherer({
stunServer: ["stun.l.google.com", 19302],
portRange: [44444, 44455],
Expand All @@ -55,7 +55,7 @@ describe("iceTransport", () => {
await gatherer.connection.close();
});

xtest("minimum target port", async () => {
test.skip("minimum target port", async () => {
const gatherer = new RTCIceGatherer({
stunServer: ["stun.l.google.com", 19302],
portRange: [44546, 44547],
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/transport/sctp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RTCDataChannel, RTCSctpTransport } from "../../src";
import { RTCDataChannelParameters } from "../../src/dataChannel";
import { dtlsTransportPair } from "../fixture";

jest.setTimeout(10_000);


describe("RTCSctpTransportTest", () => {
function trackChannels(transport: RTCSctpTransport) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/wpt/addTrack.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MediaStreamTrack, RTCPeerConnection } from "../../src";
import { RTCRtpSender } from "../../src/media/rtpSender";

jest.setTimeout(10_000);


// https://github.com/web-platform-tests/wpt/blob/master/webrtc/RTCPeerConnection-addTrack.https.html

Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/wpt/onnegotiaationneeded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RTCPeerConnection } from "../../src";
import { generateAnswer, generateOffer } from "../fixture";
import { generateAudioReceiveOnlyOffer } from "../utils";

jest.setTimeout(10_000);


describe("onnegotiationneeded", () => {
test("Creating first data channel should fire negotiationneeded event", async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/tests/wpt/ontrack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { RTCRtpReceiver } from "../../src/media/rtpReceiver";
import { MediaStream } from "../../src/media/track";
import { addEventListenerPromise, assert_equals, assert_true } from "../utils";

jest.setTimeout(10_000);


describe("wpt/ontrack", () => {
it("setRemoteDescription should trigger ontrack event when the MSID of the stream is parsed.", async () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/webrtc/tests/wpt/removeTrack.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MediaStreamTrack, RTCPeerConnection } from "../../src";
import { generateAnswer } from "../fixture";

jest.setTimeout(10_000);


// webrtc/RTCPeerConnection-removeTrack.https.html
describe("peerConnection/removeTrack", () => {
Expand Down Expand Up @@ -216,7 +216,7 @@ describe("peerConnection/removeTrack", () => {
});

// todo fix
xtest("Calling removeTrack on a stopped transceiver should be a no-op", async () => {
test.skip("Calling removeTrack on a stopped transceiver should be a no-op", async () => {
const pc = new RTCPeerConnection();

const track = new MediaStreamTrack({ kind: "audio" });
Expand Down
9 changes: 9 additions & 0 deletions packages/webrtc/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
globals: true,
minWorkers: 2,
maxWorkers: 2,
},
});

0 comments on commit d82e9e4

Please sign in to comment.