diff --git a/.eslintrc.js b/.eslintrc.js index dc74a23ae9..5047b6a1c2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -55,6 +55,7 @@ module.exports = { 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', 'plugin:import/recommended', + 'plugin:mocha/recommended', 'plugin:prettier/recommended', 'plugin:promise/recommended', // keep-sorted end @@ -91,8 +92,9 @@ module.exports = { 'import/no-duplicates': 'error', 'import/no-unresolved': 'off', 'import/order': ['warn', {'newlines-between': 'always'}], + 'mocha/no-mocha-arrows': 'off', + 'mocha/no-setup-in-describe': 'off', 'no-console': 'warn', - 'no-duplicate-imports': 'error', 'no-else-return': 'warn', 'no-empty': ['warn', {allowEmptyCatch: true}], 'no-implicit-coercion': 'error', diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c172d0d964..a1016b43c7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -98,11 +98,6 @@ repos: language: pygrep files: \.js$|\.cjs$|\.mjs$|\.ts$|\.py$ args: [--negate, --multiline] - - id: check-chai-describe-it-only - name: check chai describe & it `.only()` - entry: '\b(it|describe)\.only\(' - language: pygrep - files: \.spec\.ts$ - id: node-self name: check nodejs `self.` entry: '\bself\.' diff --git a/src/bidiMapper/domains/context/browsingContextProcessor.ts b/src/bidiMapper/domains/context/browsingContextProcessor.ts index 4663b85c11..90f06f8f7d 100644 --- a/src/bidiMapper/domains/context/browsingContextProcessor.ts +++ b/src/bidiMapper/domains/context/browsingContextProcessor.ts @@ -415,10 +415,10 @@ export class BrowsingContextProcessor { const realm = await this.#getRealm(params.target); return realm.callFunction( params.functionDeclaration, - params.this || { + params.this ?? { type: 'undefined', }, // `this` is `undefined` by default. - params.arguments || [], // `arguments` is `[]` by default. + params.arguments ?? [], // `arguments` is `[]` by default. params.awaitPromise, params.resultOwnership ?? 'none', params.serializationOptions ?? {} diff --git a/src/bidiMapper/domains/events/SubscriptionManager.spec.ts b/src/bidiMapper/domains/events/SubscriptionManager.spec.ts index cf37221d15..f87c820210 100644 --- a/src/bidiMapper/domains/events/SubscriptionManager.spec.ts +++ b/src/bidiMapper/domains/events/SubscriptionManager.spec.ts @@ -401,91 +401,91 @@ describe('SubscriptionManager', () => { ).to.deep.equal([SOME_CHANNEL]); }); }); -}); -describe('cartesian product', () => { - it('should return empty array for empty array', () => { - expect(cartesianProduct([], [])).to.deep.equal([]); - }); + describe('cartesian product', () => { + it('should return empty array for empty array', () => { + expect(cartesianProduct([], [])).to.deep.equal([]); + }); - it('works with a single input', () => { - expect(cartesianProduct([1n, 2n])).to.deep.equal([1n, 2n]); - }); + it('works with a single input', () => { + expect(cartesianProduct([1n, 2n])).to.deep.equal([1n, 2n]); + }); - it('works with multiple inputs', () => { - expect(cartesianProduct([1], [2], [3])).to.deep.equal([[1, 2, 3]]); - }); + it('works with multiple inputs', () => { + expect(cartesianProduct([1], [2], [3])).to.deep.equal([[1, 2, 3]]); + }); - it('happy path', () => { - expect(cartesianProduct([1, 2], ['A', 'B'])).to.deep.equal([ - [1, 'A'], - [1, 'B'], - [2, 'A'], - [2, 'B'], - ]); + it('happy path', () => { + expect(cartesianProduct([1, 2], ['A', 'B'])).to.deep.equal([ + [1, 'A'], + [1, 'B'], + [2, 'A'], + [2, 'B'], + ]); + }); }); -}); -describe('unroll events', () => { - it('all Browsing Context events', () => { - expect(unrollEvents([BrowsingContext.AllEvents])).to.deep.equal([ - BrowsingContext.EventNames.LoadEvent, - BrowsingContext.EventNames.DomContentLoadedEvent, - BrowsingContext.EventNames.ContextCreatedEvent, - BrowsingContext.EventNames.ContextDestroyedEvent, - ]); - }); + describe('unroll events', () => { + it('all Browsing Context events', () => { + expect(unrollEvents([BrowsingContext.AllEvents])).to.deep.equal([ + BrowsingContext.EventNames.LoadEvent, + BrowsingContext.EventNames.DomContentLoadedEvent, + BrowsingContext.EventNames.ContextCreatedEvent, + BrowsingContext.EventNames.ContextDestroyedEvent, + ]); + }); - it('all CDP events', () => { - expect(unrollEvents([CDP.AllEvents])).to.deep.equal([ - CDP.EventNames.EventReceivedEvent, - ]); - }); + it('all CDP events', () => { + expect(unrollEvents([CDP.AllEvents])).to.deep.equal([ + CDP.EventNames.EventReceivedEvent, + ]); + }); - it('all Log events', () => { - expect(unrollEvents([Log.AllEvents])).to.deep.equal([ - Log.EventNames.LogEntryAddedEvent, - ]); - }); + it('all Log events', () => { + expect(unrollEvents([Log.AllEvents])).to.deep.equal([ + Log.EventNames.LogEntryAddedEvent, + ]); + }); - it('all Network events', () => { - expect(unrollEvents([Network.AllEvents])).to.deep.equal([ - Network.EventNames.BeforeRequestSentEvent, - Network.EventNames.FetchErrorEvent, - Network.EventNames.ResponseStartedEvent, - Network.EventNames.ResponseCompletedEvent, - ]); - }); + it('all Network events', () => { + expect(unrollEvents([Network.AllEvents])).to.deep.equal([ + Network.EventNames.BeforeRequestSentEvent, + Network.EventNames.FetchErrorEvent, + Network.EventNames.ResponseStartedEvent, + Network.EventNames.ResponseCompletedEvent, + ]); + }); - it('all Script events', () => { - expect(unrollEvents([Script.AllEvents])).to.deep.equal([ - Script.EventNames.MessageEvent, - ]); - }); + it('all Script events', () => { + expect(unrollEvents([Script.AllEvents])).to.deep.equal([ + Script.EventNames.MessageEvent, + ]); + }); - it('discrete events', () => { - expect( - unrollEvents([ + it('discrete events', () => { + expect( + unrollEvents([ + CDP.EventNames.EventReceivedEvent, + Log.EventNames.LogEntryAddedEvent, + ]) + ).to.deep.equal([ CDP.EventNames.EventReceivedEvent, Log.EventNames.LogEntryAddedEvent, - ]) - ).to.deep.equal([ - CDP.EventNames.EventReceivedEvent, - Log.EventNames.LogEntryAddedEvent, - ]); - }); + ]); + }); - it('all and discrete events', () => { - expect( - unrollEvents([ - CDP.AllEvents, + it('all and discrete events', () => { + expect( + unrollEvents([ + CDP.AllEvents, + CDP.EventNames.EventReceivedEvent, + Log.EventNames.LogEntryAddedEvent, + ]) + ).to.deep.equal([ + CDP.EventNames.EventReceivedEvent, CDP.EventNames.EventReceivedEvent, Log.EventNames.LogEntryAddedEvent, - ]) - ).to.deep.equal([ - CDP.EventNames.EventReceivedEvent, - CDP.EventNames.EventReceivedEvent, - Log.EventNames.LogEntryAddedEvent, - ]); + ]); + }); }); }); diff --git a/src/bidiMapper/domains/network/networkRequest.ts b/src/bidiMapper/domains/network/networkRequest.ts index 88c2464553..be6ba66bb4 100644 --- a/src/bidiMapper/domains/network/networkRequest.ts +++ b/src/bidiMapper/domains/network/networkRequest.ts @@ -290,7 +290,7 @@ export class NetworkRequest { url: this.#responseReceivedEvent.response.url, protocol: this.#responseReceivedEvent.response.protocol ?? '', status: - this.#responseReceivedExtraInfoEvent?.statusCode || + this.#responseReceivedExtraInfoEvent?.statusCode ?? this.#responseReceivedEvent.response.status, statusText: this.#responseReceivedEvent.response.statusText, fromCache: diff --git a/src/bidiMapper/domains/script/scriptEvaluator.ts b/src/bidiMapper/domains/script/scriptEvaluator.ts index 10aeafdbd9..214908850a 100644 --- a/src/bidiMapper/domains/script/scriptEvaluator.ts +++ b/src/bidiMapper/domains/script/scriptEvaluator.ts @@ -516,7 +516,7 @@ export class ScriptEvaluator { // `lineNumber` should be adjusted. lineNumber: cdpExceptionDetails.lineNumber - lineOffset, stackTrace: { - callFrames: callFrames || [], + callFrames: callFrames ?? [], }, text: text || cdpExceptionDetails.text, }; diff --git a/src/bidiServer/index.ts b/src/bidiServer/index.ts index c6efb0107b..252b75ef31 100644 --- a/src/bidiServer/index.ts +++ b/src/bidiServer/index.ts @@ -51,7 +51,7 @@ function parseArguments(): { parser.add_argument('-p', '--port', { help: 'Port that BiDi server should listen to. Default is 8080.', type: 'int', - default: process.env['PORT'] || 8080, + default: process.env['PORT'] ?? 8080, }); parser.add_argument('-c', '--channel', { diff --git a/src/protocol/protocol.ts b/src/protocol/protocol.ts index b33373a15f..ff2f45d3af 100644 --- a/src/protocol/protocol.ts +++ b/src/protocol/protocol.ts @@ -52,8 +52,8 @@ export namespace Message { channel?: Script.Channel; }; - export type CommandRequest = Pick & BiDiCommand; - export type CommandResponse = Pick & ResultData; + export type CommandRequest = BiDiCommand & Pick; + export type CommandResponse = ResultData & Pick; export type EmptyCommand = never; export type EmptyParams = Record; @@ -1380,23 +1380,23 @@ export namespace Input { value: string; }; - export type PointerUpAction = { + export type PointerUpAction = PointerCommonProperties & { type: ActionType.PointerUp; button: number; - } & PointerCommonProperties; + }; - export type PointerDownAction = { + export type PointerDownAction = PointerCommonProperties & { type: ActionType.PointerDown; button: number; - } & PointerCommonProperties; + }; - export type PointerMoveAction = { + export type PointerMoveAction = PointerCommonProperties & { type: ActionType.PointerMove; x: number; y: number; duration?: number; origin?: Origin; - } & PointerCommonProperties; + }; export type WheelScrollAction = { type: ActionType.Scroll;