-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrender.js
More file actions
44 lines (37 loc) · 1.19 KB
/
Copy pathrender.js
File metadata and controls
44 lines (37 loc) · 1.19 KB
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
39
40
41
42
43
44
var Nightmare = require('nightmare')
var document
function render(port, routes, elementToWaitFor) {
var nightmare = Nightmare({
show: false,
webPreferences: {
partition: 'partition-' + Math.random()
}
})
var baseUrl = `http://localhost:${port}`
var pageContents = routes.reduce(function (accumulator, route) {
return accumulator.then(function (results) {
var url = baseUrl + route
return nightmare
.goto(url)
.wait(elementToWaitFor, 1000)
.evaluate(function () {
return document.documentElement.outerHTML
})
.then(function (content) {
results.push(content)
return results
})
.catch(err => {
setTimeout(function () {throw err})
})
})
}, Promise.resolve([]))
return pageContents.then(function (values) {
return nightmare.end().then(function () {
return values
})
}).catch(err => {
setTimeout(function () {console.log(`Error ${err}`)})
})
}
module.exports = render