-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.js
38 lines (34 loc) · 988 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const test = require('tape')
const http = require('http')
const url = require('url')
const nanochrome = require('nanochrome')
test('nanochrome() - app', (t) => {
let chrome
let shutdownTimeout
const server = http.createServer((req, res) => {
res.end('hello')
t.pass('request received')
if (!shutdownTimeout) shutdownTimeout = setTimeout(shutdownTest, 100)
})
function shutdownTest () {
chrome.close((err) => {
t.error(err, 'chrome closed without error')
server.close((err) => {
t.error(err, 'server closed without error')
t.end()
})
})
}
server.listen(0, (err) => {
t.error(err, 'server started without error')
const { port } = server.address()
const uri = url.format({ protocol: 'http:', hostname: 'localhost', port })
chrome = nanochrome(uri, {
app: true,
chromeFlags: ['--disable-gpu']
})
chrome.open((err) => {
t.error(err, 'chrome opened without error')
})
})
})