From 029d5365e7d74e87375fccb8db097b7c2df3f7f4 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 22 Dec 2019 10:28:14 +0900 Subject: npm run lint:fix --- test/console/actions/console.test.ts | 18 ++++++------- .../console/components/console/Completion.test.tsx | 28 ++++++++++---------- test/console/reducers/console.test.ts | 30 +++++++++++----------- 3 files changed, 38 insertions(+), 38 deletions(-) (limited to 'test/console') diff --git a/test/console/actions/console.test.ts b/test/console/actions/console.test.ts index e45d008..583c878 100644 --- a/test/console/actions/console.test.ts +++ b/test/console/actions/console.test.ts @@ -4,13 +4,13 @@ import * as consoleActions from 'console/actions/console'; describe("console actions", () => { describe('hide', () => { it('create CONSOLE_HIDE action', () => { - let action = consoleActions.hide(); + const action = consoleActions.hide(); expect(action.type).to.equal(actions.CONSOLE_HIDE); }); }); describe("showCommand", () => { it('create CONSOLE_SHOW_COMMAND action', () => { - let action = consoleActions.showCommand('hello'); + const action = consoleActions.showCommand('hello'); expect(action.type).to.equal(actions.CONSOLE_SHOW_COMMAND); expect(action.text).to.equal('hello'); }); @@ -18,14 +18,14 @@ describe("console actions", () => { describe("showFind", () => { it('create CONSOLE_SHOW_FIND action', () => { - let action = consoleActions.showFind(); + const action = consoleActions.showFind(); expect(action.type).to.equal(actions.CONSOLE_SHOW_FIND); }); }); describe("showError", () => { it('create CONSOLE_SHOW_ERROR action', () => { - let action = consoleActions.showError('an error'); + const action = consoleActions.showError('an error'); expect(action.type).to.equal(actions.CONSOLE_SHOW_ERROR); expect(action.text).to.equal('an error'); }); @@ -33,7 +33,7 @@ describe("console actions", () => { describe("showInfo", () => { it('create CONSOLE_SHOW_INFO action', () => { - let action = consoleActions.showInfo('an info'); + const action = consoleActions.showInfo('an info'); expect(action.type).to.equal(actions.CONSOLE_SHOW_INFO); expect(action.text).to.equal('an info'); }); @@ -41,14 +41,14 @@ describe("console actions", () => { describe("hideCommand", () => { it('create CONSOLE_HIDE_COMMAND action', () => { - let action = consoleActions.hideCommand(); + const action = consoleActions.hideCommand(); expect(action.type).to.equal(actions.CONSOLE_HIDE_COMMAND); }); }); describe('setConsoleText', () => { it('create CONSOLE_SET_CONSOLE_TEXT action', () => { - let action = consoleActions.setConsoleText('hello world'); + const action = consoleActions.setConsoleText('hello world'); expect(action.type).to.equal(actions.CONSOLE_SET_CONSOLE_TEXT); expect(action.consoleText).to.equal('hello world'); }); @@ -56,14 +56,14 @@ describe("console actions", () => { describe("completionPrev", () => { it('create CONSOLE_COMPLETION_PREV action', () => { - let action = consoleActions.completionPrev(); + const action = consoleActions.completionPrev(); expect(action.type).to.equal(actions.CONSOLE_COMPLETION_PREV); }); }); describe("completionNext", () => { it('create CONSOLE_COMPLETION_NEXT action', () => { - let action = consoleActions.completionNext(); + const action = consoleActions.completionNext(); expect(action.type).to.equal(actions.CONSOLE_COMPLETION_NEXT); }); }); diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx index 16bf11a..a271d77 100644 --- a/test/console/components/console/Completion.test.tsx +++ b/test/console/components/console/Completion.test.tsx @@ -3,7 +3,7 @@ import Completion from 'console/components/console/Completion' import ReactTestRenderer from 'react-test-renderer'; describe("console/components/console/completion", () => { - let completions = [{ + const completions = [{ name: "Fruit", items: [{ caption: "apple" }, { caption: "banana" }, { caption: "cherry" }], }, { @@ -12,14 +12,14 @@ describe("console/components/console/completion", () => { }]; it('renders Completion component', () => { - let root = ReactTestRenderer.create().root; expect(root.children).to.have.lengthOf(1); - let children = root.children[0].children; + const children = root.children[0].children; expect(children).to.have.lengthOf(8); expect(children[0].props.title).to.equal('Fruit'); expect(children[1].props.caption).to.equal('apple'); @@ -32,25 +32,25 @@ describe("console/components/console/completion", () => { }); it('highlight current item', () => { - let root = ReactTestRenderer.create().root; - let children = root.children[0].children; + const children = root.children[0].children; expect(children[5].props.highlight).to.be.true; }); it('does not highlight any items', () => { - let root = ReactTestRenderer.create().root; - let children = root.children[0].children; - for (let li of children[0].children) { + const children = root.children[0].children; + for (const li of children[0].children) { expect(li.props.highlight).not.to.be.ok; } }); @@ -79,13 +79,13 @@ describe("console/components/console/completion", () => { }) it('scrolls up to down with select', () => { - let component = ReactTestRenderer.create(); - let instance = component.getInstance(); - let root = component.root; + const instance = component.getInstance(); + const root = component.root; let children = root.children[0].children; expect(children).to.have.lengthOf(3); @@ -121,13 +121,13 @@ describe("console/components/console/completion", () => { }); it('scrolls down to up with select', () => { - let component = ReactTestRenderer.create(); - let root = component.root; - let instance = component.getInstance(); + const root = component.root; + const instance = component.getInstance(); let children = root.children[0].children; expect(children).to.have.lengthOf(3); diff --git a/test/console/reducers/console.test.ts b/test/console/reducers/console.test.ts index 47e7daf..038e712 100644 --- a/test/console/reducers/console.test.ts +++ b/test/console/reducers/console.test.ts @@ -3,7 +3,7 @@ import reducer from 'console/reducers'; describe("console reducer", () => { it('return the initial state', () => { - let state = reducer(undefined, {}); + const state = reducer(undefined, {}); expect(state).to.have.property('mode', ''); expect(state).to.have.property('messageText', ''); expect(state).to.have.property('consoleText', ''); @@ -12,34 +12,34 @@ describe("console reducer", () => { }); it('return next state for CONSOLE_HIDE', () => { - let action = { type: actions.CONSOLE_HIDE }; - let state = reducer({ mode: 'error' }, action); + const action = { type: actions.CONSOLE_HIDE }; + const state = reducer({ mode: 'error' }, action); expect(state).to.have.property('mode', ''); }) it('return next state for CONSOLE_SHOW_COMMAND', () => { - let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; - let state = reducer({}, action); + const action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; + const state = reducer({}, action); expect(state).to.have.property('mode', 'command'); expect(state).to.have.property('consoleText', 'open '); }); it('return next state for CONSOLE_SHOW_INFO', () => { - let action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' }; - let state = reducer({}, action); + const action = { type: actions.CONSOLE_SHOW_INFO, text: 'an info' }; + const state = reducer({}, action); expect(state).to.have.property('mode', 'info'); expect(state).to.have.property('messageText', 'an info'); }); it('return next state for CONSOLE_SHOW_ERROR', () => { - let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; - let state = reducer({}, action); + const action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; + const state = reducer({}, action); expect(state).to.have.property('mode', 'error'); expect(state).to.have.property('messageText', 'an error'); }); it('return next state for CONSOLE_HIDE_COMMAND', () => { - let action = { type: actions.CONSOLE_HIDE_COMMAND }; + const action = { type: actions.CONSOLE_HIDE_COMMAND }; let state = reducer({ mode: 'command' }, action); expect(state).to.have.property('mode', ''); @@ -48,11 +48,11 @@ describe("console reducer", () => { }); it('return next state for CONSOLE_SET_CONSOLE_TEXT', () => { - let action = { + const action = { type: actions.CONSOLE_SET_CONSOLE_TEXT, consoleText: 'hello world' } - let state = reducer({}, action) + const state = reducer({}, action) expect(state).to.have.property('consoleText', 'hello world'); }); @@ -62,7 +62,7 @@ describe("console reducer", () => { select: 0, completions: [], } - let action = { + const action = { type: actions.CONSOLE_SET_COMPLETIONS, completions: [{ name: 'Apple', @@ -78,7 +78,7 @@ describe("console reducer", () => { }); it ('return next state for CONSOLE_COMPLETION_NEXT', () => { - let action = { type: actions.CONSOLE_COMPLETION_NEXT }; + const action = { type: actions.CONSOLE_COMPLETION_NEXT }; let state = { select: -1, completions: [{ @@ -104,7 +104,7 @@ describe("console reducer", () => { }); it ('return next state for CONSOLE_COMPLETION_PREV', () => { - let action = { type: actions.CONSOLE_COMPLETION_PREV }; + const action = { type: actions.CONSOLE_COMPLETION_PREV }; let state = { select: -1, completions: [{ -- cgit v1.2.3 From da72c2ddd916d79d134662e3985b53a4ac78af7a Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 22 Dec 2019 10:42:48 +0900 Subject: Fix lint rules on tests --- .eslintrc | 1 + test/background/repositories/Mark.test.ts | 5 ++--- test/console/components/console/Completion.test.tsx | 2 -- test/content/InputDriver.test.ts | 2 +- test/content/presenters/Hint.test.ts | 2 +- test/content/presenters/NavigationPresenter.test.ts | 7 +++---- test/content/repositories/KeymapRepository.test.ts | 10 +++++----- test/content/usecases/ClipboardUseCase.test.ts | 20 ++++++++++++++++---- test/main.ts | 6 ++---- 9 files changed, 31 insertions(+), 24 deletions(-) (limited to 'test/console') diff --git a/.eslintrc b/.eslintrc index 0ff0b11..d08c3a6 100644 --- a/.eslintrc +++ b/.eslintrc @@ -28,6 +28,7 @@ }, "rules": { "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-namespace": "off", "@typescript-eslint/no-non-null-assertion": "off", diff --git a/test/background/repositories/Mark.test.ts b/test/background/repositories/Mark.test.ts index 625f11d..ed1a68e 100644 --- a/test/background/repositories/Mark.test.ts +++ b/test/background/repositories/Mark.test.ts @@ -1,11 +1,10 @@ import MarkRepository from 'background/repositories/MarkRepository'; -import GlobalMark from 'background/domains/GlobalMark'; describe('background/repositories/mark', () => { - let repository; + let repository: MarkRepository; beforeEach(() => { - repository = new MarkRepository; + repository = new MarkRepository(); }); it('get and set', async() => { diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx index a271d77..e411c4a 100644 --- a/test/console/components/console/Completion.test.tsx +++ b/test/console/components/console/Completion.test.tsx @@ -84,7 +84,6 @@ describe("console/components/console/completion", () => { size={3} select={1} />); - const instance = component.getInstance(); const root = component.root; let children = root.children[0].children; @@ -127,7 +126,6 @@ describe("console/components/console/completion", () => { select={5} />); const root = component.root; - const instance = component.getInstance(); let children = root.children[0].children; expect(children).to.have.lengthOf(3); diff --git a/test/content/InputDriver.test.ts b/test/content/InputDriver.test.ts index 367ec1d..d3a55dd 100644 --- a/test/content/InputDriver.test.ts +++ b/test/content/InputDriver.test.ts @@ -104,7 +104,7 @@ describe('InputDriver', () => { ['input', 'textarea', 'select'].forEach((name) => { const input = window.document.createElement(name); const driver = new InputDriver(input); - driver.onKey((key: Key): boolean => { + driver.onKey((_key: Key): boolean => { expect.fail(); return false; }); diff --git a/test/content/presenters/Hint.test.ts b/test/content/presenters/Hint.test.ts index 708ddaa..7daa63d 100644 --- a/test/content/presenters/Hint.test.ts +++ b/test/content/presenters/Hint.test.ts @@ -12,7 +12,7 @@ describe('Hint', () => { describe('#constructor', () => { it('creates a hint element with tag name', () => { const link = document.getElementById('test-link'); - const hint = new Hint(link, 'abc'); + new Hint(link, 'abc'); const elem = document.querySelector('.vimvixen-hint'); expect(elem.textContent.trim()).to.be.equal('abc'); diff --git a/test/content/presenters/NavigationPresenter.test.ts b/test/content/presenters/NavigationPresenter.test.ts index 5b6a8ca..6aa057b 100644 --- a/test/content/presenters/NavigationPresenter.test.ts +++ b/test/content/presenters/NavigationPresenter.test.ts @@ -1,9 +1,8 @@ -import NavigationPresenter, { NavigationPresenterImpl } - from '../../../src/content/presenters/NavigationPresenter'; +import { NavigationPresenterImpl } from '../../../src/content/presenters/NavigationPresenter'; import { expect } from 'chai'; -describe('NavigationPresenter', () => { - let sut; +describe('NavigationPresenterImpl', () => { + let sut: NavigationPresenterImpl; const testRel = (done, rel, html) => { const method = rel === 'prev' ? sut.openLinkPrev.bind(sut) : sut.openLinkNext.bind(sut); diff --git a/test/content/repositories/KeymapRepository.test.ts b/test/content/repositories/KeymapRepository.test.ts index df013df..68f515c 100644 --- a/test/content/repositories/KeymapRepository.test.ts +++ b/test/content/repositories/KeymapRepository.test.ts @@ -12,11 +12,11 @@ describe('KeymapRepositoryImpl', () => { describe('#enqueueKey()', () => { it('enqueues keys', () => { - sut.enqueueKey(Key.fromMapKey('a'); - sut.enqueueKey(Key.fromMapKey('b'); - let sequence = sut.enqueueKey(Key.fromMapKey('c')); + sut.enqueueKey(Key.fromMapKey('a')); + sut.enqueueKey(Key.fromMapKey('b')); + const sequence = sut.enqueueKey(Key.fromMapKey('c')); - let keys = sequence.keys; + const keys = sequence.keys; expect(keys[0].equals(Key.fromMapKey('a'))).to.be.true; expect(keys[1].equals(Key.fromMapKey('b'))).to.be.true; expect(keys[2].equals(Key.fromMapKey('c'))).to.be.true; @@ -30,7 +30,7 @@ describe('KeymapRepositoryImpl', () => { sut.enqueueKey(Key.fromMapKey('c')); sut.clear(); - let sequence = sut.enqueueKey(Key.fromMapKey('a')); + const sequence = sut.enqueueKey(Key.fromMapKey('a')); expect(sequence.length()).to.equal(1); }); }); diff --git a/test/content/usecases/ClipboardUseCase.test.ts b/test/content/usecases/ClipboardUseCase.test.ts index 2e711c6..3cc82fe 100644 --- a/test/content/usecases/ClipboardUseCase.test.ts +++ b/test/content/usecases/ClipboardUseCase.test.ts @@ -6,19 +6,31 @@ import ConsoleClient from '../../../src/content/client/ConsoleClient'; import * as sinon from 'sinon'; import { expect } from 'chai'; +import {Operation} from "../../../src/shared/operations"; describe('ClipboardUseCase', () => { let clipboardRepository: ClipboardRepository; + let operationClient: OperationClient; + let consoleClient: ConsoleClient; + let sut: ClipboardUseCase; beforeEach(() => { - const modal = {}; + clipboardRepository = new class implements ClipboardRepository { + read(): string { return ""; } + write(_text: string) {} + }; + operationClient = new class implements OperationClient { + execBackgroundOp(_repeat: number, _op: Operation): Promise { return Promise.resolve() } + internalOpenUrl(_url: string, _newTab?: boolean, _background?: boolean): Promise { return Promise.resolve() } + }; + consoleClient = new class implements ConsoleClient { + error(_text: string): Promise { return Promise.resolve() } + info(_text: string): Promise { return Promise.resolve() } + }; - clipboardRepository = { read() {}, write(_) {} }; - operationClient = { internalOpenUrl(_) {} }; - consoleClient = { info(_) {}}; sut = new ClipboardUseCase( clipboardRepository, new SettingRepositoryImpl(), diff --git a/test/main.ts b/test/main.ts index 433b531..c985546 100644 --- a/test/main.ts +++ b/test/main.ts @@ -1,8 +1,6 @@ import 'reflect-metadata'; import { expect } from 'chai'; - -const browserFake = require('webextensions-api-fake'); -const browser = browserFake(); +import browserFake from 'webextensions-api-fake'; global.expect = expect; -global.browser = browser; +global.browser = browserFake(); -- cgit v1.2.3