Skip to content

Commit

Permalink
Unbreak runs without happo-cypress -- prefix
Browse files Browse the repository at this point in the history
When working locally, it helps if you can get happo snapshots even if
you're running `cypress open` without the `happo-cypress --` wrapper.
  • Loading branch information
trotzig committed May 26, 2020
1 parent f0a25d6 commit 529ec59
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions task.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const nodeFetch = require('node-fetch');
const makeRequest = require('happo.io/build/makeRequest').default;

const createAssetPackage = require('./src/createAssetPackage');
const findCSSAssetUrls = require('./src/findCSSAssetUrls');
const loadHappoConfig = require('./src/loadHappoConfig');
const makeAbsolute = require('./src/makeAbsolute');
const resolveEnvironment = require('./src/resolveEnvironment');

const { HAPPO_CYPRESS_PORT = 5338 } = process.env;
const { HAPPO_CYPRESS_PORT } = process.env;

let snapshots;
let allCssBlocks;
Expand Down Expand Up @@ -110,15 +112,37 @@ module.exports = {
allRequestIds.push(...requestIds);
}),
);
const fetchRes = await nodeFetch(`http://localhost:${HAPPO_CYPRESS_PORT}/`, {
method: 'POST',
body: allRequestIds.join('\n'),
});
if (!fetchRes.ok) {
console.error(
`[HAPPO] Failed to communicate with happo-cypress process — ${fetchRes.statusText}`,
if (HAPPO_CYPRESS_PORT) {
// We're running with `happo-cypress --`
const fetchRes = await nodeFetch(
`http://localhost:${HAPPO_CYPRESS_PORT}/`,
{
method: 'POST',
body: allRequestIds.join('\n'),
},
);
if (!fetchRes.ok) {
throw new Error('Failed to communicate with happo-cypress server');
}
} else {
// We're not running with `happo-cypress --`. We'll create a report
// despite the fact that it might not contain all the snapshots. This is
// still helpful when running `cypress open` locally.
const { afterSha } = resolveEnvironment();
const reportResult = await makeRequest(
{
url: `${happoConfig.endpoint}/api/async-reports/${afterSha}`,
method: 'POST',
json: true,
body: {
requestIds: allRequestIds,
project: happoConfig.project,
},
},
{ ...happoConfig, maxTries: 3 },
);
return;
console.log(`[HAPPO] ${reportResult.url}`);
return null;
}
return null;
},
Expand Down

0 comments on commit 529ec59

Please sign in to comment.