Skip to content

Commit

Permalink
Headless test with puppeteer
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardonunesp committed Sep 29, 2019
1 parent 877edfc commit 2a55c6d
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 23 deletions.
6 changes: 3 additions & 3 deletions e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ stop_chains() {
}

run_tests() {
yarn test:node
#yarn test:node
# Disabled temporarily because it dies for some unknown reason on Travis
#yarn test:browser
yarn e2e:node
yarn test:browser
#yarn e2e:node
}

cleanup() {
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
"format": "prettier --write \"src/**/*.ts\"",
"test": "yarn test:node && yarn test:browser",
"test:node": "yarn proto && yarn abi && tsc && tape dist/tests/unit_tests.js | tap-spec",
"test:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.unit.tests.config.js | tap-spec",
"test:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.unit.tests.config.js | yarn puppeteer-run ./dist/browser_unit_tests.js | tap-spec",
"test:e2e:local": "bash e2e_tests.sh",
"e2e:node": "yarn proto && yarn abi && tsc && tape -r dotenv/config dotenv_config_path=./.env.test dist/tests/e2e_tests.js | tap-spec",
"e2e:browser": "yarn proto && yarn abi && tsc && webpack --config webpack.e2e.test.config.js | tap-spec",
"proto": "node ./scripts/gen-proto.js",
"abi": "node ./scripts/abi.js && bash ./scripts/fix_types.sh",
"puppeteer-run": "node ./scripts/puppeteer-run.js",
"copy-contracts": "node ./scripts/copy-contracts.js",
"prepublish": "yarn proto && yarn abi && yarn build && webpack"
},
Expand All @@ -39,7 +40,9 @@
"ethereumjs-util": "^5.2.0",
"ethers": "^4.0.9",
"google-protobuf": "3.6",
"karma-phantomjs-launcher": "^1.0.4",
"lodash": "^4.17.11",
"phantomjs-prebuilt": "^2.1.16",
"retry": "^0.12.0",
"ripemd160": "^2.0.1",
"rlp": "^2.1.0",
Expand Down Expand Up @@ -73,6 +76,8 @@
"shelljs": "^0.8.2",
"tap-spec": "^5.0.0",
"tape": "4.9",
"tape-puppet": "git+https://[email protected]/eduardonunesp/tape-puppet.git#9c1ed208391957de40e90962e89730417be1a30e",
"ts-protoc-gen": "^",
"ts-protoc-gen": "^0.6.0",
"tslint": "^5.9.1",
"tslint-config-prettier": "^1.12.0",
Expand Down
23 changes: 23 additions & 0 deletions scripts/puppeteer-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { readFileSync } = require('fs')
const puppeteer = require('puppeteer')

const file = readFileSync(process.argv[2], 'utf-8')

const html = `
<html>
<script>
${file}
</script>
</html>
`
;(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
page.setContent(html)

page.on('console', msg => console.log(msg.text()))

await page.waitFor(2000)

await browser.close()
})()
14 changes: 4 additions & 10 deletions webpack.unit.tests.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This config is used to run tests in the browser.

const path = require('path');
const WebpackTapeRun = require('webpack-tape-run');
const path = require('path')

module.exports = {
mode: 'production',
Expand All @@ -19,10 +18,10 @@ module.exports = {
crypto: true,
util: true,
stream: true,
path: 'empty',
path: 'empty'
},
externals: {
shelljs: 'commonjs shelljs',
shelljs: 'commonjs shelljs'
},
module: {
rules: [
Expand All @@ -33,14 +32,9 @@ module.exports = {
}
]
},
plugins: [
// Be default tests will run in Electron, but can use other browsers too,
// see https://github.com/syarul/webpack-tape-run for plugin settings.
new WebpackTapeRun()
],
// silence irrelevant messages
performance: {
hints: false
},
stats: 'errors-only'
};
}
Loading

0 comments on commit 2a55c6d

Please sign in to comment.