@percy/report 0.0.5 → 0.0.7

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.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/src/generate.js +22 -9
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": "0.0.5",
4
+ "version": "0.0.7",
5
5
  "main": "src/index.js",
6
6
  "license": "MIT",
7
7
  "author": "BrowserStack Pvt Ltd",
@@ -44,11 +44,12 @@
44
44
  "commander": "^9.4.0",
45
45
  "date-fns": "^2.29.3",
46
46
  "dotenv": "^16.0.3",
47
- "ejs": "^3.1.8"
47
+ "ejs": "^3.1.8",
48
+ "p-queue": "^8.0.1"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@percy/selenium-webdriver": "^1.0.2",
51
52
  "chai": "^4.3.7",
52
53
  "mocha": "^10.2.0"
53
54
  }
54
- }
55
+ }
package/src/generate.js CHANGED
@@ -9,6 +9,7 @@ const defaultConfig = {
9
9
  downloadPath: './Reports',
10
10
  diffThreshold: 1
11
11
  }
12
+ let downloadQueue;
12
13
  module.exports.Generate = async function (config) {
13
14
  let { buildId, percyToken, apiUrl, downloadImages, downloadPath, diffThreshold } = Object.assign({}, defaultConfig, config)
14
15
  let axios = new Axios({
@@ -28,6 +29,11 @@ module.exports.Generate = async function (config) {
28
29
  throw res.data
29
30
  }
30
31
  })
32
+ if(!downloadQueue){
33
+ await import('p-queue').then(({default:PQueue})=>{
34
+ downloadQueue = new PQueue({concurrency:1,intervalCap:5,interval:5000})
35
+ })
36
+ }
31
37
  const isApp = buildDetails['data']['attributes']['type'] == 'app'
32
38
  while (buildDetails.data && buildDetails.data.attributes.state !== 'finished') {
33
39
  console.log("Waiting for build to complete on Percy...")
@@ -101,10 +107,12 @@ module.exports.Generate = async function (config) {
101
107
  }
102
108
  }
103
109
  if (downloadImages) {
110
+
111
+
104
112
  ['base', 'head', 'diff'].forEach((val) => {
105
113
  if (images[val]) {
106
114
  images[val].file = downloadImage({
107
- name: String(snapshot?.['attributes'].name).replace('/', '-'),
115
+ name: String(snapshot?.['attributes'].name),
108
116
  compTag,
109
117
  width: images[val].width,
110
118
  type: val,
@@ -127,7 +135,7 @@ module.exports.Generate = async function (config) {
127
135
 
128
136
  comparison['diff-percentage'] = (comparison['diff-ratio'] * 100).toFixed(2)
129
137
  comparison['diff-color'] = "yellow"
130
- if (comparison['diff-percentage'] > diffThreshold) {
138
+ if (Number(comparison['diff-percentage']) > Number(diffThreshold)) {
131
139
  comparison['diff-color'] = "red"
132
140
  }
133
141
  return comparison
@@ -167,18 +175,23 @@ function downloadImage(options) {
167
175
  if (!fs.existsSync(`${baseDir}/${type}`)) {
168
176
  fs.mkdirSync(`${baseDir}/${type}`, { recursive: true })
169
177
  }
170
- let path = `${baseDir}/${type}/${name}-${compTag}-${width}.png`
178
+ let composedName = `${name}-${compTag}-${width}.png`.replace(/[\\\/]/g,'_')
179
+ let path = `${baseDir}/${type}/${composedName}`
171
180
  try {
172
- new Axios({ responseType: 'arraybuffer', url: url }).get(url).then((file) => {
181
+ downloadQueue.add(()=>new Axios({ responseType: 'arraybuffer', url: url }).get(url).then((file) => {
173
182
  console.log("Download Complete:" + path)
174
183
  fs.writeFileSync(path, file.data)
175
184
  }).catch((err) => {
176
185
  console.error("Failed to Download: " + path)
177
- console.error(err)
178
- })
179
- return `file:./${type}/${name}-${compTag}-${width}.png`;
180
- } catch {
181
-
186
+ if(err.code == 'ECONNRESET'){
187
+ console.log('Retrying '+ path)
188
+ }else{
189
+ console.error(`Failed ${path}, error: ${err.code}`)
190
+ }
191
+ }))
192
+ return `file:./${type}/${composedName}`;
193
+ } catch(err) {
194
+
182
195
  }
183
196
  }
184
197