Skip to content

Commit

Permalink
Start
Browse files Browse the repository at this point in the history
  • Loading branch information
havardholvik committed Oct 31, 2023
1 parent 9b2215f commit 036845c
Show file tree
Hide file tree
Showing 17 changed files with 1,879 additions and 1,954 deletions.
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"parser": "@babel/eslint-parser",
"env": {
"jest/globals": true,
"browser": true,
"es6": true,
"mocha": true
"es6": true
},
"extends": ["@whereby/eslint-config/browser", "prettier"],
"parserOptions": {
"sourceType": "module",
"requireConfigFile": false
},
"plugins": ["mocha-no-only", "prettier"],
"plugins": ["prettier", "jest"],
"rules": {
"no-console": ["error", { "allow": ["warn", "error"] }],
"prettier/prettier": "error"
Expand Down
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
testEnvironment: "jsdom",
testMatch: ["<rootDir>/tests/**/?(*.)+(spec|test).[jt]s?(x)"],
roots: ["<rootDir>"],
};
37 changes: 12 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@whereby/jslib-media",
"description": "Media library for Whereby",
"version": "1.3.5",
"version": "1.3.6",
"private": false,
"license": "MIT",
"homepage": "https://github.com/whereby/jslib-media",
Expand All @@ -15,7 +15,7 @@
"scripts": {
"lint": "eslint src tests config",
"test": "npm run lint && npm run test:unit",
"test:unit": "karma start config/karma.conf.js",
"test:unit": "jest",
"format:fix": "prettier --write './**/*.{js,ts,yml,json}'",
"format:check": "prettier --check './**/*.{js,ts,yml,json}'"
},
Expand All @@ -31,39 +31,26 @@
"webrtc-adapter": "^7.3.0"
},
"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/core": "^7.23.2",
"@babel/eslint-parser": "^7.22.15",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8",
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
"@babel/preset-env": "^7.12.13",
"@babel/preset-env": "^7.23.2",
"@whereby/auto-config": "0.0.2",
"@whereby/eslint-config": "5.0.4",
"babel-loader": "^9.1.3",
"babel-plugin-rewire-exports": "^2.3.0",
"chai": "^4.0.2",
"chai-as-promised": "^7.1.1",
"dirty-chai": "^2.0.0",
"babel-jest": "^29.7.0",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-mocha-no-only": "^1.1.1",
"eslint-plugin-prettier": "^5.0.0",
"i18n-iso-countries": "^7.7.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^6.1.0",
"karma-babel-preprocessor": "^8.0.1",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-mocha": "^2.0.1",
"karma-webpack": "^5.0.0",
"libphonenumber-js": "^1.9.7",
"mocha": "^10.2.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "3.0.3",
"process": "^0.11.10",
"sinon": "^16.0.0",
"sinon-chai": "^3.7.0",
"webpack": "^5.69.1"
"process": "^0.11.10"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"engines": {
"node": ">=16.0.0"
}
}
1 change: 1 addition & 0 deletions src/webrtc/VegaRtcManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { maybeTurnOnly } from "../utils/transportSettings";

const logger = console;
const browserName = adapter.browserDetails.browser;

let unloading = false;

const RESTARTICE_ERROR_RETRY_THRESHOLD_IN_MS = 3500;
Expand Down
2 changes: 1 addition & 1 deletion tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function itShouldThrowIfMissing(missingPropertyName, fn) {
it(`should throw if ${scenario}`, () => {
expect(() => {
fn();
}).to.throw(expectedException);
}).toThrow(expectedException);
});
}

Expand Down
48 changes: 24 additions & 24 deletions tests/model/RtcStream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,34 @@ describe("RtcStream", () => {
it("should throw error if id is null", () => {
expect(() => {
new RtcStream(null, STREAM_TYPES.SCREEN_SHARE); //eslint-disable-line no-new
}).to.throw("id is required");
}).toThrow("id is required");
});

it("should throw error if id is undefined", () => {
expect(() => {
new RtcStream(undefined, STREAM_TYPES.SCREEN_SHARE); //eslint-disable-line no-new
}).to.throw("id is required");
}).toThrow("id is required");
});

it("should throw error if type is missing", () => {
expect(() => {
new RtcStream("1"); //eslint-disable-line no-new
}).to.throw("type is required");
}).toThrow("type is required");
});

it("should create a stream with a string id if the specified id is a number", () => {
const stream = new RtcStream(1, STREAM_TYPES.SCREEN_SHARE);

expect(stream.id).to.deep.equals("1");
expect(stream.id).toEqual("1");
});

it("should create a stream with the specified id and type", () => {
const streamId = "1";
const streamType = STREAM_TYPES.SCREEN_SHARE;
const stream = new RtcStream(streamId, streamType);

expect(stream.id).to.deep.equals(streamId);
expect(stream.type).to.deep.equals(streamType);
expect(stream.id).toEqual(streamId);
expect(stream.type).toEqual(streamType);
});
});

Expand All @@ -42,29 +42,29 @@ describe("RtcStream", () => {

beforeEach(() => {
fakeStream = {
getVideoTracks: sinon.stub().returns([{ enabled: true }]),
getAudioTracks: sinon.stub().returns([{ enabled: true }]),
getVideoTracks: jest.fn().mockReturnValue([{ enabled: true }]),
getAudioTracks: jest.fn().mockReturnValue([{ enabled: true }]),
};
});

it("applies isVideoEnabled state override from earlier", () => {
const stream = new RtcStream("id", "type");
stream.isVideoEnabled = false;
sinon.spy(stream, "setVideoEnabled");
jest.spyOn(stream, "setVideoEnabled");

stream.setup(fakeStream);

expect(stream.setVideoEnabled).to.have.been.calledWithExactly(false);
expect(stream.setVideoEnabled).toHaveBeenCalledWith(false);
});

it("applies isAudioEnabled state override from earlier", () => {
const stream = new RtcStream("id", "type");
stream.isAudioEnabled = false;
sinon.spy(stream, "setAudioEnabled");
jest.spyOn(stream, "setAudioEnabled");

stream.setup(fakeStream);

expect(stream.setAudioEnabled).to.have.been.calledWithExactly(false);
expect(stream.setAudioEnabled).toHaveBeenCalledWith(false);
});
});
});
Expand All @@ -74,31 +74,31 @@ describe("RtcStream", () => {
beforeEach(() => {
stream = new RtcStream("id", STREAM_TYPES.CAMERA);
stream.stream = {
getAudioTracks: sinon.stub().returns([]),
getVideoTracks: sinon.stub().returns([]),
getAudioTracks: jest.fn().mockReturnValue([]),
getVideoTracks: jest.fn().mockReturnValue([]),
};
});

it("defaults to being true", () => {
expect(stream.isAudioEnabled).to.equal(true);
expect(stream.isAudioEnabled).toEqual(true);
});

it("sets isAudioEnabled to the given value", () => {
const expectedValue = false;

stream.setAudioEnabled(expectedValue);

expect(stream.isAudioEnabled).to.equal(expectedValue);
expect(stream.isAudioEnabled).toEqual(expectedValue);
});

it("sets each stream's track' enabled property", () => {
const track = {};
stream.stream.getAudioTracks = sinon.stub().returns([track]);
stream.stream.getAudioTracks = jest.fn().mockReturnValue([track]);

const expectedValue = true;
stream.setAudioEnabled(expectedValue);

expect(track.enabled).to.equal(expectedValue);
expect(track.enabled).toEqual(expectedValue);
});
});

Expand All @@ -107,31 +107,31 @@ describe("RtcStream", () => {
beforeEach(() => {
stream = new RtcStream("id", STREAM_TYPES.CAMERA);
stream.stream = {
getAudioTracks: sinon.stub().returns([]),
getVideoTracks: sinon.stub().returns([]),
getAudioTracks: jest.fn().mockReturnValue([]),
getVideoTracks: jest.fn().mockReturnValue([]),
};
});

it("defaults to being true", () => {
expect(stream.isVideoEnabled).to.equal(true);
expect(stream.isVideoEnabled).toEqual(true);
});

it("sets isVideoEnabled to the given value", () => {
const expectedValue = false;

stream.setVideoEnabled(expectedValue);

expect(stream.isVideoEnabled).to.equal(expectedValue);
expect(stream.isVideoEnabled).toEqual(expectedValue);
});

it("sets each stream's track' enabled property", () => {
const track = {};
stream.stream.getVideoTracks = sinon.stub().returns([track]);
stream.stream.getVideoTracks = jest.fn().mockReturnValue([track]);

const expectedValue = true;
stream.setVideoEnabled(expectedValue);

expect(track.enabled).to.equal(expectedValue);
expect(track.enabled).toEqual(expectedValue);
});
});
});
17 changes: 8 additions & 9 deletions tests/utils/ServerSocket.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,37 @@ describe("ServerSocket", () => {

beforeEach(() => {
serverSocket = new ServerSocket("https://localhost");
sinon.stub(serverSocket._socket, "on");
sinon.stub(serverSocket._socket, "off");
jest.spyOn(serverSocket._socket, "on");
jest.spyOn(serverSocket._socket, "off");
});

afterEach(() => {
serverSocket._socket.on.restore();
serverSocket._socket.off.restore();
jest.clearAllMocks();
});

it("should attach an event listener to the internal socket", () => {
const eventName = "some event";
const handler = sinon.stub();
const handler = jest.fn();

serverSocket.on(eventName, handler);

expect(serverSocket._socket.on).to.be.calledWithExactly(eventName, handler);
expect(serverSocket._socket.on).toHaveBeenCalledWith(eventName, handler);
});

it("should return a deregistering function", () => {
const deregisterHandler = serverSocket.on("event", () => {});

expect(deregisterHandler).to.be.instanceOf(Function);
expect(deregisterHandler).toBeInstanceOf(Function);
});

it("should return a deregistering function which will remove the listener", () => {
const eventName = "some event";
const handler = sinon.stub();
const handler = jest.fn();

const deregisterHandler = serverSocket.on(eventName, handler);
deregisterHandler();

expect(serverSocket._socket.off).to.be.calledWithExactly(eventName, handler);
expect(serverSocket._socket.off).toHaveBeenCalledWith(eventName, handler);
});
});
});
Loading

0 comments on commit 036845c

Please sign in to comment.