-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability for configuration through jest-playwright.config.js file
- Loading branch information
Showing
4 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,44 @@ | ||
import { CHROMIUM, FIREFOX, WEBKIT } from './constants'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { promisify } from 'util'; | ||
import { CHROMIUM, FIREFOX, WEBKIT, DEFAULT_CONFIG } from './constants'; | ||
|
||
function checkBrowserEnv(param) { | ||
const exists = promisify(fs.exists); | ||
|
||
export function checkBrowserEnv(param) { | ||
if (param !== CHROMIUM && param !== FIREFOX && param !== WEBKIT) { | ||
throw new Error(`Wrong browser type. Should be one of [${CHROMIUM}, ${FIREFOX}, ${WEBKIT}], but got ${param}`) | ||
} | ||
} | ||
|
||
export default checkBrowserEnv | ||
export function getBrowserType(config) { | ||
const processBrowser = process.env.BROWSER; | ||
if (processBrowser) { | ||
return processBrowser | ||
} else { | ||
return config.browser || CHROMIUM | ||
} | ||
} | ||
|
||
export async function readConfig() { | ||
const defaultConfig = DEFAULT_CONFIG; | ||
|
||
const hasCustomConfigPath = !!process.env.JEST_PLAYWRIGHT_CONFIG; | ||
const configPath = | ||
process.env.JEST_PLAYWRIGHT_CONFIG || 'jest-playwright.config.js'; | ||
const absConfigPath = path.resolve(process.cwd(), configPath) | ||
const configExists = await exists(absConfigPath); | ||
|
||
if (hasCustomConfigPath && !configExists) { | ||
throw new Error( | ||
`Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${configPath}`, | ||
) | ||
} | ||
|
||
if (!hasCustomConfigPath && !configExists) { | ||
return defaultConfig | ||
} | ||
|
||
const localConfig = await require(absConfigPath); | ||
return Object.assign({}, defaultConfig, localConfig); | ||
} |