Skip to content

Commit 0f7d043

Browse files
authored
chore(tsc+lint): Enhancing project tsc and linting (#1873)
* Reapply "chore(tsc+lint): Enhancing project tsc and linting (#1867)" This reverts commit 4b9bedb. * Separate build vs normal tsc check since it broke the release * Add warning to be verbose on the exclude behavior * Ensure no test folder in the lib folder
1 parent 568f8d4 commit 0f7d043

11 files changed

+52
-36
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default wdioEslint.config([
44
{
55
ignores: [
66
'lib',
7-
'types'
7+
'**/*/dist'
88
]
99
},
1010
/**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"compile": "tsc --build tsconfig.build.json",
4949
"tsc:root-types": "tsc jasmine.d.ts jest.d.ts",
5050
"test": "run-s test:*",
51+
"test:tsc": "tsc --project tsconfig.json --noEmit",
5152
"test:lint": "eslint .",
5253
"test:unit": "vitest --run",
5354
"test:types": "node test-types/copy && npm run ts && npm run clean:tests && npm run tsc:root-types",

src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const waitUntil = async (
5353
// wait for condition to be truthy
5454
try {
5555
const start = Date.now()
56-
// eslint-disable-next-line no-constant-condition
5756
while (true) {
5857
if (Date.now() - start > wait) {
5958
throw new Error('timeout')

test/matchers/mock/toBeRequested.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { vi, test, describe, expect } from 'vitest'
2+
// @ts-ignore TODO fix me
23
import type { Matches, Mock } from 'webdriverio'
34

45
import { toBeRequested } from '../../../src/matchers/mock/toBeRequested.js'

test/matchers/mock/toBeRequestedTimes.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { vi, test, describe, expect } from 'vitest'
2+
// @ts-ignore TODO fix me
23
import type { Matches, Mock } from 'webdriverio'
34

45
import { toBeRequestedTimes } from '../../../src/matchers/mock/toBeRequestedTimes.js'

test/util/elementsUtil.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ vi.mock('@wdio/globals')
88
describe('elementsUtil', () => {
99
describe('wrapExpectedWithArray', () => {
1010
test('is not array ', async () => {
11-
const el = await $('sel')
11+
const el = (await $('sel')) as unknown as WebdriverIO.Element
1212
const actual = wrapExpectedWithArray(el, 'Test Actual', 'Test Expected')
1313
expect(actual).toEqual('Test Expected')
1414
})
1515

1616
test('is array ', async () => {
17-
const els = await $$('sel')
17+
const els = (await $$('sel')) as unknown as WebdriverIO.ElementArray
1818
const actual = wrapExpectedWithArray(els, ['Test Actual', 'Test Actual'], 'Test Expected')
1919
expect(actual).toEqual(['Test Expected'])
2020
})

test/util/refetchElements.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('refetchElements', () => {
99
let els: WebdriverIO.ElementArray
1010

1111
beforeEach(async () => {
12-
els = await $$('parent')
12+
els = (await $$('parent')) as unknown as WebdriverIO.ElementArray
1313
// @ts-ignore
1414
els.parent._length = 5
1515
})

tsconfig.build.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
33
"exclude": [
4+
// Warning: not excluding test folder change the release folder root structure
45
"./test/**/*.ts"
56
]
6-
}
7+
}

types/expect-webdriverio.d.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
type ServiceInstance = import('@wdio/types').Services.ServiceInstance;
2-
type Test = import('@wdio/types').Frameworks.Test;
3-
type TestResult = import('@wdio/types').Frameworks.TestResult;
4-
type PickleStep = import('@wdio/types').Frameworks.PickleStep;
5-
type Scenario = import('@wdio/types').Frameworks.Scenario;
6-
type SnapshotResult = import('@vitest/snapshot').SnapshotResult;
7-
type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState;
1+
/* eslint-disable @typescript-eslint/consistent-type-imports*/
2+
type ServiceInstance = import('@wdio/types').Services.ServiceInstance
3+
type Test = import('@wdio/types').Frameworks.Test
4+
type TestResult = import('@wdio/types').Frameworks.TestResult
5+
type PickleStep = import('@wdio/types').Frameworks.PickleStep
6+
type Scenario = import('@wdio/types').Frameworks.Scenario
7+
type SnapshotResult = import('@vitest/snapshot').SnapshotResult
8+
type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState
89

910
declare namespace ExpectWebdriverIO {
1011
const expect: ExpectWebdriverIO.Expect
1112
function setOptions(options: DefaultOptions): void
13+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1214
function getConfig(): any
1315

1416
interface SnapshotServiceArgs {
@@ -23,32 +25,34 @@ declare namespace ExpectWebdriverIO {
2325
}
2426

2527
interface SoftFailure {
26-
error: Error;
27-
matcherName: string;
28-
location?: string;
28+
error: Error
29+
matcherName: string
30+
location?: string
2931
}
3032

3133
class SoftAssertService {
32-
static getInstance(): SoftAssertService;
33-
setCurrentTest(testId: string, testName?: string, testFile?: string): void;
34-
clearCurrentTest(): void;
35-
getCurrentTestId(): string | null;
36-
addFailure(error: Error, matcherName: string): void;
37-
getFailures(testId?: string): SoftFailure[];
38-
clearFailures(testId?: string): void;
39-
assertNoFailures(testId?: string): void;
34+
static getInstance(): SoftAssertService
35+
setCurrentTest(testId: string, testName?: string, testFile?: string): void
36+
clearCurrentTest(): void
37+
getCurrentTestId(): string | null
38+
addFailure(error: Error, matcherName: string): void
39+
getFailures(testId?: string): SoftFailure[]
40+
clearFailures(testId?: string): void
41+
assertNoFailures(testId?: string): void
4042
}
4143

4244
interface SoftAssertionServiceOptions {
43-
autoAssertOnTestEnd?: boolean;
45+
autoAssertOnTestEnd?: boolean
4446
}
4547

4648
class SoftAssertionService implements ServiceInstance {
47-
constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: any, config?: any);
48-
beforeTest(test: Test): void;
49-
beforeStep(step: PickleStep, scenario: Scenario): void;
50-
afterTest(test: Test, context: any, result: TestResult): void;
51-
afterStep(step: PickleStep, scenario: Scenario, result: { passed: boolean, error?: Error }): void;
49+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
50+
constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: any, config?: any)
51+
beforeTest(test: Test): void
52+
beforeStep(step: PickleStep, scenario: Scenario): void
53+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54+
afterTest(test: Test, context: any, result: TestResult): void
55+
afterStep(step: PickleStep, scenario: Scenario, result: { passed: boolean, error?: Error }): void
5256
}
5357

5458
interface AssertionResult {
@@ -59,7 +63,9 @@ declare namespace ExpectWebdriverIO {
5963
const matchers: Map<
6064
string,
6165
(
66+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6267
actual: any,
68+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6369
...expected: any[]
6470
) => Promise<AssertionResult>
6571
>
@@ -79,6 +85,7 @@ declare namespace ExpectWebdriverIO {
7985
* expect(el).toHaveAttribute('attr', 'value', { ... }) // expectedValue is `['attr', 'value]`
8086
* ```
8187
*/
88+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8289
expectedValue?: any,
8390
/**
8491
* Options that the user has passed in, e.g. `expect(el).toHaveText('foo', { ignoreCase: true })` -> `{ ignoreCase: true }`
@@ -238,10 +245,10 @@ declare namespace ExpectWebdriverIO {
238245
* **Usage**
239246
* ```js
240247
* // Check if an element has the class 'btn'
241-
* await expect(element).toHaveElementClass('btn');
248+
* await expect(element).toHaveElementClass('btn')
242249
*
243250
* // Check if an element has any of the specified classes
244-
* await expect(element).toHaveElementClass(['btn', 'btn-large']);
251+
* await expect(element).toHaveElementClass(['btn', 'btn-large'])
245252
* ```
246253
*/
247254
toHaveElementClass(className: string | RegExp | Array<string | RegExp> | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
@@ -251,6 +258,7 @@ declare namespace ExpectWebdriverIO {
251258
*/
252259
toHaveElementProperty(
253260
property: string | RegExp | ExpectWebdriverIO.PartialMatcher,
261+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
254262
value?: any,
255263
options?: ExpectWebdriverIO.StringOptions
256264
): R
@@ -418,7 +426,7 @@ declare namespace ExpectWebdriverIO {
418426
toBeElementsArrayOfSize(
419427
size: number | ExpectWebdriverIO.NumberOptions,
420428
options?: ExpectWebdriverIO.NumberOptions
421-
): R & Promise<WebdriverIO.ElementArray>;
429+
): R & Promise<WebdriverIO.ElementArray>
422430

423431
// ==== network mock ====
424432
/**
@@ -479,8 +487,10 @@ declare namespace ExpectWebdriverIO {
479487
type JsonCompatible = jsonObject | jsonArray
480488

481489
interface PartialMatcher {
490+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
482491
sample?: any
483492
$$typeof: symbol
493+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
484494
asymmetricMatch(...args: any[]): boolean
485495
toString(): string
486496
}
@@ -527,6 +537,7 @@ declare namespace ExpectWebdriverIO {
527537
}
528538

529539
interface AsymmetricMatchers {
540+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
530541
any(expectedObject: any): PartialMatcher
531542
anything(): PartialMatcher
532543
arrayContaining(sample: Array<unknown>): PartialMatcher

types/standalone.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/consistent-type-imports*/
12
/// <reference types="./expect-webdriverio.js"/>
23

34
type ChainablePromiseElement = import('webdriverio').ChainablePromiseElement
@@ -21,6 +22,7 @@ declare namespace ExpectWebdriverIO {
2122
} & AsymmetricMatchers
2223

2324
interface AsymmetricMatchers {
25+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2426
any(expectedObject: any): PartialMatcher
2527
anything(): PartialMatcher
2628
arrayContaining(sample: Array<unknown>): PartialMatcher

0 commit comments

Comments
 (0)