diff --git a/src/driver.ts b/src/driver.ts index e64bd5c..f7cce97 100644 --- a/src/driver.ts +++ b/src/driver.ts @@ -1,13 +1,13 @@ import { assert, Builder, By, isEmpty, join, Kia } from '../deps.ts' import type { - TCaseFn, - TConfigJSON, - TData, - TDriverParams, - TDriverServiceCaseParamsBuilder, - TDrowserDriverResponse, - TDrowserServiceCase, - TDrowserThenableWebDriver, + CaseFn, + ConfigJSON, + Data, + DriverParams, + DriverServiceCaseParamsBuilder, + DrowserDriverResponse, + DrowserServiceCase, + DrowserThenableWebDriver, } from './types.ts' import { isValidHttpUrl, result as resultData } from './utils.ts' import { @@ -20,13 +20,13 @@ import { exportGeneratedLog, exportJSONReport } from './export.ts' const driver = async ({ browser, -}: TDriverParams): Promise => { - const data: TData = { url: '', results: [] } +}: DriverParams): Promise => { + const data: Data = { url: '', results: [] } const configPath = join(Deno.cwd(), 'drowser.json') try { await Deno.stat(configPath) - const { url }: TConfigJSON = JSON.parse( + const { url }: ConfigJSON = JSON.parse( await Deno.readTextFile(configPath), ) @@ -39,7 +39,9 @@ const driver = async ({ data.url = url } catch (error) { if (error instanceof Deno.errors.NotFound) { - throw new Error('An error occurred, please create drowser.json file.') + throw new Error( + 'An error occurred, please create drowser.json file.', + ) } if (!(error instanceof Deno.errors.NotFound)) { @@ -50,15 +52,17 @@ const driver = async ({ } if (isEmpty(browser) || !driverBrowserList.includes(browser)) { - throw new Error('An error occurred, please provide a valid browser driver') + throw new Error( + 'An error occurred, please provide a valid browser driver', + ) } - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { if (isEmpty(data.url) || !isValidHttpUrl({ url: data.url })) reject() const builder = new Builder() .forBrowser(driverBrowsers[browser]) - .build() as TDrowserThenableWebDriver + .build() as DrowserThenableWebDriver const service = { cases: [] } @@ -75,16 +79,16 @@ const driver = async ({ .finally(() => { const methodPromises: Promise[] = [] - service.cases.forEach((c: TDrowserServiceCase) => { + service.cases.forEach((c: DrowserServiceCase) => { if (typeof c === 'object') { const omitedBuilder = - builder as unknown as TDriverServiceCaseParamsBuilder + builder as unknown as DriverServiceCaseParamsBuilder const megaBuilder = { builder: omitedBuilder, assert, by: By, } - const method = c.fn as TCaseFn + const method = c.fn as CaseFn const methodPromise = method(megaBuilder) const start = performance.now() diff --git a/src/types.ts b/src/types.ts index 773236f..3f9259e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,84 +1,84 @@ import { assert } from '../deps.ts' import type { By, ThenableWebDriver } from '../deps.ts' -export type TDriverParams = { - browser: TDriverBrowser +export type DriverParams = { + browser: DriverBrowser } -export type TDriverBrowser = 'chrome' | 'firefox' | 'safari' | 'edge' +export type DriverBrowser = 'chrome' | 'firefox' | 'safari' | 'edge' -export type TConfigJSON = { +export type ConfigJSON = { url: string exportPdf: boolean } -export type TDataResult = { +export type DataResult = { id?: string name: string status: string timestamp?: Date duration: number month_of_test?: string - browser: TDriverBrowser + browser: DriverBrowser } -export type TData = { +export type Data = { url: string - results: Array + results: Array } -export type TDrowserThenableWebDriver = ThenableWebDriver +export type DrowserThenableWebDriver = ThenableWebDriver -export type TDrowserBuilder = Omit< +export type DrowserBuilder = Omit< ThenableWebDriver, 'get' > -export type TDriverServiceCaseParamsBuilder = Omit< +export type DriverServiceCaseParamsBuilder = Omit< ThenableWebDriver, 'get' | 'quit' | 'then' | 'catch' | 'close' | 'finally' > -export type TDriverServiceCaseParamsAssert = typeof assert +export type DriverServiceCaseParamsAssert = typeof assert -export type TDriverServiceCaseParamsBy = typeof By +export type DriverServiceCaseParamsBy = typeof By -export type TDriverBrowserCaseParams = { - builder: TDriverServiceCaseParamsBuilder - assert: TDriverServiceCaseParamsAssert - by: TDriverServiceCaseParamsBy +export type DriverBrowserCaseParams = { + builder: DriverServiceCaseParamsBuilder + assert: DriverServiceCaseParamsAssert + by: DriverServiceCaseParamsBy } -export type TDrowserServiceCase = { +export type DrowserServiceCase = { name: string fn: ( - params: TDriverBrowserCaseParams, + params: DriverBrowserCaseParams, ) => void } -export type TDrowserService = { - cases: Array +export type DrowserService = { + cases: Array } -export type TCaseFn = ( - params: TDriverBrowserCaseParams, +export type CaseFn = ( + params: DriverBrowserCaseParams, ) => Promise -export type TDrowserDriverResponse = { - service: TDrowserService +export type DrowserDriverResponse = { + service: DrowserService } -export type TAssertFunction = ( +export type AssertFunction = ( actual: unknown, expected: unknown, msg?: string, ) => void -export type TAssertError = { +export type AssertError = { name: string } -export type TIsValidHttpUrlParams = { +export type IsValidHttpUrlParams = { url: string } @@ -102,7 +102,7 @@ export type MonthValue = { value: number } -export type TJSON = { +export type ReportSchema = { drowser: { metadata: { current_month: string @@ -131,35 +131,36 @@ export type TJSON = { coverage: number flaky: number month_of_test: string - browser: TDriverBrowser - cases: Array + browser: DriverBrowser + cases: Array }, ] } } const types = { - TDriverParams: {} as TDriverParams, - TDriverBrowser: {} as TDriverBrowser, - TConfigJSON: {} as TConfigJSON, - TData: {} as TData, - TDrowserThenableWebDriver: {} as TDrowserThenableWebDriver, - TDrowserBuilder: {} as TDrowserBuilder, - TDriverServiceCaseParamsBuilder: {} as TDriverServiceCaseParamsBuilder, - TDriverServiceCaseParamsAssert: {} as TDriverServiceCaseParamsAssert, - TDriverServiceCaseParamsBy: {} as TDriverServiceCaseParamsBy, - TDriverBrowserCaseParams: {} as TDriverBrowserCaseParams, - TDrowserServiceCase: {} as TDrowserServiceCase, - TDrowserService: {} as TDrowserService, - TCaseFn: {} as TCaseFn, - TDrowserDriverResponse: {} as TDrowserDriverResponse, - TAssertFunction: {} as TAssertFunction, - TAssertError: {} as TAssertError, - TIsValidHttpUrlParams: {} as TIsValidHttpUrlParams, + TDriverParams: {} as DriverParams, + DriverBrowser: {} as DriverBrowser, + ConfigJSON: {} as ConfigJSON, + Data: {} as Data, + DrowserThenableWebDriver: {} as DrowserThenableWebDriver, + DrowserBuilder: {} as DrowserBuilder, + DriverServiceCaseParamsBuilder: {} as DriverServiceCaseParamsBuilder, + DriverServiceCaseParamsAssert: {} as DriverServiceCaseParamsAssert, + DriverServiceCaseParamsBy: {} as DriverServiceCaseParamsBy, + DriverBrowserCaseParams: {} as DriverBrowserCaseParams, + DrowserServiceCase: {} as DrowserServiceCase, + DrowserService: {} as DrowserService, + CaseFn: {} as CaseFn, + DrowserDriverResponse: {} as DrowserDriverResponse, + AssertFunction: {} as AssertFunction, + AssertError: {} as AssertError, + IsValidHttpUrlParams: {} as IsValidHttpUrlParams, DataPoint: {} as DataPoint, DataSet: {} as DataSet, MonthCount: {} as MonthCount, MonthValue: {} as MonthValue, + ReportSchema: {} as ReportSchema, } export default types