From e73bf11849dca0d545302efad4211005ef7fe262 Mon Sep 17 00:00:00 2001 From: IllusionMH Date: Tue, 1 Sep 2020 22:19:57 +0300 Subject: [PATCH] Log error instead of throwing. Move test to service. --- src/browser/Terminal.test.ts | 6 ------ src/common/services/OptionsService.test.ts | 22 ++++++++++++++++++++++ src/common/services/OptionsService.ts | 8 ++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/common/services/OptionsService.test.ts diff --git a/src/browser/Terminal.test.ts b/src/browser/Terminal.test.ts index bef0ced4..9bdc783e 100644 --- a/src/browser/Terminal.test.ts +++ b/src/browser/Terminal.test.ts @@ -1533,12 +1533,6 @@ describe('Terminal', () => { }); }); }); - it('constructor options validation', () => { - expect(() => new TestTerminal({cursorStyle: undefined})).to.not.throw(); - expect(() => new TestTerminal({tabStopWidth: 0})).to.throw('value: 0'); - expect(() => new TestTerminal({scrollback: -10})).to.throw('value: -10'); - expect(() => new TestTerminal({scrollSensitivity: 0})).to.throw('value: 0'); - }); }); class TestLinkifier extends Linkifier { diff --git a/src/common/services/OptionsService.test.ts b/src/common/services/OptionsService.test.ts new file mode 100644 index 00000000..59c17faf --- /dev/null +++ b/src/common/services/OptionsService.test.ts @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2020 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { assert } from 'chai'; +import { OptionsService, DEFAULT_OPTIONS } from 'common/services/OptionsService'; + +describe('OptionsService', () => { + describe('constructor', () => { + const originalError = console.error; + beforeEach(() => { + console.error = () => {}; + }); + afterEach(() => { + console.error = originalError; + }); + it('uses default value if invalid constructor option value passed', () => { + assert.equal(new OptionsService({tabStopWidth: 0}).getOption('tabStopWidth'), DEFAULT_OPTIONS.tabStopWidth); + }); + }); +}); diff --git a/src/common/services/OptionsService.ts b/src/common/services/OptionsService.ts index a4b06404..2f010923 100644 --- a/src/common/services/OptionsService.ts +++ b/src/common/services/OptionsService.ts @@ -73,8 +73,12 @@ export class OptionsService implements IOptionsService { this.options = clone(DEFAULT_OPTIONS); for (const k of Object.keys(options)) { if (k in this.options) { - const newValue = options[k as keyof IPartialTerminalOptions] as any; - this.options[k] = this._sanitizeAndValidateOption(k, newValue); + try { + const newValue = options[k as keyof IPartialTerminalOptions] as any; + this.options[k] = this._sanitizeAndValidateOption(k, newValue); + } catch (e) { + console.error(e); + } } } }