Skip to content

Commit

Permalink
Replace expect with assert for new tests picked from master
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bartos committed Mar 11, 2019
1 parent fba8fe3 commit 8a244d1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 67 deletions.
41 changes: 21 additions & 20 deletions tests/unit/controller/level-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as LevelHelper from '../../../src/controller/level-helper';
import Level from '../../../src/loader/level';
import Fragment from '../../../src/loader/fragment';
import sinon from 'sinon';
const assert = require('assert');

const generatePlaylist = (sequenceNumbers) => {
const playlist = new Level('');
Expand Down Expand Up @@ -43,44 +44,44 @@ describe('LevelHelper Tests', function () {
const oldPlaylist = generatePlaylist([1, 2, 3, 4, 5]);
const newPlaylist = generatePlaylist([3, 4, 5, 6, 7]);
const actual = getIteratedSequence(oldPlaylist, newPlaylist);
expect(actual).to.deep.equal([3, 4, 5]);
assert.deepEqual(actual, [3, 4, 5]);
});

it('can iterate with one overlapping fragment', function () {
const oldPlaylist = generatePlaylist([1, 2, 3, 4, 5]);
const newPlaylist = generatePlaylist([5, 6, 7, 8, 9]);
const actual = getIteratedSequence(oldPlaylist, newPlaylist);
expect(actual).to.deep.equal([5]);
assert.deepEqual(actual, [5]);
});

it('can iterate over the entire segment array', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([1, 2, 3]);
const actual = getIteratedSequence(oldPlaylist, newPlaylist);
expect(actual).to.deep.equal([1, 2, 3]);
assert.deepEqual(actual, [1, 2, 3]);
});

it('can iterate when overlapping happens at the start of the old playlist', function () {
const oldPlaylist = generatePlaylist([5, 6, 7, 8]);
const newPlaylist = generatePlaylist([3, 4, 5, 6]);
const actual = getIteratedSequence(oldPlaylist, newPlaylist);
expect(actual).to.deep.equal([5, 6]);
assert.deepEqual(actual, [5, 6]);
});

it('never executes the callback if no intersection exists', function () {
const oldPlaylist = generatePlaylist([1, 2, 3, 4, 5]);
const newPlaylist = generatePlaylist([10, 11, 12]);
const actual = getIteratedSequence(oldPlaylist, newPlaylist);
expect(actual).to.deep.equal([]);
assert.deepEqual(actual, []);
});

it('exits early if either playlist does not exist', function () {
let oldPlaylist = null;
let newPlaylist = generatePlaylist([10, 11, 12]);
expect(getIteratedSequence(oldPlaylist, newPlaylist)).to.deep.equal([]);
assert.deepEqual(getIteratedSequence(oldPlaylist, newPlaylist), []);
oldPlaylist = newPlaylist;
newPlaylist = null;
expect(getIteratedSequence(oldPlaylist, newPlaylist)).to.deep.equal([]);
assert.deepEqual(getIteratedSequence(oldPlaylist, newPlaylist), []);
});
});

Expand All @@ -91,15 +92,15 @@ describe('LevelHelper Tests', function () {
const newPlaylist = generatePlaylist([3, 4, 5]);
LevelHelper.adjustSliding(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map(f => f.start);
expect(actual).to.deep.equal([10, 15, 20]);
assert.deepEqual(actual, [10, 15, 20]);
});

it('does not apply sliding if no common segments exist', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([5, 6, 7]);
LevelHelper.adjustSliding(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map(f => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
assert.deepEqual(actual, [0, 5, 10]);
});
});

Expand All @@ -109,23 +110,23 @@ describe('LevelHelper Tests', function () {
const newPlaylist = generatePlaylist([2, 3, 4, 5]);
LevelHelper.mergeSubtitlePlaylists(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map(f => f.start);
expect(actual).to.deep.equal([5, 10, 15, 20]);
assert.deepEqual(actual, [5, 10, 15, 20]);
});

it('does not change start times when there is no segment overlap', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([5, 6, 7]);
LevelHelper.mergeSubtitlePlaylists(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map(f => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
assert.deepEqual(actual, [0, 5, 10]);
});

it('adjusts sliding using the reference start if there is no segment overlap', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([5, 6, 7]);
LevelHelper.mergeSubtitlePlaylists(oldPlaylist, newPlaylist, 30);
const actual = newPlaylist.fragments.map(f => f.start);
expect(actual).to.deep.equal([30, 35, 40]);
assert.deepEqual(actual, [30, 35, 40]);
});

it('does not extrapolate if the new playlist starts before the old', function () {
Expand All @@ -136,7 +137,7 @@ describe('LevelHelper Tests', function () {
const newPlaylist = generatePlaylist([1, 2, 3]);
LevelHelper.mergeSubtitlePlaylists(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map(f => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
assert.deepEqual(actual, [0, 5, 10]);
});
});

Expand All @@ -146,7 +147,7 @@ describe('LevelHelper Tests', function () {
const newPlaylist = generatePlaylist([3, 4]);
newPlaylist.averagetargetduration = 5;
const actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, null);
expect(actual).to.equal(5000);
assert.strictEqual(actual, 5000);
});

it('returns the targetduration of the new level if averagetargetduration is falsy', function () {
Expand All @@ -155,27 +156,27 @@ describe('LevelHelper Tests', function () {
newPlaylist.averagetargetduration = null;
newPlaylist.targetduration = 4;
let actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, null);
expect(actual).to.equal(4000);
assert.strictEqual(actual, 4000);

newPlaylist.averagetargetduration = null;
actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, null);
expect(actual).to.equal(4000);
assert.strictEqual(actual, 4000);
});

it('halves the reload interval if the playlist contains the same segments', function () {
const oldPlaylist = generatePlaylist([1, 2]);
const newPlaylist = generatePlaylist([1, 2]);
newPlaylist.averagetargetduration = 5;
const actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, null);
expect(actual).to.equal(2500);
assert.strictEqual(actual, 2500);
});

it('rounds the reload interval', function () {
const oldPlaylist = generatePlaylist([1, 2]);
const newPlaylist = generatePlaylist([3, 4]);
newPlaylist.averagetargetduration = 5.9999;
const actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, null);
expect(actual).to.equal(6000);
assert.strictEqual(actual, 6000);
});

it('subtracts the request time of the last level load from the reload interval', function () {
Expand All @@ -186,7 +187,7 @@ describe('LevelHelper Tests', function () {
const clock = sandbox.useFakeTimers();
clock.tick(2000);
const actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, 1000);
expect(actual).to.equal(4000);
assert.strictEqual(actual, 4000);
});

it('returns a minimum of half the target duration', function () {
Expand All @@ -197,7 +198,7 @@ describe('LevelHelper Tests', function () {
const clock = sandbox.useFakeTimers();
clock.tick(9000);
const actual = LevelHelper.computeReloadInterval(oldPlaylist, newPlaylist, 1000);
expect(actual).to.equal(2500);
assert.strictEqual(actual, 2500);
});
});
});
27 changes: 14 additions & 13 deletions tests/unit/controller/subtitle-stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Hls from '../../../src/hls';
import Event from '../../../src/events';
import { FragmentTracker } from '../../../src/controller/fragment-tracker';
import { SubtitleStreamController } from '../../../src/controller/subtitle-stream-controller';
const assert = require('assert');

const mediaMock = {
currentTime: 0,
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('SubtitleStreamController', function () {
});

it('should update tracks list', function () {
expect(subtitleStreamController.tracks).to.equal(tracksMock);
assert.strictEqual(subtitleStreamController.tracks, tracksMock);
});
});

Expand All @@ -57,22 +58,22 @@ describe('SubtitleStreamController', function () {
});

it('should call setInterval if details available', function () {
expect(subtitleStreamController.setInterval).to.have.been.calledOnce;
assert.strictEqual(subtitleStreamController.setInterval.callCount, 1);
});

it('should call clearInterval if no tracks present', function () {
subtitleStreamController.tracks = null;
hls.trigger(Event.SUBTITLE_TRACK_SWITCH, {
id: 0
});
expect(subtitleStreamController.clearInterval).to.have.been.calledOnce;
assert.strictEqual(subtitleStreamController.clearInterval.callCount, 1);
});

it('should call clearInterval if new track id === -1', function () {
hls.trigger(Event.SUBTITLE_TRACK_SWITCH, {
id: -1
});
expect(subtitleStreamController.clearInterval).to.have.been.calledOnce;
assert.strictEqual(subtitleStreamController.clearInterval.callCount, 1);
});
});

Expand All @@ -89,8 +90,8 @@ describe('SubtitleStreamController', function () {
hls.trigger(Event.SUBTITLE_TRACK_LOADED, {
id: 1, details
});
expect(subtitleStreamController.tracks[1].details).to.equal(details);
expect(subtitleStreamController.setInterval).to.have.been.calledOnce;
assert.strictEqual(subtitleStreamController.tracks[1].details, details);
assert.strictEqual(subtitleStreamController.setInterval.callCount, 1);
});

it('should ignore the event if the data does not match the current track', function () {
Expand All @@ -99,8 +100,8 @@ describe('SubtitleStreamController', function () {
hls.trigger(Event.SUBTITLE_TRACK_LOADED, {
id: 1, details
});
expect(subtitleStreamController.tracks[0].details).to.not.equal(details);
expect(subtitleStreamController.setInterval).to.not.have.been.called;
assert.strictEqual(subtitleStreamController.tracks[0].details !== details, true);
assert.strictEqual(subtitleStreamController.setInterval.callCount, 0);
});

it('should ignore the event if there are no tracks, or the id is not within the tracks array', function () {
Expand All @@ -110,8 +111,8 @@ describe('SubtitleStreamController', function () {
hls.trigger(Event.SUBTITLE_TRACK_LOADED, {
id: 0, details
});
expect(subtitleStreamController.tracks[0]).to.not.exist;
expect(subtitleStreamController.setInterval).to.not.have.been.called;
assert.strictEqual(subtitleStreamController.tracks[0], undefined);
assert.strictEqual(subtitleStreamController.setInterval.callCount, 0);
});
});

Expand All @@ -120,20 +121,20 @@ describe('SubtitleStreamController', function () {
hls.trigger(Event.LEVEL_UPDATED, {
details: { fragments: [{ start: 5 }] }
});
expect(subtitleStreamController.lastAVStart).to.equal(5);
assert.strictEqual(subtitleStreamController.lastAVStart, 5);

hls.trigger(Event.LEVEL_UPDATED, {
details: { fragments: [] }
});
expect(subtitleStreamController.lastAVStart).to.equal(0);
assert.strictEqual(subtitleStreamController.lastAVStart, 0);
});
});

describe('onMediaSeeking', function () {
it('nulls fragPrevious', function () {
subtitleStreamController.fragPrevious = {};
subtitleStreamController.onMediaSeeking();
expect(subtitleStreamController.fragPrevious).to.not.exist;
assert.strictEqual(subtitleStreamController.fragPrevious, null);
});
});
});
Loading

0 comments on commit 8a244d1

Please sign in to comment.