Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit d8212bf

Browse files
authored
feat: log option key renamings to console (#150)
* feat: added logging for deprecated config options * fix: added formatError * fix: uppercase
1 parent 465f4d8 commit d8212bf

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ You can specify a `jest-playwright.config.js` at the root of the project or defi
8383
- `webkit` Each test runs Webkit.
8484
- `devices` <[string[]]>. Define a [devices](https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypedevices) to run tests in. Actual list of devices can be found [here](https://github.com/Microsoft/playwright/blob/master/src/deviceDescriptors.ts).
8585
- `exitOnPageError` <[boolean]> Exits process on any page error. Defaults to `true`.
86-
- `server` <[object]> [All `jest-dev-server` options](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server#options).
86+
- `serverOptions` <[object]> [All `jest-dev-server` options](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/jest-dev-server#options).
8787
- `selectors` <[array]>. Define [selectors](https://github.com/microsoft/playwright/blob/v0.11.1/docs/api.md#class-selectors). Each selector must be an object with name and script properties.
8888

8989
Usage with [query-selector-shadow-dom](https://github.com/Georgegriff/query-selector-shadow-dom):

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ export const DEFAULT_CONFIG: Config = {
1515
}
1616

1717
export const DEFAULT_TEST_PLAYWRIGHT_TIMEOUT = 15000
18+
19+
export const PACKAGE_NAME = 'jest-playwright-preset'

src/utils.ts

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
FIREFOX,
1515
IMPORT_KIND_PLAYWRIGHT,
1616
WEBKIT,
17+
PACKAGE_NAME,
1718
} from './constants'
1819

1920
const exists = promisify(fs.exists)
@@ -42,7 +43,9 @@ export const checkDependencies = (
4243
export const checkBrowserEnv = (param: BrowserType): void => {
4344
if (param !== CHROMIUM && param !== FIREFOX && param !== WEBKIT) {
4445
throw new Error(
45-
`Wrong browser type. Should be one of [${CHROMIUM}, ${FIREFOX}, ${WEBKIT}], but got ${param}`,
46+
formatError(
47+
`Wrong browser type. Should be one of [${CHROMIUM}, ${FIREFOX}, ${WEBKIT}], but got ${param}`,
48+
),
4649
)
4750
}
4851
}
@@ -53,7 +56,9 @@ export const checkDeviceEnv = (
5356
): void => {
5457
if (!availableDevices.includes(device)) {
5558
throw new Error(
56-
`Wrong device. Should be one of [${availableDevices}], but got ${device}`,
59+
formatError(
60+
`Wrong device. Should be one of [${availableDevices}], but got ${device}`,
61+
),
5762
)
5863
}
5964
}
@@ -95,7 +100,9 @@ export const readPackage = async (): Promise<
95100
checkDependencies(packageConfig.dependencies) ||
96101
checkDependencies(packageConfig.devDependencies)
97102
if (playwright === null) {
98-
throw new Error('None of playwright packages was not found in dependencies')
103+
throw new Error(
104+
formatError('None of playwright packages was not found in dependencies'),
105+
)
99106
}
100107
return playwright
101108
}
@@ -116,13 +123,46 @@ export const getPlaywrightInstance = (
116123
return buildPlaywrightStructure('playwright')
117124
}
118125
if (!playwrightPackage[browserName]) {
119-
throw new Error('Cannot find provided playwright package')
126+
throw new Error(formatError('Cannot find provided playwright package'))
120127
}
121128
return buildPlaywrightStructure(
122129
`playwright-${playwrightPackage[browserName]}`,
123130
)
124131
}
125132

133+
const validateConfig = (config: Config) => {
134+
const renamings = [
135+
{
136+
from: 'launchBrowserApp',
137+
to: 'launchOptions',
138+
},
139+
{
140+
from: 'connectBrowserApp',
141+
to: 'connectOptions',
142+
},
143+
{
144+
from: 'context',
145+
to: 'contextOptions',
146+
},
147+
{
148+
from: 'server',
149+
to: 'serverOptions',
150+
},
151+
]
152+
const hasError = renamings.some(({ from, to }) => {
153+
if (from in config) {
154+
console.warn(
155+
formatError(`"${from}" was renamed to "${to}" in version 1.0`),
156+
)
157+
return true
158+
}
159+
return false
160+
})
161+
if (hasError) {
162+
throw new Error(formatError('Validation error occurred'))
163+
}
164+
}
165+
126166
export const readConfig = async (
127167
rootDir: string = process.cwd(),
128168
): Promise<Config> => {
@@ -134,7 +174,9 @@ export const readConfig = async (
134174

135175
if (hasCustomConfigPath && !configExists) {
136176
throw new Error(
137-
`Error: Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${configPath}`,
177+
formatError(
178+
`Can't find a root directory while resolving a config file path.\nProvided path to resolve: ${configPath}`,
179+
),
138180
)
139181
}
140182

@@ -143,6 +185,7 @@ export const readConfig = async (
143185
}
144186

145187
const localConfig = await require(absConfigPath)
188+
validateConfig(localConfig)
146189
return {
147190
...DEFAULT_CONFIG,
148191
...localConfig,
@@ -156,3 +199,6 @@ export const readConfig = async (
156199
},
157200
}
158201
}
202+
203+
export const formatError = (error: string): string =>
204+
`${PACKAGE_NAME}: ${error}`

0 commit comments

Comments
 (0)