Skip to content

Commit

Permalink
feat: migrate export log , pdf to be at drowser json config (#29)
Browse files Browse the repository at this point in the history
* feat: add prettierrc json config and update git ignore

* feat: add import map

* docs: use contributing and code of conduct

* feat: install selenium webdriver and std assert on deps

* feat: configure deno.json use fmt, lint, compiler options

* chore: delete tsconfig

* feat: create browser engines, types, constants

* feat: create gh workflows to auto create pull request

* feat: add edge to browser enginer and remove utils folder from import maps

* feat: clean arch and update deno fmt, lint

* feat: re-arch pkg to be drowser and clean file, dir

* feat: handle drowser json config and validate url

* feat: handle new promise execution for driver and return as value driver from selenium

* fix: handle return promise in driver in get url

* chore: clean lib and move basic example to examples folder

* feat: create pkg types and handle builder quit outside the pkg for now

* feat: create service type, obj to set extra services for pkg and create types

* docs: update readme docs

* docs: update readme docs

* docs: update readme docs

* feat: set version to v0.1.0

* fix: for todo specify builder.quit to be able to quit internaly

* docs: update docs, don't use hard tabs on readme

* feat: migrate export log , pdf to be at drowser json config
  • Loading branch information
Ando authored Apr 29, 2024
1 parent 61f7b59 commit 7358fdf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 9 additions & 5 deletions driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import { driverBrowser, driverBrowserType } from '@pkg/constants.ts'
import { generatedLog, generatedPdf } from '@pkg/export.ts'

const driver = async (
{ browserType, exportPdf = false, exportLog = true }: TDriverParams,
{ browserType }: TDriverParams,
): Promise<TDrowserDriverResponse> => {
console.log({ browserType, exportPdf, exportLog })

const data: TData = { url: '', results: [], log: [] }
const configPath = join(Deno.cwd(), 'drowser.json')

try {
const configPath = join(Deno.cwd(), 'drowser.json')
await Deno.stat(configPath)
const { url }: TConfigJSON = JSON.parse(await Deno.readTextFile(configPath))
const { url }: TConfigJSON = JSON.parse(
await Deno.readTextFile(configPath),
)

if (isEmpty(url) || !isValidHttpUrl({ url })) {
throw new Error(
Expand Down Expand Up @@ -68,6 +68,10 @@ const driver = async (
.catch((err) => reject(err))
// .finally(() => builder.quit()) //TODO: Need to find a solution to handle this internaly
.finally(() => {
const { exportLog, exportPdf }: TConfigJSON = JSON.parse(
Deno.readTextFileSync(configPath),
)

if (exportLog) generatedLog()
if (exportPdf) generatedPdf()
})
Expand Down
4 changes: 3 additions & 1 deletion drowser.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"url": "http://localhost:3000"
"url": "http://localhost:3000",
"exportPdf": false,
"exportLog": false
}
4 changes: 2 additions & 2 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import type { ThenableWebDriver } from '@pkg/deps.ts'

export type TDriverParams = {
browserType: TDriverBrowser
exportPdf?: boolean
exportLog?: boolean
}

export type TDriverBrowser = 'chrome' | 'firefox' | 'safari' | 'edge'

export type TConfigJSON = {
url: string
exportPdf: boolean
exportLog: boolean
}

export type TData = {
Expand Down

0 comments on commit 7358fdf

Please sign in to comment.