Comparing version 2.2.4 to 2.2.5
@@ -108,33 +108,29 @@ const crypto = require('crypto'); | ||
async finish() { | ||
async uploadAssetsIfNeeded({ buffer, hash }) { | ||
if (HAPPO_DEBUG) { | ||
console.log('[HAPPO] Running Controller.finish'); | ||
console.log(`[HAPPO] Checking if we need to upload assets`); | ||
} | ||
if (this.localSnapshots.length) { | ||
try { | ||
// Check if the assets already exist. If so, we don't have to upload them. | ||
const assetsDataRes = await makeRequest( | ||
{ | ||
url: `${this.happoConfig.endpoint}/api/snap-requests/assets-data/${hash}`, | ||
method: 'GET', | ||
json: true, | ||
}, | ||
{ ...this.happoConfig }, | ||
); | ||
if (HAPPO_DEBUG) { | ||
console.log( | ||
`[HAPPO] Processing ${this.localSnapshots.length} local snapshots`, | ||
`[HAPPO] Reusing existing assets at ${assetsDataRes.path} (previously uploaded on ${assetsDataRes.uploadedAt})`, | ||
); | ||
} | ||
await this.processSnapRequestIds([await this.uploadLocalSnapshots()]); | ||
return null; | ||
} | ||
if (!this.snapshots.length) { | ||
if (HAPPO_DEBUG) { | ||
console.log('[HAPPO] No snapshots recorded'); | ||
return assetsDataRes.path; | ||
} catch (e) { | ||
if (e.statusCode !== 404) { | ||
throw e; | ||
} | ||
return null; | ||
} | ||
this.dedupeSnapshots(); | ||
await downloadCSSContent(this.allCssBlocks); | ||
const allUrls = [...this.snapshotAssetUrls]; | ||
this.allCssBlocks.forEach(block => { | ||
findCSSAssetUrls(block.content).forEach(url => | ||
allUrls.push({ url, baseUrl: block.assetsBaseUrl || block.baseUrl }), | ||
); | ||
}); | ||
const uniqueUrls = getUniqueUrls(allUrls); | ||
const { buffer, hash } = await createAssetPackage(uniqueUrls); | ||
if (HAPPO_DEBUG) { | ||
@@ -163,3 +159,38 @@ console.log(`[HAPPO] Uploading assets package`); | ||
} | ||
return assetsRes.path; | ||
} | ||
async finish() { | ||
if (HAPPO_DEBUG) { | ||
console.log('[HAPPO] Running Controller.finish'); | ||
} | ||
if (this.localSnapshots.length) { | ||
if (HAPPO_DEBUG) { | ||
console.log( | ||
`[HAPPO] Processing ${this.localSnapshots.length} local snapshots`, | ||
); | ||
} | ||
await this.processSnapRequestIds([await this.uploadLocalSnapshots()]); | ||
return null; | ||
} | ||
if (!this.snapshots.length) { | ||
if (HAPPO_DEBUG) { | ||
console.log('[HAPPO] No snapshots recorded'); | ||
} | ||
return null; | ||
} | ||
this.dedupeSnapshots(); | ||
await downloadCSSContent(this.allCssBlocks); | ||
const allUrls = [...this.snapshotAssetUrls]; | ||
this.allCssBlocks.forEach(block => { | ||
findCSSAssetUrls(block.content).forEach(url => | ||
allUrls.push({ url, baseUrl: block.assetsBaseUrl || block.baseUrl }), | ||
); | ||
}); | ||
const uniqueUrls = getUniqueUrls(allUrls); | ||
const { buffer, hash } = await createAssetPackage(uniqueUrls); | ||
const assetsPath = await this.uploadAssetsIfNeeded({ buffer, hash }); | ||
const globalCSS = this.allCssBlocks.map(block => ({ | ||
@@ -210,3 +241,3 @@ id: block.key, | ||
globalCSS, | ||
assetsPackage: assetsRes.path, | ||
assetsPackage: assetsPath, | ||
snapPayloads: snapshotsForTarget, | ||
@@ -213,0 +244,0 @@ apiKey: this.happoConfig.apiKey, |
{ | ||
"name": "happo-e2e", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "Helpers for e2e integrations with Happo", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
772189
2961