Skip to content

Commit

Permalink
fix: types import in export file
Browse files Browse the repository at this point in the history
  • Loading branch information
andostronaut committed Dec 18, 2024
1 parent c1556ae commit 1da10eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const driverBrowsers: Record<string, string> = {
const seleniumExceptions: Record<string, string> = {
WebDriverError: 'General WebDriver error.',
NoSuchElementError: 'The requested element could not be found in the DOM.',
TimeoutError: 'The operation did not complete within the specified timeout.',
TimeoutError:
'The operation did not complete within the specified timeout.',
SessionNotCreatedError: 'A new session could not be created.',
ScriptTimeoutError: 'A script execution timeout occurred.',
StaleElementReferenceError:
Expand Down
50 changes: 27 additions & 23 deletions src/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
} from './utils.ts'
import {
DataPoint,
DataResult,
DriverBrowser,
MonthCount,
MonthValue,
TDataResult,
TDriverBrowser,
TJSON,
ReportSchema,
} from './types.ts'

const exportGeneratedLog = (
{ results }: { results: Array<TDataResult> },
{ results }: { results: Array<DataResult> },
): void => {
const dirPath = join(Deno.cwd(), 'drowser/logs')
const hasDir = existsSync(dirPath)
Expand All @@ -40,7 +40,8 @@ const exportGeneratedLog = (

const writeResult = () =>
results.forEach((r) => {
const logRow = `[${r.timestamp}] - Test with ${r.name} is ${r.status}`
const logRow =
`[${r.timestamp}] - Test with ${r.name} is ${r.status}`
Deno.writeTextFile(logFilePath, `${logRow}\n`, { append: true })
})

Expand All @@ -55,8 +56,8 @@ const exportGeneratedLog = (

const exportJSONReport = (
{ results, browser }: {
results: Array<TDataResult>
browser: TDriverBrowser
results: Array<DataResult>
browser: DriverBrowser
},
): void => {
const filePath = join(Deno.cwd(), 'drowser-reports.json')
Expand All @@ -73,7 +74,7 @@ const exportJSONReport = (
}

if (Array.isArray(results) && results.length > 0) {
const jsonData = readJsonSync(filePath) as TJSON
const jsonData = readJsonSync(filePath) as ReportSchema

const month = getCurrentMonth({ type: 'short' })

Expand All @@ -83,11 +84,12 @@ const exportJSONReport = (
}
}

const flatedTotalTests = jsonData.drowser.metadata.current_month === month
? jsonData.drowser.cases.flatMap((item) => item.cases).filter((c) =>
c.month_of_test === month
)
: []
const flatedTotalTests =
jsonData.drowser.metadata.current_month === month
? jsonData.drowser.cases.flatMap((item) => item.cases).filter((
c,
) => c.month_of_test === month)
: []
const totalTests = [
...flatedTotalTests,
...results,
Expand Down Expand Up @@ -120,7 +122,9 @@ const exportJSONReport = (
({ status }: { status: string }) => status,
)

const CombinedTestCoverage = getCoverage({ results: CombinedTotalTests })
const CombinedTestCoverage = getCoverage({
results: CombinedTotalTests,
})

const CombinedAvgTestDuration = getAverageDuration({
results: CombinedTotalTests,
Expand Down Expand Up @@ -149,15 +153,15 @@ const exportJSONReport = (
.data as DataPoint[] ?? [],
},
],
passing_tests:
jsonData?.drowser?.metrics?.graphs?.passing_tests as MonthCount[] ??
[],
failed_tests:
jsonData?.drowser?.metrics?.graphs?.failed_tests as MonthCount[] ??
[],
test_coverage:
jsonData?.drowser?.metrics?.graphs?.test_coverage as MonthCount[] ??
[],
passing_tests: jsonData?.drowser?.metrics?.graphs
?.passing_tests as MonthCount[] ??
[],
failed_tests: jsonData?.drowser?.metrics?.graphs
?.failed_tests as MonthCount[] ??
[],
test_coverage: jsonData?.drowser?.metrics?.graphs
?.test_coverage as MonthCount[] ??
[],
avg_test_duration: jsonData?.drowser?.metrics?.graphs
?.avg_test_duration as MonthCount[] ?? [],
flaky_tests: jsonData?.drowser?.metrics?.graphs
Expand Down

0 comments on commit 1da10eb

Please sign in to comment.