Skip to content

Instantly share code, notes, and snippets.

@huygn
Created October 30, 2017 06:11
Show Gist options
  • Save huygn/049351b338fda9ac2eb38fb435ade81e to your computer and use it in GitHub Desktop.
Save huygn/049351b338fda9ac2eb38fb435ade81e to your computer and use it in GitHub Desktop.
Automation test runner in poi.js app with puppeteer
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