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

Commit 8679770

Browse files
mxschmittmmarkelov
andauthored
feat: reuse browser with the jest-runner (#134)
* feat: reuse browser with the jest-runner * fix: it * Update dependencies and improve types * Some improvements Co-authored-by: mmarkelov <maks-markel@mail.ru>
1 parent c0f0127 commit 8679770

File tree

10 files changed

+200
-101
lines changed

10 files changed

+200
-101
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = {
1616
'prettier/prettier': 'error',
1717
'@typescript-eslint/ban-ts-ignore': 'off',
1818
'@typescript-eslint/ban-ts-comment': 'off',
19+
'@typescript-eslint/no-non-null-assertion': 'off',
1920
'@typescript-eslint/no-var-requires': 'off',
2021
},
2122
parser: '@typescript-eslint/parser',

e2e/more.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
describe('Example setContext test', () => {
2+
it('should be able to execute javascript', async () => {
3+
page.setContent(`<script>document.write("test")</script>`)
4+
const element = await page.waitForSelector('text=test')
5+
expect(element).toBeTruthy()
6+
})
7+
})

package-lock.json

Lines changed: 84 additions & 46 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
@@ -53,8 +53,8 @@
5353
"@types/jest": "26.0.0",
5454
"@types/jest-dev-server": "4.2.0",
5555
"@types/node": "14.0.13",
56-
"@typescript-eslint/eslint-plugin": "3.2.0",
57-
"@typescript-eslint/parser": "3.2.0",
56+
"@typescript-eslint/eslint-plugin": "3.3.0",
57+
"@typescript-eslint/parser": "3.3.0",
5858
"coveralls": "3.1.0",
5959
"eslint": "7.2.0",
6060
"eslint-config-airbnb-base": "14.2.0",
@@ -68,7 +68,7 @@
6868
"playwright-chromium": ">=1.1.1",
6969
"playwright-core": "npm:playwright-chromium@>=1.1.1",
7070
"prettier": "2.0.5",
71-
"snyk": "^1.339.3",
71+
"snyk": "^1.341.1",
7272
"ts-jest": "26.1.0",
7373
"typescript": "3.9.5"
7474
}

src/PlaywrightEnvironment.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/* eslint-disable no-console */
2-
import type { Config as JestConfig } from '@jest/types'
32
import type { Event, State } from 'jest-circus'
43
import type { Browser } from 'playwright-core'
5-
import type { Config, GenericBrowser, BrowserType } from './types'
4+
import type {
5+
Config,
6+
GenericBrowser,
7+
BrowserType,
8+
JestPlaywrightConfig,
9+
} from './types'
610
import { CHROMIUM, IMPORT_KIND_PLAYWRIGHT } from './constants'
711
import {
812
getBrowserType,
@@ -49,17 +53,18 @@ export const getPlaywrightEnv = (basicEnv = 'node') => {
4953
: 'jest-environment-jsdom')
5054

5155
return class PlaywrightEnvironment extends RootEnv {
52-
private _config: JestConfig.ProjectConfig
56+
readonly _config: JestPlaywrightConfig
5357

54-
constructor(config: JestConfig.ProjectConfig) {
58+
constructor(config: JestPlaywrightConfig) {
5559
super(config)
5660
this._config = config
5761
}
5862

5963
async setup(): Promise<void> {
60-
const config = await readConfig(this._config.rootDir)
61-
//@ts-ignore
62-
const browserType = getBrowserType(this._config.browserName)
64+
const { rootDir, wsEndpoint, browserName } = this._config
65+
const config = await readConfig(rootDir)
66+
config.connectBrowserApp = { wsEndpoint }
67+
const browserType = getBrowserType(browserName)
6368
const { context, exitOnPageError, selectors } = config
6469
const playwrightPackage = await readPackage()
6570
if (playwrightPackage === IMPORT_KIND_PLAYWRIGHT) {
@@ -73,7 +78,6 @@ export const getPlaywrightEnv = (basicEnv = 'node') => {
7378
)
7479
}
7580
}
76-
//@ts-ignore
7781
const device = getDeviceType(this._config.device)
7882
const { instance: playwrightInstance, devices } = getPlaywrightInstance(
7983
playwrightPackage,

0 commit comments

Comments
 (0)