Created
October 30, 2017 06:11
-
-
Save huygn/049351b338fda9ac2eb38fb435ade81e to your computer and use it in GitHub Desktop.
Automation test runner in poi.js app with puppeteer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path') | |
const connect = require('connect') | |
const superstatic = require('superstatic') | |
const puppeteer = require('puppeteer') | |
const poi = require('poi') | |
const poiConfig = require('../../poi.config') | |
const rootDir = path.join(__dirname, '../..') | |
const poiApp = poi({ | |
mode: 'test', | |
entry: poiConfig.entry, | |
html: poiConfig.html, | |
autoprefixer: poiConfig.autoprefixer, | |
}) | |
const runner = (port = 4444) => { | |
const app = connect().use( | |
superstatic({ | |
public: path.join(rootDir, 'dist'), | |
}) | |
) | |
const server = app.listen(port) | |
server.addListener('listening', () => { | |
puppeteer.launch().then(browser => { | |
browser | |
.newPage() | |
.then(page => { | |
return page.goto(`http://localhost:${port}`).then(() => { | |
return page | |
.waitForSelector('#login-form', { visible: true }) | |
.then(() => { | |
return page.screenshot({ path: 'page.png' }) | |
}) | |
}) | |
}) | |
.then(() => browser.close()) | |
.then(() => server.close()) | |
}) | |
}) | |
} | |
poiApp | |
.prepare() | |
.then(() => poiApp.build()) | |
.then(build => { | |
runner() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment