From 9369b8e79353c320073810063efd48fb85d98c7a Mon Sep 17 00:00:00 2001 From: Miguel Langarano Date: Mon, 11 Sep 2023 09:25:19 -0500 Subject: [PATCH] added test full pipeline --- e2e/cypress-12-demo/scripts/files.ts | 2 - e2e/cypress-12-demo/scripts/test.ts | 53 +++++++++++++++---- e2e/cypress-13-demo/scripts/files.ts | 1 - e2e/cypress-13-demo/scripts/test.ts | 77 ++++++++++++++++------------ 4 files changed, 86 insertions(+), 47 deletions(-) diff --git a/e2e/cypress-12-demo/scripts/files.ts b/e2e/cypress-12-demo/scripts/files.ts index ee82bcf..2b863dc 100644 --- a/e2e/cypress-12-demo/scripts/files.ts +++ b/e2e/cypress-12-demo/scripts/files.ts @@ -1,4 +1,3 @@ -import assert from "assert"; import { run } from "cypress-cloud"; import fs from "fs"; @@ -17,7 +16,6 @@ import fs from "fs"; recordKey, batchSize: 4, }); - assert(result !== undefined); const headers = new Headers({ Authorization: `Bearer ${apiKey}`, diff --git a/e2e/cypress-12-demo/scripts/test.ts b/e2e/cypress-12-demo/scripts/test.ts index 7e17e32..e5b00ae 100644 --- a/e2e/cypress-12-demo/scripts/test.ts +++ b/e2e/cypress-12-demo/scripts/test.ts @@ -1,5 +1,6 @@ import fs from "fs"; import { expect } from "chai"; +import { run } from "cypress-cloud"; type ComparisonResult = { path: string; @@ -270,6 +271,44 @@ function testEachResults(results: ComparisonResult[]) { }); } +async function runTests() { + const projectId = process.env.CURRENTS_PROJECT_ID || "2cI1I5"; + const recordKey = process.env.CURRENTS_RECORD_KEY || "YakSabgBLb7D40nZ"; + + const ciBuildId = `run-api-smoke-${new Date().toISOString()}`; + const result: any = await run({ + ciBuildId, + projectId, + recordKey, + batchSize: 4, + }); + + return result; +} + +async function getApiData(runUrl: string) { + const apiKey = + process.env.CURRENTS_API_KEY || + "YpYIAerb1rWuOFrvf7ciK8Za8koKgrtRfoDPboQUOjScnBv91m4qAXSDb8Rb57m9"; + const apiUrl = "https://api.currents.dev/v1/runs/"; + + const headers = new Headers({ + Authorization: `Bearer ${apiKey}`, + }); + + try { + const response = await fetch(`${apiUrl}${runUrl.split("run/")[1]}`, { + method: "GET", + headers, + }); + const result = await response.json(); + + return result; + } catch (e: any) { + throw new Error(e.toString()); + } +} + (async function runTest() { try { const originalCurrentApiFile = fs.readFileSync( @@ -284,17 +323,11 @@ function testEachResults(results: ComparisonResult[]) { const originalCurrentApi = JSON.parse(originalCurrentApiFile); const originalCypressCloud = JSON.parse(originalCypressCloudFile); - const modifiedCurrentApiFile = fs.readFileSync( - "data-references/ccy-1.10-cypress-12/currents-api-output-reference.json", - "utf8" - ); - const modifiedCypressCloudFile = fs.readFileSync( - "data-references/ccy-1.10-cypress-12/cypress-cloud-output-reference.json", - "utf8" - ); + const cypressCloudData = await runTests(); + const currentsApiData = await getApiData(cypressCloudData.runUrl); - const modifiedCurrentApi = JSON.parse(modifiedCurrentApiFile); - const modifiedCypressCloud = JSON.parse(modifiedCypressCloudFile); + const modifiedCurrentApi = currentsApiData; + const modifiedCypressCloud = cypressCloudData; const currentsApiResults = compareObjectsRecursively( originalCurrentApi, diff --git a/e2e/cypress-13-demo/scripts/files.ts b/e2e/cypress-13-demo/scripts/files.ts index 5fcaa25..a730188 100644 --- a/e2e/cypress-13-demo/scripts/files.ts +++ b/e2e/cypress-13-demo/scripts/files.ts @@ -16,7 +16,6 @@ import fs from "fs"; projectId, recordKey, }); - assert(result !== undefined); const headers = new Headers({ Authorization: `Bearer ${apiKey}`, diff --git a/e2e/cypress-13-demo/scripts/test.ts b/e2e/cypress-13-demo/scripts/test.ts index 603ca80..ee41f0c 100644 --- a/e2e/cypress-13-demo/scripts/test.ts +++ b/e2e/cypress-13-demo/scripts/test.ts @@ -1,5 +1,6 @@ import fs from "fs"; import { expect } from "chai"; +import { run } from "cypress-cloud"; type ComparisonResult = { path: string; @@ -223,30 +224,6 @@ const avoidableProperties: { property: string; mustHave: boolean }[] = [ property: "runUrl", mustHave: true, }, - { - property: "commit.message", - mustHave: true, - }, - { - property: "commit.sha", - mustHave: true, - }, - { - property: "spec.absolute", - mustHave: true, - }, - { - property: "video", - mustHave: true, - }, - { - property: "displayError", - mustHave: true, - }, - { - property: "relativeFile", - mustHave: true, - }, ]; function isAvoidableProperty(property: string) { @@ -286,6 +263,44 @@ function testEachResults(results: ComparisonResult[]) { }); } +async function runTests() { + const projectId = process.env.CURRENTS_PROJECT_ID || "2cI1I5"; + const recordKey = process.env.CURRENTS_RECORD_KEY || "YakSabgBLb7D40nZ"; + + const ciBuildId = `run-api-smoke-${new Date().toISOString()}`; + const result: any = await run({ + ciBuildId, + projectId, + recordKey, + batchSize: 4, + }); + + return result; +} + +async function getApiData(runUrl: string) { + const apiKey = + process.env.CURRENTS_API_KEY || + "YpYIAerb1rWuOFrvf7ciK8Za8koKgrtRfoDPboQUOjScnBv91m4qAXSDb8Rb57m9"; + const apiUrl = "https://api.currents.dev/v1/runs/"; + + const headers = new Headers({ + Authorization: `Bearer ${apiKey}`, + }); + + try { + const response = await fetch(`${apiUrl}${runUrl.split("run/")[1]}`, { + method: "GET", + headers, + }); + const result = await response.json(); + + return result; + } catch (e: any) { + throw new Error(e.toString()); + } +} + (async function runTest() { try { const originalCurrentApiFile = fs.readFileSync( @@ -300,17 +315,11 @@ function testEachResults(results: ComparisonResult[]) { const originalCurrentApi = JSON.parse(originalCurrentApiFile); const originalCypressCloud = JSON.parse(originalCypressCloudFile); - const modifiedCurrentApiFile = fs.readFileSync( - "data-references/ccy-1.10-cypress-13/currents-api-output-reference.json", - "utf8" - ); - const modifiedCypressCloudFile = fs.readFileSync( - "data-references/ccy-1.10-cypress-13/cypress-cloud-output-reference.json", - "utf8" - ); + const cypressCloudData = await runTests(); + const currentsApiData = await getApiData(cypressCloudData.runUrl); - const modifiedCurrentApi = JSON.parse(modifiedCurrentApiFile); - const modifiedCypressCloud = JSON.parse(modifiedCypressCloudFile); + const modifiedCurrentApi = currentsApiData; + const modifiedCypressCloud = cypressCloudData; const currentsApiResults = compareObjectsRecursively( originalCurrentApi,