@percy/client
Advanced tools
Comparing version 1.17.0 to 1.18.0
@@ -5,3 +5,3 @@ import fs from 'fs'; | ||
import logger from '@percy/logger'; | ||
import { pool, request, sha256hash, base64encode, getPackageJSON } from './utils.js'; | ||
import { pool, request, sha256hash, base64encode, getPackageJSON, waitForTimeout } from './utils.js'; | ||
@@ -116,3 +116,4 @@ // Default client API URL can be set with an env var for API development | ||
async createBuild({ | ||
resources = [] | ||
resources = [], | ||
projectType | ||
} = {}) { | ||
@@ -124,2 +125,3 @@ this.log.debug('Creating a new build...'); | ||
attributes: { | ||
type: projectType, | ||
branch: this.env.git.branch, | ||
@@ -410,3 +412,4 @@ 'target-branch': this.env.target.branch, | ||
filepath, | ||
content | ||
content, | ||
sha | ||
} = {}) { | ||
@@ -416,2 +419,5 @@ validateId('comparison', comparisonId); | ||
if (filepath) content = await fs.promises.readFile(filepath); | ||
if (sha) { | ||
return await this.verify(comparisonId, sha); | ||
} | ||
return this.post(`comparisons/${comparisonId}/tiles`, { | ||
@@ -427,2 +433,37 @@ data: { | ||
} | ||
// Convenience method for verifying if tile is present | ||
async verify(comparisonId, sha) { | ||
let retries = 10; | ||
let success = null; | ||
do { | ||
await waitForTimeout(500); | ||
success = await this.verifyComparisonTile(comparisonId, sha); | ||
retries -= 1; | ||
} while (retries > 0 && !success); | ||
if (!success) { | ||
this.log.error('Uploading comparison tile failed'); | ||
return false; | ||
} | ||
return true; | ||
} | ||
async verifyComparisonTile(comparisonId, sha) { | ||
validateId('comparison', comparisonId); | ||
this.log.debug(`Verifying comparison tile with sha: ${sha}`); | ||
try { | ||
return await this.get(`comparisons/${comparisonId}/tiles/verify`, { | ||
data: { | ||
type: 'tiles', | ||
attributes: { | ||
sha: sha | ||
} | ||
} | ||
}); | ||
} catch (error) { | ||
if (error.message.includes('409')) { | ||
return false; | ||
} | ||
throw error; | ||
} | ||
} | ||
async uploadComparisonTiles(comparisonId, tiles) { | ||
@@ -429,0 +470,0 @@ validateId('comparison', comparisonId); |
@@ -16,2 +16,5 @@ import os from 'os'; | ||
} | ||
export function waitForTimeout() { | ||
return new Promise(resolve => setTimeout(resolve, ...arguments)); | ||
} | ||
@@ -18,0 +21,0 @@ // Returns the package.json content at the package path. |
{ | ||
"name": "@percy/client", | ||
"version": "1.17.0", | ||
"version": "1.18.0", | ||
"license": "MIT", | ||
@@ -34,6 +34,6 @@ "repository": { | ||
"dependencies": { | ||
"@percy/env": "1.17.0", | ||
"@percy/logger": "1.17.0" | ||
"@percy/env": "1.18.0", | ||
"@percy/logger": "1.18.0" | ||
}, | ||
"gitHead": "b7b2403047ea6208de71c73232df8a5375781a30" | ||
"gitHead": "8aeb759653765fea11e8ebeb96c53a4c4ea616b2" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42174
963
+ Added@percy/env@1.18.0(transitive)
+ Added@percy/logger@1.18.0(transitive)
- Removed@percy/env@1.17.0(transitive)
- Removed@percy/logger@1.17.0(transitive)
Updated@percy/env@1.18.0
Updated@percy/logger@1.18.0