Skip to content

Commit 58e9641

Browse files
authored
Merge pull request #16 from sparksuite/set-up-browser-testing
Set up browser testing
2 parents 0d97b23 + da1ce38 commit 58e9641

16 files changed

+2679
-27
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@ node_modules/
22
coverage/
33
dist/
44
babel.config.js
5+
jest-puppeteer.config.js
6+
test/puppeteer/node_modules/
7+
test/puppeteer/dist/

.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
],
1010
"env": {
1111
"es6": true,
12-
"node": true
12+
"node": true,
13+
"browser": true
1314
},
1415
"parser": "@typescript-eslint/parser",
1516
"parserOptions": {

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules/
22
coverage/
33
dist/
4+
test/puppeteer/node_modules/
5+
test/puppeteer/dist/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules/
22
coverage/
33
dist/
4+
test/puppeteer/node_modules/
5+
test/puppeteer/dist/

jest-puppeteer.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
server: {
3+
command: 'node ./test/puppeteer/server.js',
4+
port: 8080,
5+
},
6+
};

package.json

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dist/"
99
],
1010
"scripts": {
11-
"test": "jest",
11+
"test": "yarn --frozen-lockfile --check-files && yarn compile && yarn link && cd test/puppeteer && yarn --frozen-lockfile --check-files && yarn link \"w3c-css-validator\" && npx webpack && cd ../../ && jest",
1212
"lint": "eslint --ext .js,.ts . && prettier --check '**/*.{ts,js,json,yml}'",
1313
"format": "eslint --fix --ext .js,.ts . && prettier --write '**/*.{ts,js,json,yml}'",
1414
"clean": "rm -rf node_modules/ coverage/ dist/",
@@ -36,13 +36,16 @@
3636
"@babel/preset-env": "^7.12.13",
3737
"@babel/preset-typescript": "^7.12.13",
3838
"@types/jest": "^26.0.20",
39+
"@types/jest-environment-puppeteer": "^4.4.1",
3940
"@types/node": "^14.14.25",
4041
"@typescript-eslint/eslint-plugin": "^4.14.2",
4142
"@typescript-eslint/parser": "^4.14.2",
4243
"eslint": "^7.19.0",
4344
"eslint-config-prettier": "^7.2.0",
4445
"jest": "^26.6.3",
46+
"jest-puppeteer": "^4.4.0",
4547
"prettier": "^2.2.1",
48+
"puppeteer": "^7.1.0",
4649
"typescript": "^4.1.3"
4750
},
4851
"jest": {
@@ -51,9 +54,21 @@
5154
"collectCoverageFrom": [
5255
"<rootDir>/src/**"
5356
],
54-
"testMatch": [
55-
"<rootDir>/test/*.test.ts"
56-
],
57-
"verbose": true
57+
"verbose": true,
58+
"projects": [
59+
{
60+
"displayName": "Jest",
61+
"testMatch": [
62+
"<rootDir>/test/*.test.ts"
63+
]
64+
},
65+
{
66+
"displayName": "Puppeteer",
67+
"preset": "jest-puppeteer",
68+
"testMatch": [
69+
"<rootDir>/test/puppeteer/*.test.ts"
70+
]
71+
}
72+
]
5873
}
5974
}

test/puppeteer/babel.config.js

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

test/puppeteer/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
3+
<html>
4+
<head>
5+
<link rel="icon" href="data:,">
6+
<script src="/test/puppeteer/dist/bundle.js"></script>
7+
</head>
8+
9+
<body>
10+
<h1 id='is-valid'></h1>
11+
<button id='make-call'></button>
12+
</body>
13+
</html>

test/puppeteer/index.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Setup work before each test
2+
beforeEach(async () => {
3+
await jestPuppeteer.resetPage();
4+
5+
await page.goto(`http://localhost:8080/`, {
6+
waitUntil: 'load',
7+
});
8+
});
9+
10+
// Tests
11+
it('Loads', async () => {
12+
await expect(page.title()).resolves.toMatch('Hello world!');
13+
});

test/puppeteer/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"devDependencies": {
3+
"@babel/core": "^7.12.17",
4+
"@babel/preset-env": "^7.12.17",
5+
"@babel/preset-typescript": "^7.12.17",
6+
"babel-loader": "^8.2.2",
7+
"typescript": "^4.1.5",
8+
"webpack": "^5.23.0",
9+
"webpack-cli": "^4.5.0"
10+
}
11+
}

0 commit comments

Comments
 (0)