2015-05-03 16:12:38 -07:00
|
|
|
import log from '../../../src/js/utils/log.js';
|
2016-07-18 14:32:31 -04:00
|
|
|
import {logByType} from '../../../src/js/utils/log.js';
|
2015-05-03 16:12:38 -07:00
|
|
|
import window from 'global/window';
|
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
q.module('log', {
|
2015-08-03 15:19:36 -04:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
beforeEach() {
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
// Back up the original console.
|
|
|
|
this.originalConsole = window.console;
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
// Replace the native console for testing. In IE8 `console.log` is not a
|
|
|
|
// 'function' so sinon chokes on it when trying to spy:
|
|
|
|
// https://github.com/cjohansen/Sinon.JS/issues/386
|
|
|
|
//
|
|
|
|
// Instead we'll temporarily replace them with no-op functions
|
|
|
|
window.console = {
|
|
|
|
log: sinon.spy(),
|
|
|
|
warn: sinon.spy(),
|
|
|
|
error: sinon.spy()
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
afterEach() {
|
|
|
|
|
|
|
|
// Restore the native/original console.
|
|
|
|
window.console = this.originalConsole;
|
|
|
|
|
|
|
|
// Empty the logger's history.
|
|
|
|
log.history.length = 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('logging functions should work', function() {
|
|
|
|
|
|
|
|
// Need to reset history here because there are extra messages logged
|
|
|
|
// when running via Karma.
|
|
|
|
log.history.length = 0;
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
log('log1', 'log2');
|
|
|
|
log.warn('warn1', 'warn2');
|
|
|
|
log.error('error1', 'error2');
|
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
ok(window.console.log.called, 'log was called');
|
|
|
|
deepEqual(window.console.log.firstCall.args,
|
|
|
|
['VIDEOJS:', 'log1', 'log2']);
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
ok(window.console.warn.called, 'warn was called');
|
|
|
|
deepEqual(window.console.warn.firstCall.args,
|
|
|
|
['VIDEOJS:', 'WARN:', 'warn1', 'warn2']);
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
ok(window.console.error.called, 'error was called');
|
|
|
|
deepEqual(window.console.error.firstCall.args,
|
|
|
|
['VIDEOJS:', 'ERROR:', 'error1', 'error2']);
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
equal(log.history.length, 3, 'there should be three messages in the log history');
|
2016-07-18 14:32:31 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('in IE pre-11 (or when requested) objects and arrays are stringified', function() {
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
// Run a custom log call, explicitly requesting object/array stringification.
|
|
|
|
logByType('log', [
|
|
|
|
'test',
|
|
|
|
{foo: 'bar'},
|
|
|
|
[1, 2, 3],
|
|
|
|
0,
|
|
|
|
false,
|
|
|
|
null,
|
|
|
|
undefined
|
|
|
|
], true);
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2016-07-18 14:32:31 -04:00
|
|
|
ok(window.console.log.called, 'log was called');
|
|
|
|
deepEqual(window.console.log.firstCall.args,
|
|
|
|
['VIDEOJS: test {"foo":"bar"} [1,2,3] 0 false null undefined']);
|
2015-05-03 16:12:38 -07:00
|
|
|
});
|