Skip to content

Commit

Permalink
[update] add test but it fail
Browse files Browse the repository at this point in the history
  • Loading branch information
toxic-johann committed Nov 7, 2017
1 parent 0390c5b commit 929efbf
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 16 deletions.
18 changes: 18 additions & 0 deletions __tests__/bugfix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Chimee from 'index';
import chimeeKernelFlv from 'chimee-kernel-flv';
test('redudant event bind on video', () => {
const wrapper = document.createElement('div');
const fn = jest.fn();
Expand Down Expand Up @@ -38,3 +39,20 @@ test('non extendable should not be set on dispatcher.plugins', () => {
plugin: ['nonextendablePlugins']
})).not.toThrow();
});

test('load should use default preset and kernels if people do not pass one', () => {
const wrapper = document.createElement('div');
const chimee = new Chimee({
src:
'http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv',
isLive: false,
kernels: {
flv: chimeeKernelFlv
},
// 编解码容器
box: 'flv', // flv hls native
// dom容器
wrapper,
});
expect(() => chimee.load('http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv')).not.toThrow();
});
4 changes: 2 additions & 2 deletions __tests__/dispatcher/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('dispatcher/plugin', () => {
}
};
dispatcher.dom = new Dom(wrapper, dispatcher);
dispatcher.videoConfig = new VideoConfig(dispatcher, {})
dispatcher.videoConfig = new VideoConfig(dispatcher, {});
dispatcher.bus = new Bus(dispatcher);
Log.data.error = [];
Log.data.warn = [];
Expand Down Expand Up @@ -665,7 +665,7 @@ describe('dispatcher/plugin', () => {
const plugin = new Plugin({
id: 'err',
inited () {
return new Promise(() => {throw error;})
return new Promise(() => {throw error;});
}
}, dispatcher);
let catcherr = false;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Chimee from 'index';
import {Log, getAttr, setAttr} from 'chimee-helper';
import {videoReadOnlyProperties} from 'helper/const';
import esFullscreen from 'es-fullscreen';
import chimeeKernelFlv from 'chimee-kernel-flv';
// import chimeeKernelFlv from 'chimee-kernel-flv';

describe('Chimee', () => {
const normalInstall = {
Expand Down
34 changes: 34 additions & 0 deletions __tests__/silentload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Chimee from 'index';
import ChimeeKernelHls from 'chimee-kernel-hls';
// import ChimeeKernelFlv from 'chimee-kernel-flv';
import {bind, Log} from 'chimee-helper';
describe('$silentLoad', () => {
let player;
Expand Down Expand Up @@ -29,6 +30,39 @@ describe('$silentLoad', () => {
global.document.createElement = originFn;
player.destroy();
});
// test('silentload should use default preset and kernels if people do not pass one', async () => {
// const wrapper = document.createElement('div');
// player = new Chimee({
// src:
// 'http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv',
// isLive: false,
// preset: {
// flv: ChimeeKernelFlv
// },
// // 编解码容器
// box: 'flv', // flv hls native
// // dom容器
// wrapper
// });
// oldVideo = player.__dispatcher.dom.videoElement;
// oldKernel = player.__dispatcher.kernel;
// const result = player.silentLoad(
// 'http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv',
// {
// immediate: true
// }
// );
// // simulate timeupdate beforechange
// oldVideo.dispatchEvent(new Event('timeupdate'));
// // simulate metadata loaded finished
// video.dispatchEvent(new Event('loadedmetadata'));
// // simulate canplayable
// video.dispatchEvent(new Event('canplay'));
// // simulate times up
// player.currentTime = 3;
// oldVideo.dispatchEvent(new Event('timeupdate'));
// await expect(result).resolves.toBe();
// });
test('normal run', async () => {
const result = player.$silentLoad('http://cdn.toxicjohann.com/%E4%BA%8E%E6%98%AF.mp4');
await Promise.resolve();
Expand Down
2 changes: 1 addition & 1 deletion demo/flv/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>Flv Demo</h1>
</section>
</body>
<script type="text/javascript" src="/lib/index.dev.js"></script>
<script type="text/javascript" src="/node_modules/chimee-kernel-flv/lib/index.browser.js"></script>
<script type="text/javascript" src="/node_modules/chimee-kernel-flv/lib/index.js"></script>
<script type="text/javascript" src="./index.js"></script>
<script>
</script>
Expand Down
10 changes: 8 additions & 2 deletions demo/flv/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ window.player = new window.Chimee({
src: 'http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv',
// src: 'http://1253804432.vod2.myqcloud.com/3712977fvodgzp1253804432/f3f31e5f9031868223411915443/f0.flv',
isLive: false,
kernels: {
// kernels: {
// flv: window.chimeeKernelFlv
// },
preset: {
flv: window.chimeeKernelFlv
},
// 编解码容器
Expand All @@ -18,6 +21,9 @@ window.player = new window.Chimee({

window.player.on('play', evt => {
setTimeout(() => {
window.player.$silentLoad('http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv');
console.log('wowowoow');
window.player.$silentLoad('http://yunxianchang.live.ujne7.com/vod-system-bj/TL1ce1196bce348070bfeef2116efbdea6.flv', {
duration: 10
});
}, 500);
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"postmerge": "sh tool/auto-npm-install.sh",
"test": "jest --coverage",
"unit": "jest --coverage --watch",
"lint": "eslint ./src --fix && flow",
"lint": "eslint ./src ./__tests__ --fix && flow",
"flow": "flow",
"start": "rollup -c build/rollup.config.dev.js -w",
"build": "npm run b-common && npm run b-es && npm run b-umd && npm run b-min",
Expand Down
14 changes: 5 additions & 9 deletions src/dispatcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export default class Dispatcher {
immediate?: boolean,
isLive?: boolean,
box?: string,
preset?: Object,
kernels?: Object | Array<string> | void
} = {}) {
const {
Expand All @@ -212,11 +213,12 @@ export default class Dispatcher {
increment = 0,
isLive = this.videoConfig.isLive,
box = this.videoConfig.box,
kernels = this.videoConfig.kernels
kernels = this.videoConfig.kernels,
preset = this.videoConfig.preset
} = option;
// form the base config for kernel
// it should be the same as the config now
const config = {isLive, box, src, kernels};
const config = { isLive, box, src, kernels, preset };
// build tasks accroding repeat times
const tasks = new Array(repeatTimes + 1).fill(1).map((value, index) => {
return () => {
Expand Down Expand Up @@ -453,15 +455,9 @@ export default class Dispatcher {
this.changeWatchable = true;
}
_createKernel (video: HTMLVideoElement, config: Object) {
let { kernels, preset } = config;
const { kernels, preset } = config;
/* istanbul ignore else */
if(process.env.NODE_ENV !== 'production' && isEmpty(kernels) && !isEmpty(preset)) Log.warn('preset will be deprecated in next major version, please use kernels instead.');
if (isEmpty(kernels) && isEmpty(preset)) {
// it means user pass nothing
// go on use the original set
kernels = this.videoConfig.kernels;
preset = this.videoConfig.preset;
}
const newPreset = isArray(kernels)
? kernels.reduce((kernels, key) => {
if(!isFunction(kernelsSet[key])) {
Expand Down

0 comments on commit 929efbf

Please sign in to comment.