From 64be50b5bcb135f04a4d247000a3b6c3346b6aed Mon Sep 17 00:00:00 2001 From: Drini Cami Date: Thu, 6 Jul 2023 17:15:34 -0400 Subject: [PATCH] Remove Debug Console dev util Hasn't been used in forever, and we can use external tools --- src/BookReader.js | 5 -- src/BookReader/DebugConsole.js | 54 ---------------------- tests/jest/BookReader/DebugConsole.test.js | 25 ---------- 3 files changed, 84 deletions(-) delete mode 100644 src/BookReader/DebugConsole.js delete mode 100644 tests/jest/BookReader/DebugConsole.test.js diff --git a/src/BookReader.js b/src/BookReader.js index bfb7ac76d..18ec6b7e9 100644 --- a/src/BookReader.js +++ b/src/BookReader.js @@ -33,7 +33,6 @@ import { DEFAULT_OPTIONS, OptionsParseError } from './BookReader/options.js'; /** @typedef {import('./BookReader/options.js').ReductionFactor} ReductionFactor */ /** @typedef {import('./BookReader/BookModel.js').PageIndex} PageIndex */ import { EVENTS } from './BookReader/events.js'; -import { DebugConsole } from './BookReader/DebugConsole.js'; import { Toolbar } from './BookReader/Toolbar/Toolbar.js'; import { BookModel } from './BookReader/BookModel.js'; import { Mode1Up } from './BookReader/Mode1Up.js'; @@ -43,10 +42,6 @@ import { ImageCache } from './BookReader/ImageCache.js'; import { PageContainer } from './BookReader/PageContainer.js'; import { NAMED_REDUCE_SETS } from './BookReader/ReduceSet'; -if (location.toString().indexOf('_debugShowConsole=true') != -1) { - $(() => new DebugConsole().init()); -} - /** * BookReader * @param {BookReaderOptions} options diff --git a/src/BookReader/DebugConsole.js b/src/BookReader/DebugConsole.js deleted file mode 100644 index a95ace731..000000000 --- a/src/BookReader/DebugConsole.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Displays a console on the document for debugging devices where remote - * debugging is not feasible, and forwards all console.log's to be displayed - * on screen. - */ -export class DebugConsole { - constructor() { - /** How many times we've seen the same line in a row */ - this.currentRun = 0; - } - - init() { - this.$log = $(`
`); - $(document.body).prepend(this.$log); - - this.$form = $(` -
- -
`); - this.$log.append(this.$form); - - this.$form.on("submit", ev => { - ev.preventDefault(); - const result = eval(this.$form.find('input').val()); - this.logToScreen([result]); - }); - - const _realLog = console.log.bind(console); - console.log = (...args) => { - _realLog(...args); - this.logToScreen(args); - }; - - window.onerror = (...args) => this.logToScreen(args); - } - - /** - * Log the provided array onto the on screen console - * @param {Array} args - */ - logToScreen(args) { - const html = args.map(JSON.stringify).join(','); - const $lastEntry = this.$log.children('.log-entry:last-child'); - if ($lastEntry.find('.entry-code').html() == html) { - $lastEntry.find('.count').text(`(${++this.currentRun})`); - } else { - this.currentRun = 1; - this.$log.append($(` -
- ${html} -
`)); - } - } -} diff --git a/tests/jest/BookReader/DebugConsole.test.js b/tests/jest/BookReader/DebugConsole.test.js deleted file mode 100644 index 478affab9..000000000 --- a/tests/jest/BookReader/DebugConsole.test.js +++ /dev/null @@ -1,25 +0,0 @@ -import sinon from 'sinon'; -import { DebugConsole } from '@/src/BookReader/DebugConsole.js'; - -beforeEach(() => { - sinon.stub(console, 'log'); -}); -afterEach(() => { - sinon.restore(); -}); - -test('hijacks console.log', () => { - const _realLog = console.log; - expect(_realLog).toBe(console.log); - new DebugConsole().init(); - expect(_realLog).not.toBe(console.log); -}); - -test('logging the same thing twice does not create more entries', () => { - const dc = new DebugConsole(); - dc.init(); - dc.logToScreen(['hello']); - dc.logToScreen(['hello']); - expect(dc.$log.children('.log-entry')).toHaveLength(1); - expect(dc.$log.find('.count').text()).toBe('(2)'); -});