diff --git a/src/Console/Console.js b/src/Console/Console.js index 8557242..fb4e49a 100644 --- a/src/Console/Console.js +++ b/src/Console/Console.js @@ -290,7 +290,7 @@ export default class Console extends Tool { const logger = this._logger switch (key) { case 'asyncRender': - return logger.setOption('renderAsync', val) + return logger.setOption('asyncRender', val) case 'jsExecution': return this._enableJsExecution(val) case 'catchGlobalErr': diff --git a/test/console.js b/test/console.js index 6231e05..dae2c25 100644 --- a/test/console.js +++ b/test/console.js @@ -5,216 +5,26 @@ describe('console', function () { let logger = tool._logger function log(i) { - return logs()[i].el + return logs()[i].container } function logs() { - return logger._displayLogs + return logger.displayLogs } beforeEach(function () { eruda.show('console') - logger.silentClear() - }) - - it('string', function () { - let text = 'This is a log' - - tool.log(text) - expect($(log(0))).toContainText(text) - }) - - it('clear', function () { - expect($tool.find('.eruda-logs li')).toHaveLength(0) - }) - - it('recognize url', function () { - tool.log('http://liriliri.github.io/eruda/?plugin=fps') - expect($(log(0))).toContainHtml( - 'http://liriliri.github.io/eruda/?plugin=fps' - ) - }) - - it('basic object', function () { - let obj = { a: 1 } - - tool.log(obj) - expect($(log(0))).toContainText('Object { a: 1 }') - }) - - it('html', function () { - tool.html('Blue') - expect($(log(0))).toContainElement('span.color-blue') - }) - - it('timing', function () { - tool.time('eruda') - tool.timeEnd('eruda') - expect($(log(0))).toHaveText(/eruda: [.\d]+ms/) - }) - - it('error', function () { - tool.error(new Error('error test')) - expect($(log(0))).toContainElement('.eruda-stack') - expect($(log(0))).toContainText('error test') - }) - - it('assert', function () { - tool.assert(true, 'assert') - expect(logs()).toHaveLength(0) - - tool.assert(false, 'assert') - expect(logs()).toHaveLength(1) - }) - - it('count', function () { - tool.count('test') - tool.count('test') - expect($(log(1))).toContainText('test: 2') - }) - - describe('substitution', function () { - it('number', function () { - tool.log('Eruda is %d', 1.2, 'year old') - expect($(log(0))).toContainText('Eruda is 1 year old') - logger.silentClear() - - tool.log('%i', 1.2, 'year old') - expect($(log(0))).toContainText('1 year old') - logger.silentClear() - - tool.log('%f', 1.2, 'year old') - expect($(log(0))).toContainText('1.2 year old') - }) - - it('string', function () { - tool.log('My name is %s', 'eruda') - expect($(log(0))).toContainText('My name is eruda') - }) - - it('object', function () { - tool.log('Object is %O', { a: 1 }) - expect($(log(0))).toContainText('Object is { a: 1 }') - logger.silentClear() - - tool.log('Dom is %o', document.createElement('script')) - expect($(log(0))).toContainText('Dom is ') - }) - - it('style', function () { - tool.log('%cblue%cgreen', 'color:blue', 'color:green') - expect($(log(0))).toContainText('bluegreen') - }) - - it('Repeat log', function () { - for (let i = 0; i < 10; i++) tool.log(1) - let $log = $tool.find('.eruda-log-item') - expect(logs()).toHaveLength(1) - expect($(log(0))).toContainText('10') - }) - }) - - describe('table', function () { - it('wrong args', function () { - tool.table('test') - expect($tool.find('.eruda-table')).not.toContainElement('table') - }) - - it('sort keys', function () { - tool.table([{ a: 1 }, { d: 2, a: 2 }, { c: 1 }]) - expect($(log(0)).find('.eruda-table thead tr')).toContainHtml( - '(index)acd' - ) - }) - - it('basic', function () { - tool.table([{ test: 1 }, { test: 2, test2: 3 }]) - expect($(log(0)).find('.eruda-table tbody tr')).toHaveLength(2) - expect($(log(0)).find('.eruda-table thead th')).toHaveLength(3) - }) - - it('filter', function () { - tool.table([{ test: 1 }, { test: 2, test2: 3 }], 'test') - expect($(log(0)).find('.eruda-table thead th')).toHaveLength(2) - }) - }) - - describe('filter', function () { - // Test case from https://github.com/liriliri/eruda/issues/14 - it('function', function () { - tool.filter(function (log) { - return log.type !== 'error' - }) - - let obj = {} - Object.defineProperty(obj, 'a', { - get: function () { - tool.error('deprecated') - - return 1 - }, - }) - tool.log(obj) - expect(logs()).toHaveLength(1) - - tool.filter('all') - }) - - it('all info error warn log', function () { - tool.log('log').info('info').error('error').warn('warn').debug('debug') - expect(logs()).toHaveLength(5) - - tool.filter('info') - expect(logs()).toHaveLength(1) - expect(log(0).log.type).toBe('info') - - tool.filter('error') - expect(logs()).toHaveLength(1) - expect(log(0).log.type).toBe('error') - - tool.filter('warn') - expect(logs()).toHaveLength(1) - expect(log(0).log.type).toBe('warn') - - tool.filter('debug') - expect(logs()).toHaveLength(1) - expect(log(0).log.type).toBe('debug') - - tool.filter('all') - }) - - it('regex', function () { - tool.log('test').log('test2') - expect(logs()).toHaveLength(2) - - tool.filter(/test2/) - expect(logs()).toHaveLength(1) - expect($(log(0))).toContainText('test2') - - tool.filter('all') - }) + logger.clear(true) }) describe('config', function () { let config = tool.config - it('max number', function () { - config.set('maxLogNum', '10') - for (let i = 0; i < 20; i++) tool.log(i) - expect(logs()).toHaveLength(10) - }) - it('override console', function () { config.set('overrideConsole', true) console.log('test') expect($(log(0))).toContainText('test') }) - - it('display extra info', function () { - config.set('displayExtraInfo', true) - tool.log('test') - expect($(log(0))).toContainElement('.eruda-header') - }) }) describe('ui', function () {