From 929efbf2b48622e85223d9bd9ddbaa131cfa8d33 Mon Sep 17 00:00:00 2001 From: toxic-johann <353904974@qq.com> Date: Wed, 8 Nov 2017 00:21:18 +0800 Subject: [PATCH] [update] add test but it fail --- __tests__/bugfix.js | 18 ++++++++++++++++++ __tests__/dispatcher/plugin.js | 4 ++-- __tests__/index.js | 2 +- __tests__/silentload.js | 34 ++++++++++++++++++++++++++++++++++ demo/flv/index.html | 2 +- demo/flv/index.js | 10 ++++++++-- package.json | 2 +- src/dispatcher/index.js | 14 +++++--------- 8 files changed, 70 insertions(+), 16 deletions(-) diff --git a/__tests__/bugfix.js b/__tests__/bugfix.js index 7db8030a..850bb6e0 100644 --- a/__tests__/bugfix.js +++ b/__tests__/bugfix.js @@ -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(); @@ -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(); +}); diff --git a/__tests__/dispatcher/plugin.js b/__tests__/dispatcher/plugin.js index 2ff205dc..0658998d 100644 --- a/__tests__/dispatcher/plugin.js +++ b/__tests__/dispatcher/plugin.js @@ -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 = []; @@ -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; diff --git a/__tests__/index.js b/__tests__/index.js index 5b171e16..e5d4208a 100644 --- a/__tests__/index.js +++ b/__tests__/index.js @@ -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 = { diff --git a/__tests__/silentload.js b/__tests__/silentload.js index 28b537ee..ce59a02c 100644 --- a/__tests__/silentload.js +++ b/__tests__/silentload.js @@ -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; @@ -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(); diff --git a/demo/flv/index.html b/demo/flv/index.html index 85ee9231..189be7a5 100644 --- a/demo/flv/index.html +++ b/demo/flv/index.html @@ -18,7 +18,7 @@

Flv Demo

- + diff --git a/demo/flv/index.js b/demo/flv/index.js index 9aff2ab2..a73b15fc 100644 --- a/demo/flv/index.js +++ b/demo/flv/index.js @@ -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 }, // 编解码容器 @@ -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); }); diff --git a/package.json b/package.json index be8def71..3215b9c3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/dispatcher/index.js b/src/dispatcher/index.js index 8a169a22..ab7149cc 100644 --- a/src/dispatcher/index.js +++ b/src/dispatcher/index.js @@ -203,6 +203,7 @@ export default class Dispatcher { immediate?: boolean, isLive?: boolean, box?: string, + preset?: Object, kernels?: Object | Array | void } = {}) { const { @@ -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 () => { @@ -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])) {