Skip to content

Commit

Permalink
Add Unit Tests for WebRTC Troubleshooter.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelmont committed May 10, 2017
1 parent 6bd8e40 commit 1b672c5
Show file tree
Hide file tree
Showing 26 changed files with 1,310 additions and 56 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo_token: Oa8nW7MOfdcUA0mvv7zHyYgmWXOHSCRbV
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ node_modules/
bower_components/
.idea
npm-debug.log
.vscode
/coverage
/.nyc_output
2 changes: 0 additions & 2 deletions .jshintignore

This file was deleted.

20 changes: 0 additions & 20 deletions .jshintrc

This file was deleted.

8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dist: trusty
sudo: required
language: node_js
node_js:
- 6
after_success:
- npm run coverage
- npm run coveralls
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# webrtc-troubleshooter

[![Build Status](https://travis-ci.org/MyPureCloud/webrtc-troubleshooter.svg?branch=master)](https://travis-ci.org/MyPureCloud/webrtc-troubleshooter)
[![Coverage Status](https://coveralls.io/repos/github/MyPureCloud/webrtc-troubleshooter/badge.svg?branch=master)](https://coveralls.io/github/MyPureCloud/webrtc-troubleshooter?branch=master)

#### PSA

This addon is still under development and not *quite* ready for use.
Expand All @@ -17,6 +20,12 @@ TODO:
* Serve with your favorite [stupid server](https://www.npmjs.com/package/stupid-server)
* `npm test`

# Scripts

* `FILE=advanced-camera-test.js npm run unit-test-file` to run a single test file
* Alternatively run `./node_modules/.bin/ava test/unit/advanced-camera-test.js` for an individual test
* `npm run coverage` runs the code coverage report
* `npm test` will run both lint and all the unit-test and report coverage in text form in command line

# Test Page

Expand Down
15 changes: 8 additions & 7 deletions dist/webrtc-troubleshooter.bundle.js

Large diffs are not rendered by default.

42 changes: 39 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,63 @@
"version": "3.1.1",
"description": "A way to add webrtc troubleshooting to your app",
"main": "src/index.js",
"config": {
"report": "report --reporter=lcov"
},
"scripts": {
"browserify": "node_modules/.bin/browserify -t [ babelify --presets [ es2015 ] ] --s WebRTCTroubleshooter src/index.js -o dist/webrtc-troubleshooter.bundle.js",
"uglify": "node_modules/.bin/uglifyjs dist/webrtc-troubleshooter.bundle.js -o dist/webrtc-troubleshooter.bundle.js",
"browserify": "browserify -t [ babelify --presets [ es2015 ] ] --s WebRTCTroubleshooter src/index.js -o dist/webrtc-troubleshooter.bundle.js",
"uglify": "uglifyjs dist/webrtc-troubleshooter.bundle.js -o dist/webrtc-troubleshooter.bundle.js",
"build": "npm run browserify && npm run uglify",
"test": "node_modules/.bin/semistandard src/utils/**/*.js test-page/**/*.js"
"lint": "semistandard",
"lint:fix": "semistandard --fix",
"unit-test": "nyc ava test/unit/*.js",
"postunit-test": "nyc $npm_package_config_report",
"unit-test-file": "ava FILE=process.env.file test/unit/${FILE}",
"coverage": "nyc ava test/unit/*.js",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"test": "npm run lint && npm run unit-test"
},
"repository": "https://github.com/mypurecloud/webrtc-troubleshooter",
"engines": {
"node": ">= 4.4.0"
},
"devDependencies": {
"ava": "^0.19.1",
"babel-cli": "^6.22.2",
"babel-preset-es2015": "^6.22.0",
"babelify": "^7.2.0",
"browser-env": "^2.0.31",
"browserify": "^14.0.0",
"coveralls": "^2.13.1",
"nyc": "^10.3.2",
"semistandard": "^10.0.0",
"sinon": "^2.2.0",
"uglify-js": "^2.7.3"
},
"dependencies": {
"localmedia": "^3.0.0",
"rtcpeerconnection": "~7.0.0",
"webrtc-adapter": "^3.1.1"
},
"babel": {
"presets": [
"es2015"
]
},
"ava": {
"concurrency": 5,
"failFast": true,
"failWithoutAssertions": false,
"tap": true,
"powerAssert": false,
"require": [
"babel-register",
"./test/helpers/setup-browser-env.js"
]
},
"semistandard": {
"ignore": [
"**/dist"
]
}
}
14 changes: 7 additions & 7 deletions src/defaultTests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import AudioTest from './tests/AudioTest';
import VideoTest from './tests/VideoTest';
import ConnectivityTest from './tests/ConnectivityTest';
import AdvancedCameraTest from './tests/AdvancedCameraTest';
import ThroughputTest from './tests/DataThroughputTest';
import VideoBandwidthTest from './tests/VideoBandwidthTest';
import AudioBandwidthTest from './tests/AudioBandwidthTest';
import AudioTest from './diagnostics/AudioTest';
import VideoTest from './diagnostics/VideoTest';
import ConnectivityTest from './diagnostics/ConnectivityTest';
import AdvancedCameraTest from './diagnostics/AdvancedCameraTest';
import ThroughputTest from './diagnostics/DataThroughputTest';
import VideoBandwidthTest from './diagnostics/VideoBandwidthTest';
import AudioBandwidthTest from './diagnostics/AudioBandwidthTest';

export { AudioTest, VideoTest, ConnectivityTest, AdvancedCameraTest, ThroughputTest, VideoBandwidthTest, AudioBandwidthTest };
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TestSuite from '../utils/TestSuite';
import VideoFrameChecker from '../utils/VideoFrameChecker';
import WebrtcCall from '../utils/WebrtcCall';
// import VideoFrameChecker from '../utils/VideoFrameChecker';
// import WebrtcCall from '../utils/WebrtcCall';
import CameraResolutionTest from './CameraResolutionTest';

export default class AdvancedCameraTest extends TestSuite {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Test from '../utils/Test';
import StatisticsAggregate from '../utils/StatisticsAggregate';

export default class AudioBandwidthTest extends Test {
constructor() {
constructor () {
super(...arguments);
this.name = 'Bandwidth Test';
this.maxAudioBitrateKbps = 510;
Expand All @@ -31,7 +31,7 @@ export default class AudioBandwidthTest extends Test {
this.stats = {};
}

start() {
start () {
super.start();

if (!this.options.iceConfig.iceServers.length) {
Expand Down Expand Up @@ -60,17 +60,17 @@ export default class AudioBandwidthTest extends Test {
});
}

getResults() {
getResults () {
return {
log: this.log,
stats: this.stats,
constraints: this.constraints
};
}

addLog(level, msg) {
addLog (level, msg) {
this.logger[level.toLowerCase()](msg);
if (msg && typeof msg === 'Object') {
if (msg && typeof msg === 'object') {
msg = JSON.stringify(msg);
}
if (level === 'error') {
Expand All @@ -79,7 +79,7 @@ export default class AudioBandwidthTest extends Test {
this.log.push(`${level}: ${msg}`);
}

doGetUserMedia(constraints) {
doGetUserMedia (constraints) {
this.addLog('info', { status: 'pending', constraints });
return navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
Expand All @@ -94,14 +94,14 @@ export default class AudioBandwidthTest extends Test {
});
}

getDeviceName(tracks) {
getDeviceName (tracks) {
if (tracks.length === 0) {
return null;
}
return tracks[0].label;
}

setupCall(stream) {
setupCall (stream) {
this.call.pc1.addStream(stream);
return this.call.establishConnection().then(() => {
this.addLog('info', { status: 'success', message: 'establishing connection' });
Expand All @@ -113,7 +113,7 @@ export default class AudioBandwidthTest extends Test {
});
}

runTest() {
runTest () {
return new Promise((resolve, reject) => {
this.nextTimeout = setTimeout(() => {
this.gatherStats().then(resolve, reject);
Expand All @@ -131,7 +131,7 @@ export default class AudioBandwidthTest extends Test {
.catch((error) => this.addLog('error', 'Failed to getStats: ' + error));
}

gotStats(response) {
gotStats (response) {
const isWebkit = 'WebkitAppearance' in document.documentElement.style;
const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
if (isWebkit) {
Expand Down Expand Up @@ -167,13 +167,13 @@ export default class AudioBandwidthTest extends Test {
}
} else {
this.addLog('error', 'Only Firefox and Chrome getStats implementations are supported.');
return Promise.reject()
return Promise.reject(new Error('Only Firefox and Chrome getStats implementations are supported.'));
}

return this.runTest();
}

completed() {
completed () {
const stats = this.stats;

stats.mbpsAvg = this.bweStats.getAverage() / (1000 * 1000);
Expand All @@ -199,7 +199,7 @@ export default class AudioBandwidthTest extends Test {
return this.results;
}

destroy() {
destroy () {
super.destroy();
window.clearTimeout(this.nextTimeout);
if (this.call) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class VideoBandwidthTest extends Test {

addLog (level, msg) {
this.logger[level.toLowerCase()](msg);
if (msg && typeof msg === 'Object') {
if (msg && typeof msg === 'object') {
msg = JSON.stringify(msg);
}
if (level === 'error') {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/VideoTest.js → src/diagnostics/VideoTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Test from '../utils/Test';
const LocalMedia = require('localmedia');

export default class VideoTest extends Test {
constructor() {
constructor () {
super(...arguments);
this.name = 'Video Test';

Expand Down
2 changes: 2 additions & 0 deletions src/utils/WebrtcCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class WebrtcCall {
resolve({stats, statsCollectTime});
}, 1000);
peerConnection.getStats(null).then((response) => {
console.log('inside:::');
console.log(response);
clearTimeout(getStatsTimeout);
getStatsTimeout = null;
gotStats(response);
Expand Down
2 changes: 2 additions & 0 deletions test/helpers/setup-browser-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import browserEnv from 'browser-env';
browserEnv();
34 changes: 34 additions & 0 deletions test/unit/advanced-camera-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import test from 'ava';

import AdvancedCameraTest from '../../src/diagnostics/AdvancedCameraTest';

let CameraResolutionStub, options, advancedCameraTest;
test.before(() => {
CameraResolutionStub = {
resolutions: [
[320, 240]
],
start: Promise.resolve([320, 240]),
deferred: {
resolve: () => [320, 240],
reject: () => 'an error'
}
};
options = {
mediaStream: document.createElement('video').mediaStream,
duration: 5,
addTest: () => {},
runNextTest: () => {},
deferred: {
resolve: () => [320, 240],
reject: () => 'received error'
},
stopAllTests: () => {}
};
advancedCameraTest = new AdvancedCameraTest(options);
});

test('start() will return undefined if no more tests', async t => {
const actual = await advancedCameraTest.start.call(CameraResolutionStub);
t.is(actual, undefined);
});

0 comments on commit 1b672c5

Please sign in to comment.