Skip to content

Commit

Permalink
test: add StreamController unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Feb 2, 2018
1 parent c2d125e commit 9d314df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/controller/stream-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {logger} from '../utils/logger';
import { alignDiscontinuities } from '../utils/discontinuities';
import TaskLoop from '../task-loop';

const State = {
export const State = {
STOPPED : 'STOPPED',
IDLE : 'IDLE',
KEY_LOADING : 'KEY_LOADING',
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/controller/stream-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import assert from "assert";
import sinon from "sinon";
import Hls from "../../../src/hls";
import Event from "../../../src/events";
import { FragmentTracker } from "../../../src/helper/fragment-tracker";
import StreamController, { State } from "../../../src/controller/stream-controller";

/**
* @returns {{hls: Hls, streamController: StreamController}}
*/
const createStreamController = () => {
const hls = new Hls({});
const fragmentTracker = new FragmentTracker(hls);
return {
hls,
streamController: new StreamController(hls, fragmentTracker)
};
};

describe("StreamController", function() {
it("initial state should be STOPPED", function() {
const { streamController } = createStreamController();
assert.equal(streamController.state, State.STOPPED);
});
it("should trigger STREAM_STATE_TRANSITION when state is updated", function() {
const { hls, streamController } = createStreamController();
const spy = sinon.spy();
hls.on(Event.STREAM_STATE_TRANSITION, spy);
streamController.state = State.ENDED;
assert.deepEqual(spy.args[0][1], { previousState: State.STOPPED, nextState: State.ENDED });
});
});

0 comments on commit 9d314df

Please sign in to comment.