Skip to content

Commit

Permalink
Improve test logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walch committed Jul 26, 2020
1 parent 383cb7e commit 8b9e876
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/main.js
Expand Up @@ -12,7 +12,7 @@ const STORAGE_KEYS = {
};

const testStreams = require('../tests/test-streams');
const defaultTestStreamUrl = testStreams['bbb'].url;
const defaultTestStreamUrl = testStreams[Object.keys(testStreams)[0]].url;
const sourceURL = decodeURIComponent(getURLParam('src', defaultTestStreamUrl));

let demoConfig = getURLParam('demoConfig', null);
Expand Down
25 changes: 16 additions & 9 deletions tests/functional/auto/setup.js
Expand Up @@ -62,6 +62,7 @@ HttpServer.createServer({
root: './'
}).listen(8000, hostname);

const stringifyResult = (result) => JSON.stringify(result, Object.keys(result).filter(k => k !== 'logs'), 2);
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
async function retry (attempt, numAttempts = 5, interval = 2000) {
try {
Expand All @@ -88,7 +89,7 @@ async function testLoadedData (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('code').which.equals('loadeddata');
expect(result, stringifyResult(result)).to.have.property('code').which.equals('loadeddata');
}

async function testIdleBufferLength (url, config) {
Expand All @@ -114,7 +115,7 @@ async function testIdleBufferLength (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('code').which.equals('loadeddata');
expect(result, stringifyResult(result)).to.have.property('code').which.equals('loadeddata');
}

async function testSmoothSwitch (url, config) {
Expand Down Expand Up @@ -144,7 +145,7 @@ async function testSmoothSwitch (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('currentTimeDelta').which.is.gt(0);
expect(result, stringifyResult(result)).to.have.property('currentTimeDelta').which.is.gt(0);
}

async function testSeekOnLive (url, config) {
Expand All @@ -164,7 +165,7 @@ async function testSeekOnLive (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('code').which.equals('seeked');
expect(result, stringifyResult(result)).to.have.property('code').which.equals('seeked');
}

async function testSeekOnVOD (url, config) {
Expand All @@ -175,6 +176,12 @@ async function testSeekOnVOD (url, config) {
video.onloadeddata = function () {
window.setTimeout(function () {
video.currentTime = video.duration - 5;
// Fail test early if more than 2 buffered ranges are found
video.onprogress = function () {
if (video.buffered.length > 2) {
callback({ code: 'buffer-gaps', bufferedRanges: video.buffered.length, logs: window.logString });
}
};
}, 5000);
};
video.onended = function () {
Expand All @@ -184,7 +191,7 @@ async function testSeekOnVOD (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('code').which.equals('ended');
expect(result, stringifyResult(result)).to.have.property('code').which.equals('ended');
}

async function testSeekEndVOD (url, config) {
Expand All @@ -204,7 +211,7 @@ async function testSeekEndVOD (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('code').which.equals('ended');
expect(result, stringifyResult(result)).to.have.property('code').which.equals('ended');
}

async function testIsPlayingVOD (url, config) {
Expand Down Expand Up @@ -235,7 +242,7 @@ async function testIsPlayingVOD (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('playing').which.is.true;
expect(result, stringifyResult(result)).to.have.property('playing').which.is.true;
}

async function testSeekBackToStart (url, config) {
Expand Down Expand Up @@ -264,7 +271,7 @@ async function testSeekBackToStart (url, config) {
url,
config
);
expect(result, JSON.stringify(result, null, 2)).to.have.property('playing').which.is.true;
expect(result, stringifyResult(result)).to.have.property('playing').which.is.true;
}

describe(`testing hls.js playback in the browser on "${browserDescription}"`, function () {
Expand Down Expand Up @@ -410,7 +417,7 @@ describe(`testing hls.js playback in the browser on "${browserDescription}"`, fu
testIsPlayingVOD.bind(null, url, config)
);
it(
`should seek 5s from end and receive video ended event for ${stream.description}`,
`should seek 5s from end and receive video ended event for ${stream.description} with 2 or less buffered ranges`,
testSeekOnVOD.bind(null, url, config)
);
// it(`should seek on end and receive video ended event for ${stream.description}`, testSeekEndVOD.bind(null, url));
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/auto/testbench.js
Expand Up @@ -92,7 +92,7 @@ function startStream (streamUrl, config, callback, autoplay) {
var playPromise = video.play();
if (playPromise) {
playPromise.catch(function (error) {
console.log('[test] > video.play() failed with error:', error);
console.log('[test] > video.play() failed with error: ' + error.name + ' ' + error.message);
if (error.name === 'NotAllowedError') {
console.log('[test] > Attempting to play with video muted');
video.muted = true;
Expand Down

0 comments on commit 8b9e876

Please sign in to comment.