diff --git a/src/createAssetPackage.js b/src/createAssetPackage.js index a433b5d..1b4c7b4 100644 --- a/src/createAssetPackage.js +++ b/src/createAssetPackage.js @@ -6,7 +6,7 @@ const { Writable } = require('stream'); const proxiedFetch = require('./fetch'); const makeAbsolute = require('./makeAbsolute'); -const { HAPPO_DOWNLOAD_ALL } = process.env; +const { HAPPO_DOWNLOAD_ALL, HAPPO_DEBUG } = process.env; const FILE_CREATION_DATE = new Date( 'Fri March 20 2020 13:44:55 GMT+0100 (CET)', @@ -30,6 +30,9 @@ function normalize(url, baseUrl) { } module.exports = function createAssetPackage(urls) { + if (HAPPO_DEBUG) { + console.log(`[HAPPO] Creating asset package from urls`, urls); + } // eslint-disable-next-line no-async-promise-executor return new Promise(async resolve => { const seenUrls = new Set(); @@ -47,6 +50,11 @@ module.exports = function createAssetPackage(urls) { stream.on('finish', () => { const buffer = Buffer.from(data); const hash = crypto.createHash('md5').update(buffer).digest('hex'); + if (HAPPO_DEBUG) { + console.log( + `[HAPPO] Done creating asset package, hash=${hash} total bytes=${buffer.length}`, + ); + } resolve({ buffer, hash }); }); archive.pipe(stream); @@ -73,6 +81,11 @@ module.exports = function createAssetPackage(urls) { }); } else { const fetchUrl = makeAbsolute(url, baseUrl); + if (HAPPO_DEBUG) { + console.log( + `[HAPPO] Fetching asset from ${fetchUrl} — storing as ${name}`, + ); + } const fetchRes = await proxiedFetch(fetchUrl); if (!fetchRes.ok) { console.log( diff --git a/task.js b/task.js index 575af56..8a0a300 100644 --- a/task.js +++ b/task.js @@ -9,7 +9,7 @@ const loadHappoConfig = require('./src/loadHappoConfig'); const makeAbsolute = require('./src/makeAbsolute'); const resolveEnvironment = require('./src/resolveEnvironment'); -const { HAPPO_CYPRESS_PORT } = process.env; +const { HAPPO_CYPRESS_PORT, HAPPO_DEBUG } = process.env; let snapshots; let allCssBlocks; @@ -44,6 +44,9 @@ async function downloadCSSContent(blocks) { const promises = blocks.map(async block => { if (block.href) { const absUrl = makeAbsolute(block.href, block.baseUrl); + if (HAPPO_DEBUG) { + console.log(`[HAPPO] Downloading CSS file from ${absUrl}`); + } const res = await proxiedFetch(absUrl); if (!res.ok) { console.warn( @@ -52,6 +55,11 @@ async function downloadCSSContent(blocks) { return; } let text = await res.text(); + if (HAPPO_DEBUG) { + console.log( + `[HAPPO] Done downloading CSS file from ${absUrl}. Got ${text.length} chars back.`, + ); + } if (!absUrl.startsWith(block.baseUrl)) { text = makeExternalUrlsAbsolute(text, absUrl); } @@ -123,6 +131,9 @@ module.exports = { const uniqueUrls = getUniqueUrls(allUrls); const { buffer, hash } = await createAssetPackage(uniqueUrls); + if (HAPPO_DEBUG) { + console.log(`[HAPPO] Uploading assets package`); + } const assetsRes = await makeRequest( { url: `${happoConfig.endpoint}/api/snap-requests/assets/${hash}`, @@ -140,6 +151,9 @@ module.exports = { }, { ...happoConfig, maxTries: 3 }, ); + if (HAPPO_DEBUG) { + console.log('[HAPPO] Done uploading assets package, got', assetsRes); + } let globalCSS = allCssBlocks.map(block => block.content).join('\n'); for (const url of uniqueUrls) { @@ -153,6 +167,9 @@ module.exports = { const allRequestIds = []; await Promise.all( Object.keys(happoConfig.targets).map(async name => { + if (HAPPO_DEBUG) { + console.log(`[HAPPO] Sending snap-request(s) for target=${name}`); + } const snapshotsForTarget = snapshots.filter( ({ targets }) => !targets || targets.includes(name), ); @@ -166,6 +183,13 @@ module.exports = { apiKey: happoConfig.apiKey, apiSecret: happoConfig.apiSecret, }); + if (HAPPO_DEBUG) { + console.log( + `[HAPPO] Snap-request(s) for target=${name} created with ID(s)=${requestIds.join( + ',', + )}`, + ); + } allRequestIds.push(...requestIds); }), );