Skip to content

Commit

Permalink
chore: Add test for parse exception if no vtt.js is loaded for any re…
Browse files Browse the repository at this point in the history
…ason
  • Loading branch information
Dzianis Dashkevich committed Jan 18, 2023
1 parent ac94bb7 commit 5b877a9
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions test/vtt-segment-loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from './loader-common.js';
import { encryptionKey, subtitlesEncrypted } from 'create-test-data!segments';
import {merge, createTimeRanges} from '../src/util/vjs-compat';
import sinon from 'sinon';

const oldVTT = window.WebVTT;

Expand Down Expand Up @@ -367,6 +368,52 @@ QUnit.module('VTTSegmentLoader', function(hooks) {
}
);

QUnit.test(
'parse should throw if no vtt.js is loaded for any reason',
function(assert) {
const vttjs = window.WebVTT;
const playlist = playlistWithDuration(40);
let errors = 0;

const originalParse = loader.parseVTTCues_.bind(loader);

loader.parseVTTCues_ = (...args) => {
delete window.WebVTT;
return originalParse(...args);
};

const spy = sinon.spy(loader, 'error');

loader.on('error', () => errors++);

loader.playlist(playlist);
loader.track(this.track);
loader.load();

assert.equal(errors, 0, 'no error at loader start');

this.clock.tick(1);

// state WAITING for segment response
this.requests[0].responseType = 'arraybuffer';
this.requests.shift().respond(200, null, new Uint8Array(10).buffer);

this.clock.tick(1);

assert.equal(errors, 1, 'triggered error when parser emmitts fatal error');
assert.ok(loader.paused(), 'loader paused when encountering fatal error');
assert.equal(loader.state, 'READY', 'loader reset after error');
assert.ok(
spy.withArgs(sinon.match({
message: 'Trying to parse received VTT cues, but there is no WebVTT. Make sure vtt.js is loaded.'
})).calledOnce,
'error method called once with instance of NoVttJsError'
);

window.WebVTT = vttjs;
}
);

QUnit.test(
'uses timestampmap from vtt header to set cue and segment timing',
function(assert) {
Expand Down

0 comments on commit 5b877a9

Please sign in to comment.