Skip to content

Commit 958bff4

Browse files
committed
Fix eslint errors
1 parent 967ad5e commit 958bff4

File tree

7 files changed

+81
-80
lines changed

7 files changed

+81
-80
lines changed

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,21 @@ You can specify browser in multiple ways:
3838
If you don't pass any value it will be use `chromium` as default
3939

4040
Use Playwright in your tests:
41+
4142
```json
4243
"test": "BROWSER=chromium jest"
4344
```
4445

4546
```js
4647
describe('Google', () => {
47-
beforeAll(async () => {
48-
await page.goto('https://whatismybrowser.com/')
49-
})
50-
51-
it('should display "google" text on page', async () => {
52-
const browser = await page.$eval('.string-major a', el => el.text);
53-
expect(browser).toContain('Chrome')
54-
})
48+
beforeAll(async () => {
49+
await page.goto('https://whatismybrowser.com/')
50+
})
51+
52+
it('should display "google" text on page', async () => {
53+
const browser = await page.$eval('.string-major a', el => el.text)
54+
expect(browser).toContain('Chrome')
55+
})
5556
})
5657
```
5758

babel.config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module.exports = {
2-
presets: [
3-
[
4-
'@babel/preset-env',
5-
{
6-
targets: {
7-
node: '8',
8-
},
9-
loose: true,
10-
},
11-
],
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: '8',
8+
},
9+
loose: true,
10+
},
1211
],
12+
],
1313
}

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module.exports = require('./lib/PlaywrightEnvironment').default;
2-
module.exports.globalSetup = require('./lib/global').setup;
3-
module.exports.globalTeardown = require('./lib/global').teardown;
1+
module.exports = require('./lib/PlaywrightEnvironment').default
2+
module.exports.globalSetup = require('./lib/global').setup
3+
module.exports.globalTeardown = require('./lib/global').teardown

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ module.exports = {
33
globalSetup: './setup.js',
44
globalTeardown: './teardown.js',
55
testEnvironment: './testEnvironment.js',
6-
};
6+
}

src/PlaywrightEnvironment.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,32 @@ import fs from 'fs'
22
import NodeEnvironment from 'jest-environment-node'
33
import playwright from 'playwright'
44
import { WS_ENDPOINT_PATH } from './constants'
5-
import { checkBrowserEnv, getBrowserType, readConfig } from "./utils";
5+
import { checkBrowserEnv, getBrowserType, readConfig } from './utils'
66

77
const handleError = error => {
88
process.emit('uncaughtException', error)
9-
};
9+
}
1010

1111
class PlaywrightEnvironment extends NodeEnvironment {
12-
async teardown() {
13-
await super.teardown()
14-
}
15-
1612
async setup() {
17-
const wsEndpoint = fs.readFileSync(WS_ENDPOINT_PATH, 'utf8');
13+
const wsEndpoint = fs.readFileSync(WS_ENDPOINT_PATH, 'utf8')
1814
if (!wsEndpoint) {
1915
throw new Error('wsEndpoint not found')
2016
}
21-
const config = await readConfig();
22-
const browserType = getBrowserType(config);
23-
checkBrowserEnv(browserType);
24-
const { connect, context } = config;
25-
const connectOptions = Object.assign({}, { browserWSEndpoint: wsEndpoint }, connect );
26-
this.global.browser = await playwright[browserType].connect(connectOptions);
27-
this.global.context = await this.global.browser.newContext(context);
28-
this.global.page = await this.global.context.newPage();
17+
const config = await readConfig()
18+
const browserType = getBrowserType(config)
19+
checkBrowserEnv(browserType)
20+
const { connect, context } = config
21+
const connectOptions = { browserWSEndpoint: wsEndpoint, ...connect }
22+
this.global.browser = await playwright[browserType].connect(connectOptions)
23+
this.global.context = await this.global.browser.newContext(context)
24+
this.global.page = await this.global.context.newPage()
2925
this.global.page.on('pageerror', handleError)
3026
}
3127

3228
async teardown() {
33-
this.global.page.removeListener('pageerror', handleError);
29+
await super.teardown()
30+
this.global.page.removeListener('pageerror', handleError)
3431
await this.global.page.close()
3532
}
3633
}

src/global.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import fs from 'fs'
2+
// eslint-disable-next-line import/no-extraneous-dependencies
23
import rimraf from 'rimraf'
34
import playwright from 'playwright'
45
import { DIR, WS_ENDPOINT_PATH } from './constants'
5-
import { checkBrowserEnv, readConfig, getBrowserType } from "./utils";
6+
import { checkBrowserEnv, readConfig, getBrowserType } from './utils'
67

7-
let browser;
8+
let browser
89

910
export async function setup() {
10-
const config = await readConfig();
11-
const browserType = getBrowserType(config);
12-
checkBrowserEnv(browserType);
13-
const { launchBrowserApp } = config;
14-
browser = await playwright[browserType].launchBrowserApp(launchBrowserApp);
11+
const config = await readConfig()
12+
const browserType = getBrowserType(config)
13+
checkBrowserEnv(browserType)
14+
const { launchBrowserApp } = config
15+
browser = await playwright[browserType].launchBrowserApp(launchBrowserApp)
1516
// Instead, we expose the connection details via file system to be used in tests
16-
fs.mkdirSync(DIR, { recursive: true });
17+
fs.mkdirSync(DIR, { recursive: true })
1718
fs.writeFileSync(WS_ENDPOINT_PATH, browser.wsEndpoint())
1819
}
1920

src/utils.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
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'
55

6-
const exists = promisify(fs.exists);
6+
const exists = promisify(fs.exists)
77

88
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+
}
1214
}
1315

1416
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
2122
}
2223

2324
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 }
4446
}

0 commit comments

Comments
 (0)