Skip to content

Commit

Permalink
added test full pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangarano committed Sep 11, 2023
1 parent bda5ae1 commit 9369b8e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 47 deletions.
2 changes: 0 additions & 2 deletions e2e/cypress-12-demo/scripts/files.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import assert from "assert";
import { run } from "cypress-cloud";
import fs from "fs";

Expand All @@ -17,7 +16,6 @@ import fs from "fs";
recordKey,
batchSize: 4,
});
assert(result !== undefined);

const headers = new Headers({
Authorization: `Bearer ${apiKey}`,
Expand Down
53 changes: 43 additions & 10 deletions e2e/cypress-12-demo/scripts/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs";
import { expect } from "chai";
import { run } from "cypress-cloud";

type ComparisonResult = {
path: string;
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion e2e/cypress-13-demo/scripts/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import fs from "fs";
projectId,
recordKey,
});
assert(result !== undefined);

const headers = new Headers({
Authorization: `Bearer ${apiKey}`,
Expand Down
77 changes: 43 additions & 34 deletions e2e/cypress-13-demo/scripts/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "fs";
import { expect } from "chai";
import { run } from "cypress-cloud";

type ComparisonResult = {
path: string;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 9369b8e

Please sign in to comment.