Skip to content

Commit 2a55c6d

Browse files
committed
Headless test with puppeteer
1 parent 877edfc commit 2a55c6d

File tree

5 files changed

+187
-23
lines changed

5 files changed

+187
-23
lines changed

e2e_tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ stop_chains() {
7676
}
7777

7878
run_tests() {
79-
yarn test:node
79+
#yarn test:node
8080
# Disabled temporarily because it dies for some unknown reason on Travis
81-
#yarn test:browser
82-
yarn e2e:node
81+
yarn test:browser
82+
#yarn e2e:node
8383
}
8484

8585
cleanup() {

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
"format": "prettier --write \"src/**/*.ts\"",
2020
"test": "yarn test:node && yarn test:browser",
2121
"test:node": "yarn proto && yarn abi && tsc && tape dist/tests/unit_tests.js | tap-spec",
22-
"test:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.unit.tests.config.js | tap-spec",
22+
"test:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.unit.tests.config.js | yarn puppeteer-run ./dist/browser_unit_tests.js | tap-spec",
2323
"test:e2e:local": "bash e2e_tests.sh",
2424
"e2e:node": "yarn proto && yarn abi && tsc && tape -r dotenv/config dotenv_config_path=./.env.test dist/tests/e2e_tests.js | tap-spec",
2525
"e2e:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.e2e.test.config.js | tap-spec",
2626
"proto": "node ./scripts/gen-proto.js",
2727
"abi": "node ./scripts/abi.js && bash ./scripts/fix_types.sh",
28+
"puppeteer-run": "node ./scripts/puppeteer-run.js",
2829
"copy-contracts": "node ./scripts/copy-contracts.js",
2930
"prepublish": "yarn proto && yarn abi && yarn build && webpack"
3031
},
@@ -39,7 +40,9 @@
3940
"ethereumjs-util": "^5.2.0",
4041
"ethers": "^4.0.9",
4142
"google-protobuf": "3.6",
43+
"karma-phantomjs-launcher": "^1.0.4",
4244
"lodash": "^4.17.11",
45+
"phantomjs-prebuilt": "^2.1.16",
4346
"retry": "^0.12.0",
4447
"ripemd160": "^2.0.1",
4548
"rlp": "^2.1.0",
@@ -73,6 +76,8 @@
7376
"shelljs": "^0.8.2",
7477
"tap-spec": "^5.0.0",
7578
"tape": "4.9",
79+
"tape-puppet": "git+https://[email protected]/eduardonunesp/tape-puppet.git#9c1ed208391957de40e90962e89730417be1a30e",
80+
"ts-protoc-gen": "^",
7681
"ts-protoc-gen": "^0.6.0",
7782
"tslint": "^5.9.1",
7883
"tslint-config-prettier": "^1.12.0",

scripts/puppeteer-run.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const { readFileSync } = require('fs')
2+
const puppeteer = require('puppeteer')
3+
4+
const file = readFileSync(process.argv[2], 'utf-8')
5+
6+
const html = `
7+
<html>
8+
<script>
9+
${file}
10+
</script>
11+
</html>
12+
`
13+
;(async () => {
14+
const browser = await puppeteer.launch()
15+
const page = await browser.newPage()
16+
page.setContent(html)
17+
18+
page.on('console', msg => console.log(msg.text()))
19+
20+
await page.waitFor(2000)
21+
22+
await browser.close()
23+
})()

webpack.unit.tests.config.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// This config is used to run tests in the browser.
22

3-
const path = require('path');
4-
const WebpackTapeRun = require('webpack-tape-run');
3+
const path = require('path')
54

65
module.exports = {
76
mode: 'production',
@@ -19,10 +18,10 @@ module.exports = {
1918
crypto: true,
2019
util: true,
2120
stream: true,
22-
path: 'empty',
21+
path: 'empty'
2322
},
2423
externals: {
25-
shelljs: 'commonjs shelljs',
24+
shelljs: 'commonjs shelljs'
2625
},
2726
module: {
2827
rules: [
@@ -33,14 +32,9 @@ module.exports = {
3332
}
3433
]
3534
},
36-
plugins: [
37-
// Be default tests will run in Electron, but can use other browsers too,
38-
// see https://github.com/syarul/webpack-tape-run for plugin settings.
39-
new WebpackTapeRun()
40-
],
4135
// silence irrelevant messages
4236
performance: {
4337
hints: false
4438
},
4539
stats: 'errors-only'
46-
};
40+
}

0 commit comments

Comments
 (0)