-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreport-html.js
35 lines (26 loc) · 977 Bytes
/
report-html.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
'use strict'
const fs = require('fs')
const handlebars = require('handlebars')
const path = require('path')
const { promisify } = require('util')
const readFile = promisify(fs.readFile)
const report = (module.exports = {})
// Supported Versions
report.supports = '^5.0.0 || ^5.0.0-alpha || ^5.0.0-beta'
// Compile template and output formatted results
report.results = async testResults => {
const resourcePath = path.join(__dirname, '../', 'resources')
const templateString = await readFile(path.resolve(`${resourcePath}/report.html`), 'utf-8')
const template = handlebars.compile(templateString)
let output = Object.assign({}, testResults)
testResults.results.forEach((result, index) => {
if (result.screenCapture) {
output.results[index].screenCapture = result.screenCapture.replace(/^.*[\\\/]/, '') // eslint-disable-line no-useless-escape
}
})
return template(testResults)
}
// Output error messages
report.error = message => {
return message
}