Skip to content

Commit

Permalink
Merge pull request #25 from happo/debug-cypress-timeout
Browse files Browse the repository at this point in the history
Add more debug logs
  • Loading branch information
trotzig authored Jul 9, 2020
2 parents d3d6497 + 7b18389 commit f47a47b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/createAssetPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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(
Expand Down
26 changes: 25 additions & 1 deletion task.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down Expand Up @@ -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}`,
Expand All @@ -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) {
Expand All @@ -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),
);
Expand All @@ -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);
}),
);
Expand Down

0 comments on commit f47a47b

Please sign in to comment.