Skip to content

Commit

Permalink
added avoided properties to make the tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangarano committed Sep 12, 2023
1 parent cd64d3a commit 917ab2c
Show file tree
Hide file tree
Showing 10 changed files with 514 additions and 1,822 deletions.
164 changes: 131 additions & 33 deletions e2e/cypress-12-demo/scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ function compareObjectsRecursively(
return results;
}

const avoidableProperties: { property: string; mustHave: boolean }[] = [
const avoidableProperties: {
property: string | RegExp;
mustHave: boolean;
isRegex?: boolean;
}[] = [
{
property: "runId",
mustHave: true,
Expand Down Expand Up @@ -238,43 +242,133 @@ const avoidableProperties: { property: string; mustHave: boolean }[] = [
property: "cypressVersion",
mustHave: true,
},
{
property: "env.currents_temp_file",
mustHave: true,
},
{
property: "config.browsers[0].version",
mustHave: true,
},
{
property: "config.resolved.browsers.value[0].version",
mustHave: true,
},
];

const avoidedButNeedeProperties: {
property: string | RegExp;
mustHave: boolean;
isRegex?: boolean;
}[] = [
{
property:
/runs\[\d+\]\.tests\[\d+\]\.attempts\[\d+\]\.timings\.after each\[1\]/,
mustHave: true,
isRegex: true,
},
{
property:
/runs\[\d+\]\.tests\[\d+\]\.attempts\[\d+\]\.timings\.after all/,
mustHave: true,
isRegex: true,
},
{
property: "runs[2].tests[0].attempts[0]",
mustHave: true,
},
{
property: "runs[2].tests[0].testId",
mustHave: true,
},
];

const similarProperties: { property: string; similarProperty: string }[] = [];

function isAvoidableProperty(property: string) {
const avoidableData = avoidableProperties.find((item) =>
property.includes(item.property)
);
const avoidableData = [
...avoidableProperties,
...avoidedButNeedeProperties,
].find((item) => {
if (item.isRegex) {
return (item.property as RegExp).test(property);
}

return property.includes(item.property as string);
});
if (avoidableData) {
return avoidableData;
}
return;
}

function isSimilarProperty(propertyA: string) {
const similarData = similarProperties.find((item) =>
propertyA.includes(item.property)
);
if (similarData) {
return similarData;
}
return;
}

function testEachResults(results: ComparisonResult[]) {
const errors: string[] = [];
results.forEach((result) => {
if (result.valueA) {
const avoidableData = isAvoidableProperty(result.path);
if (!avoidableData) {
expect(
result.valueA,
`The values are not equal at: ${result.path}. ${
result.note ?? ""
}`
).to.equal(result.valueB);
return;
}
try {
if (result.valueA) {
const avoidableData = isAvoidableProperty(result.path);
const similarData = isSimilarProperty(result.path);

if (similarData) {
const similarPath = result.path.split(similarData.property);
const valueB = results.find(
(item) =>
item.path ===
`${similarPath[0]}${similarData.similarProperty}`
)?.valueB;
expect(
result.valueA,
`The values are not equal at: ${result.path}. ${
result.note ?? ""
}`
).to.equal(valueB);
return;
}

if (avoidableData.mustHave) {
expect(
result.valueB,
`The values at ${
result.path
} does not exist and it should. ${result.note ?? ""}`
).not.to.equal("Does not exist");
return;
if (!avoidableData) {
expect(
result.valueA,
`The values are not equal at: ${result.path}. ${
result.note ?? ""
}`
).to.equal(result.valueB);
return;
}

if (avoidableData.mustHave) {
expect(
result.valueB,
`The values at ${
result.path
} does not exist and it should. ${result.note ?? ""}`
).not.to.equal("Does not exist");
expect(
result.valueB,
`The values at ${
result.path
} does not exist and it should. ${result.note ?? ""}`
).not.to.equal("undefined");
return;
}
}
} catch (e: any) {
const error = `${errors.length}.- ${e.toString()}`;
errors.push(error);
console.log(error.red);
}
});
return errors;
}

async function runTests() {
Expand Down Expand Up @@ -342,12 +436,14 @@ async function getApiData(runUrl: string) {

console.log("Starting test: Currents API output".yellow);

testEachResults(currentsApiResults);
const currentsApiErrors = testEachResults(currentsApiResults);

console.log(
"Test Passed: Currents API output is the same in ccy 1.9 cypress 12 without change and ccy 1.9 cypress 12 with changes"
.green
);
if (currentsApiErrors.length === 0) {
console.log(
"Test Passed: Currents API output is the same in ccy 1.9 cypress 12 without change and ccy 1.10 cypress 12 with changes"
.green
);
}

console.log("Starting test: Cypress Cloud output".yellow);

Expand All @@ -356,12 +452,14 @@ async function getApiData(runUrl: string) {
modifiedCypressCloud
);

testEachResults(cypressCloudResults);
const cypressCloudErrors = testEachResults(cypressCloudResults);

console.log(
"Test Passed: Cypress Cloud output is the same in ccy 1.9 cypress 12 without change and ccy 1.9 cypress 12 with changes"
.green
);
if (cypressCloudErrors.length === 0) {
console.log(
"Test Passed: Cypress Cloud output is the same in ccy 1.9 cypress 12 without change and ccy 1.9 cypress 12 with changes"
.green
);
}
} catch (err) {
console.error("Process error:", err);
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 917ab2c

Please sign in to comment.