Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit bdb209a

Browse files
committed
build: switch to ESLint from TSLint (via @hover/javascript)
1 parent a5f8a0b commit bdb209a

File tree

15 files changed

+909
-935
lines changed

15 files changed

+909
-935
lines changed

.eslintrc.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { overrides, ...config } = require('@hover/javascript/eslint')
2+
3+
module.exports = {
4+
...config,
5+
ignorePatterns: ['dom-testing-library.js', 'rollup.input.js'],
6+
parserOptions: {
7+
project: ['tsconfig.json', 'tsconfig.eslint.json'],
8+
},
9+
}

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ before_script:
2020
- yarn add -D "playwright@${PLAYWRIGHT_OVERRIDE_VERSION}"
2121
script:
2222
- yarn rebuild
23-
- yarn test:lint
24-
- yarn test:unit --coverage --runInBand --verbose
23+
- yarn validate
2524
after_success:
2625
- cat coverage/lcov.info | coveralls || echo 'Failed to upload to coveralls...'
2726

jest.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
const config = require('@hover/javascript/jest')
2+
13
module.exports = {
4+
...config,
25
collectCoverageFrom: ['**/*.ts', '!**/*.d.ts'],
3-
transform: {
4-
'\\.ts$': 'ts-jest',
5-
},
6-
moduleFileExtensions: ['ts', 'js', 'json'],
7-
testMatch: ['**/*.test.ts'],
6+
coverageThreshold: {},
87
}

test/extend.test.ts renamed to lib/__tests__/extend.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('lib/extend.ts', () => {
77
let document: playwright.ElementHandle
88

99
it('should require without error', async () => {
10-
await import('../lib/extend')
10+
await import('../extend')
1111
})
1212

1313
it('should launch playwright', async () => {
@@ -54,7 +54,7 @@ describe('lib/extend.ts', () => {
5454

5555
try {
5656
await scope!.getByTitle('missing')
57-
fail()
57+
fail() // eslint-disable-line jest/no-jasmine-globals
5858
} catch (err) {
5959
err.message = err.message.replace(/(\s*at .*(\n|$))+/gm, '\n <stack>:X:X')
6060
expect(err.message).toMatchSnapshot()
File renamed without changes.
File renamed without changes.

test/index.test.ts renamed to lib/__tests__/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path'
22
import * as playwright from 'playwright'
3-
import {getDocument, queries, getQueriesForElement, wait} from '../lib'
3+
import {getDocument, queries, getQueriesForElement, wait} from '..'
44

55
describe('lib/index.ts', () => {
66
let browser: playwright.Browser
@@ -37,6 +37,7 @@ describe('lib/index.ts', () => {
3737

3838
it('should use `wait` properly', async () => {
3939
const {getByText} = getQueriesForElement(await getDocument(page))
40+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
4041
await wait(() => getByText('Loaded!'), {timeout: 7000})
4142
expect(await getByText('Loaded!')).toBeTruthy()
4243
}, 9000)

lib/extend.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
/* eslint-disable func-names, global-require, import/no-dynamic-require */
2+
13
import {getDocument, getQueriesForElement} from '.'
24
import {ElementHandle, IScopedQueryUtils} from './typedefs'
35

4-
// tslint:disable-next-line
5-
let Page, ElementHandle
6+
let Page
7+
let ElementHandle // eslint-disable-line no-redeclare
68

79
function requireOrUndefined(path: string): any {
810
try {
911
return require(path)
10-
} catch (err) {}
12+
} catch (err) {
13+
return null
14+
}
1115
}
1216

1317
try {
@@ -18,15 +22,15 @@ try {
1822
if (ElementHandle && ElementHandle.ElementHandle) ElementHandle = ElementHandle.ElementHandle
1923

2024
Page.prototype.getDocument = getDocument
21-
getQueriesForElement(ElementHandle.prototype, function(this: ElementHandle): ElementHandle {
25+
getQueriesForElement(ElementHandle.prototype, function (this: ElementHandle): ElementHandle {
2226
return this
2327
})
2428

25-
ElementHandle.prototype.getQueriesForElement = function(this: ElementHandle): ElementHandle {
29+
ElementHandle.prototype.getQueriesForElement = function (this: ElementHandle): ElementHandle {
2630
return getQueriesForElement(this)
2731
}
2832
} catch (err) {
29-
// tslint:disable-next-line
33+
// eslint-disable-next-line no-console
3034
console.error('Could not augment playwright functions, do you have a conflicting version?')
3135
throw err
3236
}

lib/index.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,30 @@ type DOMReturnType = ElementHandle | ElementHandle[] | null
3131

3232
type ContextFn = (...args: any[]) => ElementHandle
3333

34+
async function createElementHandle(handle: JSHandle): Promise<ElementHandle | null> {
35+
const element = handle.asElement()
36+
if (element) return element
37+
await handle.dispose()
38+
return null
39+
}
40+
3441
async function createElementHandleArray(handle: JSHandle): Promise<ElementHandle[]> {
3542
const lengthHandle = await handle.getProperty('length')
3643
const length = (await lengthHandle.jsonValue()) as number
3744

3845
const elements: ElementHandle[] = []
46+
47+
/* eslint-disable no-plusplus, no-await-in-loop */
3948
for (let i = 0; i < length; i++) {
4049
const jsElement = await handle.getProperty(i.toString())
4150
const element = await createElementHandle(jsElement)
4251
if (element) elements.push(element)
4352
}
53+
/* eslint-enable no-plusplus, no-await-in-loop */
4454

4555
return elements
4656
}
4757

48-
async function createElementHandle(handle: JSHandle): Promise<ElementHandle | null> {
49-
const element = handle.asElement()
50-
if (element) return element
51-
await handle.dispose()
52-
return null // tslint:disable-line
53-
}
54-
5558
async function covertToElementHandle(handle: JSHandle, asArray: boolean): Promise<DOMReturnType> {
5659
return asArray ? createElementHandleArray(handle) : createElementHandle(handle)
5760
}
@@ -89,15 +92,17 @@ function createDelegateFor<T = DOMReturnType>(
8992
processHandleFn?: (handles: IHandleSet) => Promise<T>,
9093
): (...args: any[]) => Promise<T> {
9194
// @ts-ignore
95+
// eslint-disable-next-line no-param-reassign
9296
processHandleFn = processHandleFn || processQuery
9397

9498
const convertRegExp = (regex: RegExp) => ({regex: regex.source, flags: regex.flags})
9599

96-
return async function(...args: any[]): Promise<T> {
100+
return async function (...args: any[]): Promise<T> {
97101
// @ts-ignore
98102
const containerHandle: ElementHandle = contextFn ? contextFn.apply(this, args) : this
99103

100104
// @ts-ignore
105+
// eslint-disable-next-line no-new-func, @typescript-eslint/no-implied-eval
101106
const evaluateFn = new Function('container, [fnName, ...args]', delegateFnBodyToExecuteInPage)
102107

103108
// Convert RegExp to a special format since they don't serialize well
@@ -132,6 +137,7 @@ export function getQueriesForElement<T>(
132137
contextFn?: ContextFn,
133138
): T & IQueryUtils & IScopedQueryUtils {
134139
const o = object as any
140+
// eslint-disable-next-line no-param-reassign
135141
if (!contextFn) contextFn = () => o
136142

137143
const functionNames: Array<keyof IQueryUtils> = [

0 commit comments

Comments
 (0)