@percy/report 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/generate.js +37 -13
- package/src/html-render.js +3 -3
- package/src/summary.js +2 -2
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ Step 3 : Execute the Percy Report Generation Step<br>
|
|
|
46
46
|
[Example](/example/percy.sh):
|
|
47
47
|
```sh
|
|
48
48
|
export PERCY_TOKEN=<your-percy-token>
|
|
49
|
-
BUILD_ID=$(npx percy exec -- {Test Command} | grep
|
|
49
|
+
BUILD_ID=$(npx percy exec -- {Test Command} | grep https:\/\/percy.io\/.*\/builds | awk -F "/" '{print $NF}')
|
|
50
50
|
npx percy-report generate $BUILD_ID
|
|
51
51
|
```
|
|
52
52
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/report",
|
|
3
3
|
"description": "Package to generate a build report and project summary report for Percy, BrowserStack's visual testing platform",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.6",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "BrowserStack Pvt Ltd",
|
package/src/generate.js
CHANGED
|
@@ -34,7 +34,7 @@ module.exports.Generate = async function (config) {
|
|
|
34
34
|
downloadQueue = new PQueue({concurrency:1,intervalCap:5,interval:5000})
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
|
-
const
|
|
37
|
+
const useCompTag = buildDetails['data']['attributes']['type'] == 'app' || buildDetails['data']['attributes']['type'] == 'automate'
|
|
38
38
|
while (buildDetails.data && buildDetails.data.attributes.state !== 'finished') {
|
|
39
39
|
console.log("Waiting for build to complete on Percy...")
|
|
40
40
|
await wait(30000)
|
|
@@ -49,17 +49,41 @@ module.exports.Generate = async function (config) {
|
|
|
49
49
|
throw new Error("Build Failed with an Error on Percy Server. Please check your percy dashboard for more information.")
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
console.log(`Generating report for Build ID ${buildId}`)
|
|
54
|
-
let snapshotsData = await axios.get(`/snapshots?build_id=${buildId}`, { responseType: 'json' }).then((res) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
// let snapshotsData = await axios.get(`/snapshots?build_id=${buildId}`, { responseType: 'json' }).then((res) => {
|
|
55
|
+
// if (res.status == 200) {
|
|
56
|
+
// let parser = new Parser(res.data)
|
|
57
|
+
// let data = parser.getSimplified()
|
|
58
|
+
// return data
|
|
59
|
+
// } else {
|
|
60
|
+
// throw res.data
|
|
61
|
+
// }
|
|
62
|
+
// })
|
|
63
|
+
//
|
|
64
|
+
let snapshotsData = [];
|
|
65
|
+
let cursor = null;
|
|
66
|
+
let hasMore = true;
|
|
67
|
+
|
|
68
|
+
while (hasMore) {
|
|
69
|
+
const cursorParam = cursor ? `&page[cursor]=${cursor}` : '';
|
|
70
|
+
const response = await axios.get(`/snapshots?build_id=${buildId}${cursorParam}`, { responseType: 'json' });
|
|
71
|
+
if (response.status === 200) {
|
|
72
|
+
let parser = new Parser(response.data);
|
|
73
|
+
let data = parser.getSimplified();
|
|
74
|
+
if (data.length > 0) {
|
|
75
|
+
snapshotsData.push(...data);
|
|
76
|
+
cursor = data[data.length - 1].id; // update cursor to last snapshot ID
|
|
77
|
+
// If less than a typical page size (usually 20), stop
|
|
78
|
+
// hasMore = data.length >= 20;
|
|
79
|
+
} else {
|
|
80
|
+
hasMore = false;
|
|
81
|
+
}
|
|
59
82
|
} else {
|
|
60
|
-
throw
|
|
83
|
+
throw response.data;
|
|
61
84
|
}
|
|
62
|
-
}
|
|
85
|
+
}
|
|
86
|
+
|
|
63
87
|
buildURL = buildDetails['data']['attributes']['web-url']
|
|
64
88
|
projectURL = buildURL.split("/builds/")[0]
|
|
65
89
|
projectName = projectURL.split('/').slice(-1)[0]
|
|
@@ -89,8 +113,8 @@ module.exports.Generate = async function (config) {
|
|
|
89
113
|
let head = images['head'] = getComparisonImage(comp, 'head-screenshot')
|
|
90
114
|
let diff = images['diff'] = getComparisonImage(comp, 'diff-image')
|
|
91
115
|
let compTag;
|
|
92
|
-
Object.assign(comparison, comp.attributes, { images },
|
|
93
|
-
if (
|
|
116
|
+
Object.assign(comparison, comp.attributes, { images }, useCompTag?{ device:compTag }:{browser:compTag});
|
|
117
|
+
if (useCompTag) {
|
|
94
118
|
let device = getComparisonDevice(comp)
|
|
95
119
|
compTag = `${device.name} (${device['os-name']} ${device['os-version']})`
|
|
96
120
|
if(!report.devices.includes(compTag)){
|
|
@@ -130,7 +154,7 @@ module.exports.Generate = async function (config) {
|
|
|
130
154
|
report['unreviewedScreenshots']++
|
|
131
155
|
flagChanged = true
|
|
132
156
|
}
|
|
133
|
-
Object.assign(comparison, comp.attributes, { images },
|
|
157
|
+
Object.assign(comparison, comp.attributes, { images }, useCompTag?{ device:compTag }:{browser:compTag})
|
|
134
158
|
|
|
135
159
|
|
|
136
160
|
comparison['diff-percentage'] = (comparison['diff-ratio'] * 100).toFixed(2)
|
|
@@ -146,7 +170,7 @@ module.exports.Generate = async function (config) {
|
|
|
146
170
|
return formattedSnapshot
|
|
147
171
|
})
|
|
148
172
|
fs.writeFileSync(`${baseDir}/report.json`, JSON.stringify(report, undefined, 2))
|
|
149
|
-
HtmlReportGenerator(config, report,
|
|
173
|
+
HtmlReportGenerator(config, report, useCompTag)
|
|
150
174
|
console.log("Build Report Generated.")
|
|
151
175
|
return report
|
|
152
176
|
}
|
package/src/html-render.js
CHANGED
|
@@ -2,7 +2,7 @@ const fs = require('fs')
|
|
|
2
2
|
const ejs = require('ejs');
|
|
3
3
|
const path = require('path')
|
|
4
4
|
|
|
5
|
-
function HtmlReportGenerator(config, jsonReport,
|
|
5
|
+
function HtmlReportGenerator(config, jsonReport, useCompTag) {
|
|
6
6
|
let {
|
|
7
7
|
buildId,
|
|
8
8
|
downloadPath
|
|
@@ -24,8 +24,8 @@ function HtmlReportGenerator(config, jsonReport, isApp) {
|
|
|
24
24
|
fs.writeFileSync(`${downloadPath}/${buildId}/report.html`, htmlReport)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function HtmlSummary(summary, filename,
|
|
28
|
-
if (
|
|
27
|
+
function HtmlSummary(summary, filename, useCompTag) {
|
|
28
|
+
if (useCompTag) {
|
|
29
29
|
let template_path = path.resolve(__dirname, 'template/app-summary.html')
|
|
30
30
|
const template = fs.readFileSync(template_path, {
|
|
31
31
|
encoding: "utf-8"
|
package/src/summary.js
CHANGED
|
@@ -35,7 +35,7 @@ module.exports.Summary = async function (opts) {
|
|
|
35
35
|
throw res.data
|
|
36
36
|
}
|
|
37
37
|
})
|
|
38
|
-
const
|
|
38
|
+
const useCompTag = project['data']['attributes']['type'] == 'app' || project['data']['attributes']['type'] == 'automate'
|
|
39
39
|
let projectId = project.data.id
|
|
40
40
|
let projectURL = "https://percy.io/"+project.data.attributes['full-slug']
|
|
41
41
|
let projectName = project.data.attributes.name
|
|
@@ -131,7 +131,7 @@ module.exports.Summary = async function (opts) {
|
|
|
131
131
|
fs.mkdirSync('Summary',{recursive:true})
|
|
132
132
|
}
|
|
133
133
|
fs.writeFileSync(`Summary/${summary.projectName}-${Date.now()}.json`,JSON.stringify(summary,undefined,2))
|
|
134
|
-
HtmlSummary(summary,`Summary/${summary.projectName}-${Date.now()}.html`,
|
|
134
|
+
HtmlSummary(summary,`Summary/${summary.projectName}-${Date.now()}.html`, useCompTag)
|
|
135
135
|
console.log("Summary report generated")
|
|
136
136
|
return summary;
|
|
137
137
|
|