From e03d46eeb71f56f7f65a14981a997e017dbf2759 Mon Sep 17 00:00:00 2001 From: brandonocasey <brandonocasey@gmail.com> Date: Fri, 2 Jul 2021 11:25:22 -0400 Subject: [PATCH] add test --- src/media-segment-request.js | 6 ++-- test/segment-loader.test.js | 64 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/media-segment-request.js b/src/media-segment-request.js index f51eb3fed..23322a775 100644 --- a/src/media-segment-request.js +++ b/src/media-segment-request.js @@ -361,13 +361,13 @@ const transmuxAndNotify = ({ onEndedTimeline: () => { endedTimelineFn(); }, - onError: ({message}) => { + onError: (message) => { onTransmuxerError(message); }, - onWarn: ({message}) => { + onWarn: (message) => { onTransmuxerWarn(message); }, - onDebug: ({message}) => { + onDebug: (message) => { onTransmuxerDebug(message); }, onDone: (result) => { diff --git a/test/segment-loader.test.js b/test/segment-loader.test.js index d4f049d7e..29bbbfed9 100644 --- a/test/segment-loader.test.js +++ b/test/segment-loader.test.js @@ -902,6 +902,70 @@ QUnit.module('SegmentLoader', function(hooks) { }); }); + QUnit.test('logs warnings, debugs, and errors from the transmuxer', function(assert) { + const playlist = playlistWithDuration(10); + const ogPost = loader.transmuxer_.postMessage; + const messages = []; + + loader.logger_ = (message) => { + messages.push(message); + }; + + loader.transmuxer_.postMessage = (message) => { + if (message.action === 'flush') { + const debug = newEvent('message'); + const error = newEvent('message'); + const warn = newEvent('message'); + + debug.data = {action: 'debug', message: 'debug foo'}; + error.data = {action: 'error', message: 'error foo'}; + warn.data = {action: 'warn', message: 'warning foo'}; + + loader.transmuxer_.dispatchEvent(debug); + loader.transmuxer_.dispatchEvent(error); + loader.transmuxer_.dispatchEvent(warn); + return; + } + return ogPost.call(loader.transmuxer_, message); + }; + + return setupMediaSource(loader.mediaSource_, loader.sourceUpdater_, {isVideoOnly: true}).then(() => { + return new Promise((resolve, reject) => { + loader.one('appended', resolve); + loader.one('error', reject); + + loader.playlist(playlist); + loader.load(); + + this.clock.tick(100); + // segment + standardXHRResponse(this.requests.shift(), videoOneSecondSegment()); + }); + }).then(() => { + let debugFound = false; + let warnFound = false; + let errorFound = false; + + messages.forEach(function(message) { + if ((/debug foo/).test(message)) { + debugFound = true; + } + + if ((/warning foo/).test(message)) { + warnFound = true; + } + + if ((/error foo/).test(message)) { + errorFound = true; + } + }); + + assert.ok(debugFound, 'debug message was logged'); + assert.ok(warnFound, 'warn message was logged'); + assert.ok(errorFound, 'error message was logged'); + }); + }); + QUnit.test('segmentKey will cache new encrypted keys with cacheEncryptionKeys true', function(assert) { loader.cacheEncryptionKeys_ = true;