From 9e73937adf34058fde9201eff748e841d0be4795 Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Mon, 6 May 2024 14:20:03 -0400 Subject: [PATCH] Seemingly get Cypress uploads working --- cypress.config.js | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index efd3e335e1..5fb0927e72 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -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, @@ -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(); @@ -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 { @@ -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); @@ -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,