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

Commit 5c093f3

Browse files
mmarkelovmxschmitt
andauthored
Refactoring checking playwright packages (#151)
* Update dependencies * Rewrite checking playwright packages * cleanup: getPlaywrightInstance * fix: it * Revert "cleanup: getPlaywrightInstance" This reverts commit 18d7ee0. * fix: tests * Update ts-jest * Update ts-jest Co-authored-by: Max Schmitt <max@schmitt.mx>
1 parent eb894fe commit 5c093f3

File tree

7 files changed

+55
-287
lines changed

7 files changed

+55
-287
lines changed

package-lock.json

Lines changed: 13 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"@typescript-eslint/eslint-plugin": "3.3.0",
6262
"@typescript-eslint/parser": "3.3.0",
6363
"coveralls": "3.1.0",
64-
"eslint": "7.2.0",
64+
"eslint": "7.3.0",
6565
"eslint-config-airbnb-base": "14.2.0",
6666
"eslint-config-prettier": "6.11.0",
6767
"eslint-plugin-import": "2.21.2",
@@ -73,8 +73,8 @@
7373
"playwright-chromium": ">=1.1.1",
7474
"playwright-core": "npm:playwright-chromium@>=1.1.1",
7575
"prettier": "2.0.5",
76-
"snyk": "^1.343.0",
77-
"ts-jest": "26.1.0",
76+
"snyk": "^1.346.0",
77+
"ts-jest": "26.1.1",
7878
"typescript": "3.9.5"
7979
}
8080
}

src/PlaywrightEnvironment.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getDeviceType,
1414
getPlaywrightInstance,
1515
readConfig,
16-
readPackage,
1716
} from './utils'
1817
import { savePageCoverage } from './coverage'
1918

@@ -68,8 +67,14 @@ export const getPlaywrightEnv = (basicEnv = 'node') => {
6867
const browserType = getBrowserType(browserName)
6968
const { exitOnPageError, selectors } = config
7069
let { contextOptions } = config
71-
const playwrightPackage = await readPackage()
72-
if (playwrightPackage === IMPORT_KIND_PLAYWRIGHT) {
70+
const device = getDeviceType(this._config.device)
71+
const {
72+
name,
73+
instance: playwrightInstance,
74+
devices,
75+
} = getPlaywrightInstance(browserType)
76+
77+
if (name === IMPORT_KIND_PLAYWRIGHT) {
7378
// eslint-disable-next-line @typescript-eslint/no-var-requires
7479
const playwright = require('playwright')
7580
if (selectors) {
@@ -80,11 +85,6 @@ export const getPlaywrightEnv = (basicEnv = 'node') => {
8085
)
8186
}
8287
}
83-
const device = getDeviceType(this._config.device)
84-
const { instance: playwrightInstance, devices } = getPlaywrightInstance(
85-
playwrightPackage,
86-
browserType,
87-
)
8888

8989
if (device) {
9090
const { viewport, userAgent } = devices[device]

src/PlaywrightRunner.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
getDisplayName,
2222
readConfig,
2323
getPlaywrightInstance,
24-
readPackage,
2524
} from './utils'
2625
import { DEFAULT_TEST_PLAYWRIGHT_TIMEOUT } from './constants'
2726
import { BrowserServer } from 'playwright-core'
@@ -72,13 +71,11 @@ class PlaywrightRunner extends JestRunner {
7271

7372
async getTests(tests: Test[], config: JestPlaywrightConfig): Promise<Test[]> {
7473
const { browsers, devices, launchOptions } = config
75-
const playwrightPackage = await readPackage()
7674
const pwTests: Test[] = []
7775
for (const test of tests) {
7876
for (const browser of browsers) {
7977
checkBrowserEnv(browser)
8078
const { devices: availableDevices, instance } = getPlaywrightInstance(
81-
playwrightPackage,
8279
browser,
8380
)
8481
if (!this.browser2Server[browser]) {

src/types.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ export type SelectorType = {
2828
name: string
2929
}
3030

31+
export type PlaywrightRequireType = BrowserType | typeof IMPORT_KIND_PLAYWRIGHT
32+
3133
export interface Playwright {
34+
name: PlaywrightRequireType
3235
instance: GenericBrowser
3336
devices: typeof devices
3437
}
3538

36-
export type PlaywrightRequireType = BrowserType | typeof IMPORT_KIND_PLAYWRIGHT
37-
3839
export interface JestPlaywrightConfig {
3940
launchOptions?: LaunchOptions
4041
connectOptions?: Parameters<GenericBrowser['connect']>[0]

0 commit comments

Comments
 (0)