Skip to content

Commit b4f142b

Browse files
author
GERMAN
committed
migrate to eslint
1 parent dda8656 commit b4f142b

27 files changed

Lines changed: 705 additions & 640 deletions

.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
],
10+
"overrides": [
11+
],
12+
"parser": "@typescript-eslint/parser",
13+
"parserOptions": {
14+
"ecmaVersion": "latest",
15+
"sourceType": "module"
16+
},
17+
"plugins": [
18+
"@typescript-eslint"
19+
],
20+
"rules": {
21+
}
22+
}

.prettierrc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"printWidth": 120,
3-
"trailingComma": "all",
4-
"singleQuote": true
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"useTabs": false
56
}

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@gbisogno/cdp-utils",
3-
"version": "1.3.10",
3+
"version": "1.4.0",
44
"description": "A set of utilities/wrapper for Test Automation or Performance testing on top of Chrome DevTools Protocol",
55
"repository": {
66
"type": "git",
@@ -11,8 +11,9 @@
1111
"scripts": {
1212
"build": "tsc",
1313
"test": "jest",
14-
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
15-
"lint": "tslint -p tsconfig.json",
14+
"format": "prettier --write src/**/*.ts",
15+
"prebuild": "npm run lint && npm run format",
16+
"lint": "eslint --fix ./src/**/*.ts",
1617
"doc": "compodoc -p --tsconfig tsconfig.json -s"
1718
},
1819
"keywords": [
@@ -33,14 +34,17 @@
3334
"@types/chrome-remote-interface": "^0.31.4",
3435
"@types/jest": "^27.5.2",
3536
"@types/selenium-webdriver": "^4.0.16",
37+
"@typescript-eslint/eslint-plugin": "^5.42.0",
38+
"@typescript-eslint/parser": "^5.42.0",
3639
"chromedriver": "latest",
3740
"endpoint-utils": "^1.0.2",
41+
"eslint": "^8.27.0",
42+
"eslint-config-prettier": "^8.5.0",
43+
"eslint-plugin-prettier": "^4.2.1",
3844
"jest": "^27.4.5",
3945
"prettier": "^2.4.1",
4046
"selenium-webdriver": "^4.0.0",
4147
"ts-jest": "^27.1.2",
42-
"tslint": "^6.1.3",
43-
"tslint-config-prettier": "^1.18.0",
4448
"typed-query-selector": "^2.6.1",
4549
"typescript": "^4.4.4"
4650
},

src/__tests__/browser.test.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
1-
import { Builder } from "selenium-webdriver";
2-
import * as chrome from "selenium-webdriver/chrome";
1+
import { Builder } from 'selenium-webdriver';
2+
import * as chrome from 'selenium-webdriver/chrome';
33
import 'chromedriver';
44
import { CDPClient } from '../cdpClient';
55
import { GooglePage } from '../pages/googlePage';
66
import { Browser } from '../browser';
7-
import { cdpConfig } from "../config/cdpConfig";
7+
import { cdpConfig } from '../config/cdpConfig';
88
import { getFreePort } from 'endpoint-utils';
99

1010
jest.setTimeout(cdpConfig.maxTimeout);
1111

1212
test('Test Browser', async () => {
13+
const port = await getFreePort();
14+
const options = new chrome.Options();
1315

14-
const port = await getFreePort();
15-
const options = new chrome.Options();
16+
options.addArguments(`--remote-debugging-port=${port}`);
1617

17-
options.addArguments(`--remote-debugging-port=${port}`);
18+
const driver = await new Builder()
19+
.forBrowser('chrome')
20+
.setChromeOptions(options)
21+
.build();
1822

19-
const driver = await new Builder().forBrowser('chrome')
20-
.setChromeOptions(options)
21-
.build();
23+
const googlePage = new GooglePage(driver);
2224

23-
const googlePage = new GooglePage(driver);
25+
const cdpClient = new CDPClient();
26+
await cdpClient.init(port);
2427

25-
const cdpClient = new CDPClient();
26-
await cdpClient.init(port);
27-
28-
const browser = new Browser(cdpClient);
28+
const browser = new Browser(cdpClient);
2929

30-
await driver.get("https://www.google.com");
30+
await driver.get('https://www.google.com');
3131

32-
const url = await driver.getCurrentUrl();
33-
await browser.grantPermissions({
34-
origin: url,
35-
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
36-
});
32+
const url = await driver.getCurrentUrl();
33+
await browser.grantPermissions({
34+
origin: url,
35+
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
36+
});
3737

38-
await googlePage.searchFromClipboard();
38+
await googlePage.searchFromClipboard();
3939

40-
await cdpClient.close();
40+
await cdpClient.close();
4141

42-
await driver.quit();
42+
await driver.quit();
4343
});
44-
45-

src/__tests__/lighthouse.tests.ts

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
import { Builder } from "selenium-webdriver";
2-
import * as chrome from "selenium-webdriver/chrome";
1+
import { Builder } from 'selenium-webdriver';
2+
import * as chrome from 'selenium-webdriver/chrome';
33
import 'chromedriver';
44
import { GooglePage } from '../pages/googlePage';
55
import { Lighthouse } from '../lighthouse';
66
import { getFreePort } from 'endpoint-utils';
77
import * as DesktopConfig from 'lighthouse/lighthouse-core/config/desktop-config.js';
8-
import { cdpConfig } from "../config/cdpConfig";
8+
import { cdpConfig } from '../config/cdpConfig';
99

1010
jest.setTimeout(cdpConfig.maxTimeout);
1111

1212
test('Test Lighthouse', async () => {
13+
const port = await getFreePort();
14+
const options = new chrome.Options();
1315

14-
const port = await getFreePort();
15-
const options = new chrome.Options();
16+
options.addArguments(`--remote-debugging-port=${port}`);
17+
options.excludeSwitches('--enable-logging');
1618

17-
options.addArguments(`--remote-debugging-port=${port}`);
18-
options.excludeSwitches('--enable-logging');
19+
const driver = await new Builder()
20+
.forBrowser('chrome')
21+
.setChromeOptions(options)
22+
.build();
1923

20-
const driver = await new Builder().forBrowser('chrome')
21-
.setChromeOptions(options)
22-
.build();
24+
const googlePage = new GooglePage(driver);
2325

24-
const googlePage = new GooglePage(driver);
26+
const lighthouse = new Lighthouse(port);
2527

26-
const lighthouse = new Lighthouse(port);
28+
await lighthouse.initWorkFlow('Google search', DesktopConfig.settings);
2729

28-
await lighthouse.initWorkFlow('Google search', DesktopConfig.settings);
30+
await lighthouse.navigate('https://www.google.com');
2931

30-
await lighthouse.navigate("https://www.google.com");
32+
await lighthouse.startTrace('search operation');
3133

32-
await lighthouse.startTrace('search operation');
34+
await googlePage.search('test');
3335

34-
await googlePage.search('test');
36+
const res = await lighthouse.stopTrace();
3537

36-
const res = await lighthouse.stopTrace();
38+
await driver.quit();
3739

38-
await driver.quit();
39-
40-
await lighthouse.generateFlowReport('lighthouse.html');
41-
42-
res.forEach((step) => {
43-
expect(step.lhr.categories.performance.score).toBeGreaterThanOrEqual(0.8);
44-
})
40+
await lighthouse.generateFlowReport('lighthouse.html');
4541

42+
res.forEach((step) => {
43+
expect(step.lhr.categories.performance.score).toBeGreaterThanOrEqual(0.8);
44+
});
4645
});

src/__tests__/network.test.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
1-
import { Builder } from "selenium-webdriver";
2-
import * as chrome from "selenium-webdriver/chrome";
1+
import { Builder } from 'selenium-webdriver';
2+
import * as chrome from 'selenium-webdriver/chrome';
33
import 'chromedriver';
44
import { GooglePage } from '../pages/googlePage';
55
import { Network } from '../network';
66
import { CDPClient } from '../cdpClient';
77
import { getFreePort } from 'endpoint-utils';
8-
import { Har } from "har-format";
9-
import { cdpConfig } from "../config/cdpConfig";
8+
import { Har } from 'har-format';
9+
import { cdpConfig } from '../config/cdpConfig';
1010

1111
jest.setTimeout(cdpConfig.maxTimeout);
1212

1313
test('Test Network', async () => {
14+
const port = await getFreePort();
15+
const options = new chrome.Options();
1416

15-
const port = await getFreePort();
16-
const options = new chrome.Options();
17+
options.addArguments(`--remote-debugging-port=${port}`);
1718

18-
options.addArguments(`--remote-debugging-port=${port}`);
19+
const driver = await new Builder()
20+
.forBrowser('chrome')
21+
.setChromeOptions(options)
22+
.build();
1923

20-
const driver = await new Builder().forBrowser('chrome')
21-
.setChromeOptions(options)
22-
.build();
24+
const googlePage = new GooglePage(driver);
2325

24-
const googlePage = new GooglePage(driver);
26+
const cdpClient = new CDPClient();
27+
await cdpClient.init(port);
2528

26-
const cdpClient = new CDPClient();
27-
await cdpClient.init(port);
29+
const network = new Network(cdpClient, 'network.har');
2830

29-
const network = new Network(cdpClient, 'network.har');
31+
await network.startTrace();
3032

31-
await network.startTrace();
33+
await driver.get('https://www.google.com');
3234

33-
await driver.get("https://www.google.com");
35+
await googlePage.search('test');
3436

35-
await googlePage.search('test');
37+
const networkResults: Har = await network.stopTrace();
38+
expect(networkResults.log.entries.length).toBeGreaterThan(0);
3639

37-
const networkResults: Har = await network.stopTrace();
38-
expect(networkResults.log.entries.length).toBeGreaterThan(0);
39-
40-
await cdpClient.close();
41-
42-
await driver.quit()
40+
await cdpClient.close();
4341

42+
await driver.quit();
4443
});
45-

src/__tests__/performance.test.ts

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,48 @@
1-
import { Builder } from "selenium-webdriver";
2-
import * as chrome from "selenium-webdriver/chrome";
1+
import { Builder } from 'selenium-webdriver';
2+
import * as chrome from 'selenium-webdriver/chrome';
33
import 'chromedriver';
44
import { GooglePage } from '../pages/googlePage';
55
import { Performance } from '../performance';
66
import { CDPClient } from '../cdpClient';
77
import { getFreePort } from 'endpoint-utils';
8-
import { cdpConfig } from "../config/cdpConfig";
8+
import { cdpConfig } from '../config/cdpConfig';
99

1010
jest.setTimeout(cdpConfig.maxTimeout);
1111

1212
test('Test Performance', async () => {
13+
const port = await getFreePort();
14+
const options = new chrome.Options();
1315

14-
const port = await getFreePort();
15-
const options = new chrome.Options();
16+
options.addArguments(`--remote-debugging-port=${port}`);
1617

17-
options.addArguments(`--remote-debugging-port=${port}`);
18+
const driver = await new Builder()
19+
.forBrowser('chrome')
20+
.setChromeOptions(options)
21+
.build();
1822

19-
const driver = await new Builder().forBrowser('chrome')
20-
.setChromeOptions(options)
21-
.build();
23+
const googlePage = new GooglePage(driver);
2224

23-
const googlePage = new GooglePage(driver);
25+
const cdpClient = new CDPClient();
26+
await cdpClient.init(port);
2427

25-
const cdpClient = new CDPClient();
26-
await cdpClient.init(port);
28+
const performance = new Performance(
29+
cdpClient,
30+
'startTrace.json',
31+
'endTrace.json'
32+
);
2733

28-
const performance = new Performance(cdpClient, 'startTrace.json', 'endTrace.json');
34+
const perfStartResults = await performance.startTrace();
2935

30-
const perfStartResults = await performance.startTrace();
36+
await driver.get('https://www.google.com');
3137

32-
await driver.get("https://www.google.com");
38+
await googlePage.search('test');
3339

34-
await googlePage.search('test');
40+
const perfEndResults = await performance.stopTrace();
3541

36-
const perfEndResults = await performance.stopTrace();
42+
expect(perfStartResults.metrics.length).toBeGreaterThan(0);
43+
expect(perfEndResults.metrics.length).toBeGreaterThan(0);
3744

38-
expect(perfStartResults.metrics.length).toBeGreaterThan(0);
39-
expect(perfEndResults.metrics.length).toBeGreaterThan(0);
40-
41-
await cdpClient.close();
42-
43-
await driver.quit()
45+
await cdpClient.close();
4446

47+
await driver.quit();
4548
});
46-

0 commit comments

Comments
 (0)