Skip to content

Commit c72fd29

Browse files
committed
feat: improve types export and name
1 parent 0b6df3f commit c72fd29

2 files changed

Lines changed: 71 additions & 66 deletions

File tree

src/driver.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { assert, Builder, By, isEmpty, join, Kia } from '../deps.ts'
22
import type {
3-
TCaseFn,
4-
TConfigJSON,
5-
TData,
6-
TDriverParams,
7-
TDriverServiceCaseParamsBuilder,
8-
TDrowserDriverResponse,
9-
TDrowserServiceCase,
10-
TDrowserThenableWebDriver,
3+
CaseFn,
4+
ConfigJSON,
5+
Data,
6+
DriverParams,
7+
DriverServiceCaseParamsBuilder,
8+
DrowserDriverResponse,
9+
DrowserServiceCase,
10+
DrowserThenableWebDriver,
1111
} from './types.ts'
1212
import { isValidHttpUrl, result as resultData } from './utils.ts'
1313
import {
@@ -20,13 +20,13 @@ import { exportGeneratedLog, exportJSONReport } from './export.ts'
2020

2121
const driver = async ({
2222
browser,
23-
}: TDriverParams): Promise<TDrowserDriverResponse> => {
24-
const data: TData = { url: '', results: [] }
23+
}: DriverParams): Promise<DrowserDriverResponse> => {
24+
const data: Data = { url: '', results: [] }
2525
const configPath = join(Deno.cwd(), 'drowser.json')
2626

2727
try {
2828
await Deno.stat(configPath)
29-
const { url }: TConfigJSON = JSON.parse(
29+
const { url }: ConfigJSON = JSON.parse(
3030
await Deno.readTextFile(configPath),
3131
)
3232

@@ -39,7 +39,9 @@ const driver = async ({
3939
data.url = url
4040
} catch (error) {
4141
if (error instanceof Deno.errors.NotFound) {
42-
throw new Error('An error occurred, please create drowser.json file.')
42+
throw new Error(
43+
'An error occurred, please create drowser.json file.',
44+
)
4345
}
4446

4547
if (!(error instanceof Deno.errors.NotFound)) {
@@ -50,15 +52,17 @@ const driver = async ({
5052
}
5153

5254
if (isEmpty(browser) || !driverBrowserList.includes(browser)) {
53-
throw new Error('An error occurred, please provide a valid browser driver')
55+
throw new Error(
56+
'An error occurred, please provide a valid browser driver',
57+
)
5458
}
5559

56-
return new Promise<TDrowserDriverResponse>((resolve, reject) => {
60+
return new Promise<DrowserDriverResponse>((resolve, reject) => {
5761
if (isEmpty(data.url) || !isValidHttpUrl({ url: data.url })) reject()
5862

5963
const builder = new Builder()
6064
.forBrowser(driverBrowsers[browser])
61-
.build() as TDrowserThenableWebDriver
65+
.build() as DrowserThenableWebDriver
6266

6367
const service = { cases: [] }
6468

@@ -75,16 +79,16 @@ const driver = async ({
7579
.finally(() => {
7680
const methodPromises: Promise<void>[] = []
7781

78-
service.cases.forEach((c: TDrowserServiceCase) => {
82+
service.cases.forEach((c: DrowserServiceCase) => {
7983
if (typeof c === 'object') {
8084
const omitedBuilder =
81-
builder as unknown as TDriverServiceCaseParamsBuilder
85+
builder as unknown as DriverServiceCaseParamsBuilder
8286
const megaBuilder = {
8387
builder: omitedBuilder,
8488
assert,
8589
by: By,
8690
}
87-
const method = c.fn as TCaseFn
91+
const method = c.fn as CaseFn
8892
const methodPromise = method(megaBuilder)
8993

9094
const start = performance.now()

src/types.ts

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
import { assert } from '../deps.ts'
22
import type { By, ThenableWebDriver } from '../deps.ts'
33

4-
export type TDriverParams = {
5-
browser: TDriverBrowser
4+
export type DriverParams = {
5+
browser: DriverBrowser
66
}
77

8-
export type TDriverBrowser = 'chrome' | 'firefox' | 'safari' | 'edge'
8+
export type DriverBrowser = 'chrome' | 'firefox' | 'safari' | 'edge'
99

10-
export type TConfigJSON = {
10+
export type ConfigJSON = {
1111
url: string
1212
exportPdf: boolean
1313
}
1414

15-
export type TDataResult = {
15+
export type DataResult = {
1616
id?: string
1717
name: string
1818
status: string
1919
timestamp?: Date
2020
duration: number
2121
month_of_test?: string
22-
browser: TDriverBrowser
22+
browser: DriverBrowser
2323
}
2424

25-
export type TData = {
25+
export type Data = {
2626
url: string
27-
results: Array<TDataResult>
27+
results: Array<DataResult>
2828
}
2929

30-
export type TDrowserThenableWebDriver = ThenableWebDriver
30+
export type DrowserThenableWebDriver = ThenableWebDriver
3131

32-
export type TDrowserBuilder = Omit<
32+
export type DrowserBuilder = Omit<
3333
ThenableWebDriver,
3434
'get'
3535
>
3636

37-
export type TDriverServiceCaseParamsBuilder = Omit<
37+
export type DriverServiceCaseParamsBuilder = Omit<
3838
ThenableWebDriver,
3939
'get' | 'quit' | 'then' | 'catch' | 'close' | 'finally'
4040
>
4141

42-
export type TDriverServiceCaseParamsAssert = typeof assert
42+
export type DriverServiceCaseParamsAssert = typeof assert
4343

44-
export type TDriverServiceCaseParamsBy = typeof By
44+
export type DriverServiceCaseParamsBy = typeof By
4545

46-
export type TDriverBrowserCaseParams = {
47-
builder: TDriverServiceCaseParamsBuilder
48-
assert: TDriverServiceCaseParamsAssert
49-
by: TDriverServiceCaseParamsBy
46+
export type DriverBrowserCaseParams = {
47+
builder: DriverServiceCaseParamsBuilder
48+
assert: DriverServiceCaseParamsAssert
49+
by: DriverServiceCaseParamsBy
5050
}
5151

52-
export type TDrowserServiceCase = {
52+
export type DrowserServiceCase = {
5353
name: string
5454
fn: (
55-
params: TDriverBrowserCaseParams,
55+
params: DriverBrowserCaseParams,
5656
) => void
5757
}
5858

59-
export type TDrowserService = {
60-
cases: Array<TDrowserServiceCase>
59+
export type DrowserService = {
60+
cases: Array<DrowserServiceCase>
6161
}
6262

63-
export type TCaseFn = (
64-
params: TDriverBrowserCaseParams,
63+
export type CaseFn = (
64+
params: DriverBrowserCaseParams,
6565
) => Promise<void>
6666

67-
export type TDrowserDriverResponse = {
68-
service: TDrowserService
67+
export type DrowserDriverResponse = {
68+
service: DrowserService
6969
}
7070

71-
export type TAssertFunction = (
71+
export type AssertFunction = (
7272
actual: unknown,
7373
expected: unknown,
7474
msg?: string,
7575
) => void
7676

77-
export type TAssertError = {
77+
export type AssertError = {
7878
name: string
7979
}
8080

81-
export type TIsValidHttpUrlParams = {
81+
export type IsValidHttpUrlParams = {
8282
url: string
8383
}
8484

@@ -102,7 +102,7 @@ export type MonthValue = {
102102
value: number
103103
}
104104

105-
export type TJSON = {
105+
export type ReportSchema = {
106106
drowser: {
107107
metadata: {
108108
current_month: string
@@ -131,35 +131,36 @@ export type TJSON = {
131131
coverage: number
132132
flaky: number
133133
month_of_test: string
134-
browser: TDriverBrowser
135-
cases: Array<TDataResult>
134+
browser: DriverBrowser
135+
cases: Array<DataResult>
136136
},
137137
]
138138
}
139139
}
140140

141141
const types = {
142-
TDriverParams: {} as TDriverParams,
143-
TDriverBrowser: {} as TDriverBrowser,
144-
TConfigJSON: {} as TConfigJSON,
145-
TData: {} as TData,
146-
TDrowserThenableWebDriver: {} as TDrowserThenableWebDriver,
147-
TDrowserBuilder: {} as TDrowserBuilder,
148-
TDriverServiceCaseParamsBuilder: {} as TDriverServiceCaseParamsBuilder,
149-
TDriverServiceCaseParamsAssert: {} as TDriverServiceCaseParamsAssert,
150-
TDriverServiceCaseParamsBy: {} as TDriverServiceCaseParamsBy,
151-
TDriverBrowserCaseParams: {} as TDriverBrowserCaseParams,
152-
TDrowserServiceCase: {} as TDrowserServiceCase,
153-
TDrowserService: {} as TDrowserService,
154-
TCaseFn: {} as TCaseFn,
155-
TDrowserDriverResponse: {} as TDrowserDriverResponse,
156-
TAssertFunction: {} as TAssertFunction,
157-
TAssertError: {} as TAssertError,
158-
TIsValidHttpUrlParams: {} as TIsValidHttpUrlParams,
142+
TDriverParams: {} as DriverParams,
143+
DriverBrowser: {} as DriverBrowser,
144+
ConfigJSON: {} as ConfigJSON,
145+
Data: {} as Data,
146+
DrowserThenableWebDriver: {} as DrowserThenableWebDriver,
147+
DrowserBuilder: {} as DrowserBuilder,
148+
DriverServiceCaseParamsBuilder: {} as DriverServiceCaseParamsBuilder,
149+
DriverServiceCaseParamsAssert: {} as DriverServiceCaseParamsAssert,
150+
DriverServiceCaseParamsBy: {} as DriverServiceCaseParamsBy,
151+
DriverBrowserCaseParams: {} as DriverBrowserCaseParams,
152+
DrowserServiceCase: {} as DrowserServiceCase,
153+
DrowserService: {} as DrowserService,
154+
CaseFn: {} as CaseFn,
155+
DrowserDriverResponse: {} as DrowserDriverResponse,
156+
AssertFunction: {} as AssertFunction,
157+
AssertError: {} as AssertError,
158+
IsValidHttpUrlParams: {} as IsValidHttpUrlParams,
159159
DataPoint: {} as DataPoint,
160160
DataSet: {} as DataSet,
161161
MonthCount: {} as MonthCount,
162162
MonthValue: {} as MonthValue,
163+
ReportSchema: {} as ReportSchema,
163164
}
164165

165166
export default types

0 commit comments

Comments
 (0)