|
1 | | -import fs from 'fs'; |
2 | | -import path from 'path'; |
3 | | -import { promisify } from 'util'; |
4 | | -import { CHROMIUM, FIREFOX, WEBKIT, DEFAULT_CONFIG } from './constants'; |
| 1 | +import fs from 'fs' |
| 2 | +import path from 'path' |
| 3 | +import { promisify } from 'util' |
| 4 | +import { CHROMIUM, FIREFOX, WEBKIT, DEFAULT_CONFIG } from './constants' |
5 | 5 |
|
6 | | -const exists = promisify(fs.exists); |
| 6 | +const exists = promisify(fs.exists) |
7 | 7 |
|
8 | 8 | export function checkBrowserEnv(param) { |
9 | | - if (param !== CHROMIUM && param !== FIREFOX && param !== WEBKIT) { |
10 | | - throw new Error(`Wrong browser type. Should be one of [${CHROMIUM}, ${FIREFOX}, ${WEBKIT}], but got ${param}`) |
11 | | - } |
| 9 | + if (param !== CHROMIUM && param !== FIREFOX && param !== WEBKIT) { |
| 10 | + throw new Error( |
| 11 | + `Wrong browser type. Should be one of [${CHROMIUM}, ${FIREFOX}, ${WEBKIT}], but got ${param}`, |
| 12 | + ) |
| 13 | + } |
12 | 14 | } |
13 | 15 |
|
14 | 16 | export function getBrowserType(config) { |
15 | | - const processBrowser = process.env.BROWSER; |
16 | | - if (processBrowser) { |
17 | | - return processBrowser |
18 | | - } else { |
19 | | - return config.browser || CHROMIUM |
20 | | - } |
| 17 | + const processBrowser = process.env.BROWSER |
| 18 | + if (processBrowser) { |
| 19 | + return processBrowser |
| 20 | + } |
| 21 | + return config.browser || CHROMIUM |
21 | 22 | } |
22 | 23 |
|
23 | 24 | export async function readConfig() { |
24 | | - const defaultConfig = DEFAULT_CONFIG; |
25 | | - |
26 | | - const hasCustomConfigPath = !!process.env.JEST_PLAYWRIGHT_CONFIG; |
27 | | - const configPath = |
28 | | - process.env.JEST_PLAYWRIGHT_CONFIG || 'jest-playwright.config.js'; |
29 | | - const absConfigPath = path.resolve(process.cwd(), configPath); |
30 | | - const configExists = await exists(absConfigPath); |
31 | | - |
32 | | - if (hasCustomConfigPath && !configExists) { |
33 | | - throw new Error( |
34 | | - `Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${configPath}`, |
35 | | - ) |
36 | | - } |
37 | | - |
38 | | - if (!hasCustomConfigPath && !configExists) { |
39 | | - return defaultConfig |
40 | | - } |
41 | | - |
42 | | - const localConfig = await require(absConfigPath); |
43 | | - return Object.assign({}, defaultConfig, localConfig); |
| 25 | + const defaultConfig = DEFAULT_CONFIG |
| 26 | + |
| 27 | + const hasCustomConfigPath = !!process.env.JEST_PLAYWRIGHT_CONFIG |
| 28 | + const configPath = |
| 29 | + process.env.JEST_PLAYWRIGHT_CONFIG || 'jest-playwright.config.js' |
| 30 | + const absConfigPath = path.resolve(process.cwd(), configPath) |
| 31 | + const configExists = await exists(absConfigPath) |
| 32 | + |
| 33 | + if (hasCustomConfigPath && !configExists) { |
| 34 | + throw new Error( |
| 35 | + `Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${configPath}`, |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + if (!hasCustomConfigPath && !configExists) { |
| 40 | + return defaultConfig |
| 41 | + } |
| 42 | + |
| 43 | + // eslint-disable-next-line global-require,import/no-dynamic-require |
| 44 | + const localConfig = await require(absConfigPath) |
| 45 | + return { ...defaultConfig, ...localConfig } |
44 | 46 | } |
0 commit comments