Skip to content

Commit

Permalink
Seemingly get Cypress uploads working
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed May 7, 2024
1 parent 1932aac commit 9e73937
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ dotenv.config();

const awsConfig = require(path.join(__dirname, "./aws-exports-es5.js"));

const graphqlUrl = "https://api.replay.io/v1/graphql";
const graphqlServer = process.env.CI ? "https://api.replay.io" : "http://localhost:8087";
const graphqlUrl = `${graphqlServer}/v1/graphql`;

module.exports = defineConfig({
projectId: "7s5okt",
video: false,
env: {
apiUrl: "http://localhost:3001",
mobileViewportWidthBreakpoint: 414,
Expand Down Expand Up @@ -75,9 +77,12 @@ module.exports = defineConfig({
setupNodeEvents(on, config) {
on = cypressReplay.wrapOn(on);

// API key for a test suites workspace to upload to
const apiKey = process.env.WORKSPACE_API_KEY;

cypressReplay.default(on, config, {
upload: true,
apiKey: process.env.REPLAY_API_KEY,
apiKey: apiKey,
});

const newRecordings = new Set();
Expand All @@ -97,14 +102,15 @@ module.exports = defineConfig({
if (now - start > 300000) {
throw new Error("Recording did not upload within 5 minutes");
}
const recordingEntries = listAllRecordings({ all: true });
const recordingEntry = recordingEntries.find((entry) => entry.id === recordingId);

let recordingEntries = listAllRecordings({ all: true });
let recordingEntry = recordingEntries.find((entry) => entry.id === recordingId);

console.log("Recording status: ", recordingEntry.id, recordingEntry.status);
if (recordingEntry.status === "uploaded" || recordingEntry.status === "startedUpload") {
uploadedRecordings.add(recordingId);
console.log(new Date(), "Making replay public for recordingId: ", recordingId);
await makeReplayPublic(process.env.REPLAY_API_KEY, recordingId);
await makeReplayPublic(apiKey, recordingId);
console.log(new Date(), "Replay made public for recordingId: ", recordingId);
break;
} else {
Expand All @@ -116,6 +122,8 @@ module.exports = defineConfig({
on("after:spec", async (afterSpec) => {
const recordingEntries = listAllRecordings({ all: true });

console.log("All recordings: ", recordingEntries);

for (const recordingEntry of recordingEntries) {
if (!newRecordings.has(recordingEntry.id)) {
newRecordings.add(recordingEntry.id);
Expand Down Expand Up @@ -165,6 +173,17 @@ module.exports = defineConfig({
},
});

function logError(e, variables) {
if (e.response) {
console.log("Parameters");
console.log(JSON.stringify(variables, undefined, 2));
console.log("Response");
console.log(JSON.stringify(e.response.data, undefined, 2));
}

throw e.message;
}

async function makeReplayPublic(apiKey, recordingId) {
const variables = {
recordingId: recordingId,
Expand Down

0 comments on commit 9e73937

Please sign in to comment.