Skip to content

Commit

Permalink
[fix] cover some change-kernel branch
Browse files Browse the repository at this point in the history
  • Loading branch information
toxic-johann committed Apr 21, 2018
1 parent c51ce34 commit 1a9590e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
37 changes: 37 additions & 0 deletions __tests__/dispatcher/binder.js
Expand Up @@ -33,6 +33,16 @@ describe('dispatcher/binder', () => {
expect(() => player.destroy()).not.toThrow();
});

test('binder will clear video events which is forget to clear by upper layer', () => {
player.__dispatcher.binder.on({
target: 'video',
name: 'play',
id: 'illegal',
fn: () => {},
});
expect(() => player.destroy()).not.toThrow();
});

test('binder triggersync isEventEmitalbe backup', () => {
expect(() => player.__dispatcher.binder.triggerSync({})).not.toThrow();
});
Expand All @@ -50,4 +60,31 @@ describe('dispatcher/binder', () => {
});
}).toThrow('You must provide a function to handle with event what, but not undefined');
});

test('off redudant event which has no function bind', () => {
player.__dispatcher.binder.bindedEventNames.kernel.push('heartbeat');
player.on('mediaInfo', () => {});
player.off('heartbeat', () => {});
});

test('off redudant event which has no name index', () => {
player.off('heartbeat', () => {});
});

test('penetrate event binding', async () => {
const plugin = {
name: 'penetrate plugin',
penetrate: true,
events: {
click() {},
},
};
Chimee.install(plugin);
await player.use(plugin.name);
});

test('bind the same event', async () => {
player.on('click', () => {});
player.on('click', () => {});
});
});
9 changes: 8 additions & 1 deletion __tests__/situation/change-kernel.js
@@ -1,6 +1,10 @@
import Chimee from 'index';
import flv from 'chimee-kernel-flv';

function sleep(duration) {
return new Promise(resolve => setTimeout(resolve, duration));
}

describe('changeKernel', () => {
test('property should change', async () => {
const originFn = global.URL.revokeObjectURL;
Expand All @@ -11,7 +15,10 @@ describe('changeKernel', () => {
box: 'native',
autoload: false,
});
// test migrateKernelEvent
chimee.on('heartbeat', () => {});
// test bindEventOnVideo
chimee.on('play', () => {});
expect(chimee.isLive).toBe(false);
expect(chimee.box).toBe('native');
expect(chimee.preset).toEqual({});
Expand All @@ -33,7 +40,7 @@ describe('changeKernel', () => {
box: 'native',
kernels: [],
});
await Promise.resolve();
await sleep(100);
expect(chimee.isLive).toBe(false);
expect(chimee.box).toBe('native');
// 因为 preset 不为人知,所以这方面保持逻辑正确即可
Expand Down
4 changes: 4 additions & 0 deletions src/dispatcher/binder.js
Expand Up @@ -269,6 +269,10 @@ export default class Binder {
}
};
this._addEventOnDom(node, name, fn);
// this function is only used once now
// so we do not cover this branch
// but we still keep this judegement
/* istanbul ignore else */
if (this.bindedEventNames[target].indexOf(name) < 0) {
this.bindedEventNames[target].push(name);
// $FlowFixMe: fn must be function now
Expand Down

0 comments on commit 1a9590e

Please sign in to comment.