Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Cypress/E2E: Fix reporting and save environment details to dashboard #7888

Merged
merged 1 commit into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions e2e/generate_test_cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,20 @@

const os = require('os');
const chalk = require('chalk');
const axios = require('axios');

const {createAndStartCycle} = require('./utils/dashboard');
const {getSortedTestFiles} = require('./utils/file');

require('dotenv').config();

const {
AUTOMATION_DASHBOARD_URL,
AUTOMATION_DASHBOARD_TOKEN,
BRANCH,
BROWSER,
BUILD_ID,
HEADLESS,
REPO,
} = process.env;

async function createAndStartCycle(data) {
const response = await axios({
url: `${AUTOMATION_DASHBOARD_URL}/cycles/start`,
headers: {
Authorization: `Bearer ${AUTOMATION_DASHBOARD_TOKEN}`,
},
method: 'post',
timeout: 10000,
data,
});

return response.data;
}

async function main() {
const browser = BROWSER || 'chrome';
const headless = typeof HEADLESS === 'undefined' ? true : HEADLESS === 'true';
Expand Down
36 changes: 0 additions & 36 deletions e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"path": "0.12.7",
"pg": "8.5.1",
"recursive-readdir": "2.2.2",
"reportportal-client": "5.5.0",
"shelljs": "0.8.4",
"start-server-and-test": "1.12.1",
"uuid": "8.3.2",
Expand Down
87 changes: 29 additions & 58 deletions e2e/run_test_cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ const axiosRetry = require('axios-retry');
const chalk = require('chalk');
const cypress = require('cypress');

const {MOCHAWESOME_REPORT_DIR} = require('./utils/constants');
const {
getSpecToTest,
recordSpecResult,
updateCycle,
} = require('./utils/dashboard');
const {writeJsonToFile} = require('./utils/report');
const {MOCHAWESOME_REPORT_DIR, RESULTS_DIR} = require('./utils/constants');

require('dotenv').config();
axiosRetry(axios, {
Expand All @@ -36,66 +42,13 @@ axiosRetry(axios, {
});

const {
AUTOMATION_DASHBOARD_URL,
AUTOMATION_DASHBOARD_TOKEN,
BRANCH,
BUILD_ID,
CI_BASE_URL,
REPO,
} = process.env;

const connectionErrors = ['ECONNABORTED', 'ECONNREFUSED'];

async function getSpecToTest({repo, branch, build, server}) {
try {
const response = await axios({
url: `${AUTOMATION_DASHBOARD_URL}/executions/specs/start?repo=${repo}&branch=${branch}&build=${build}`,
headers: {
Authorization: `Bearer ${AUTOMATION_DASHBOARD_TOKEN}`,
},
method: 'post',
timeout: 10000,
data: {server},
});

return response.data;
} catch (err) {
console.log(chalk.red('Failed to get spec to test'));
if (connectionErrors.includes(err.code) || !err.response) {
console.log(chalk.red(`Error code: ${err.code}`));
return {code: err.code};
}

return err.response && err.response.data;
}
}

async function recordSpecResult(specId, spec, tests) {
try {
const response = await axios({
url: `${AUTOMATION_DASHBOARD_URL}/executions/specs/end?id=${specId}`,
headers: {
Authorization: `Bearer ${AUTOMATION_DASHBOARD_TOKEN}`,
},
method: 'post',
timeout: 10000,
data: {spec, tests},
});

console.log(chalk.green('Successfully recorded!'));
return response.data;
} catch (err) {
console.log(chalk.red('Failed to record spec result'));
if (connectionErrors.includes(err.code) || !err.response) {
console.log(chalk.red(`Error code: ${err.code}`));
return {code: err.code};
}

return err.response && err.response.data;
}
}

async function runTest(specExecution) {
async function runTest(specExecution, currentTestCount) {
const browser = 'chrome';
const headless = true;

Expand All @@ -122,7 +75,6 @@ async function runTest(specExecution) {
html: false,
json: true,
testMeta: {
platform: 'darwin',
browser,
headless,
branch: BRANCH,
Expand All @@ -132,6 +84,22 @@ async function runTest(specExecution) {
},
});

// Write and update test environment details once
if (currentTestCount === 1) {
const environment = {
cypress_version: result.cypressVersion,
browser_name: result.browserName,
browser_version: result.browserVersion,
headless,
os_name: result.osName,
os_version: result.osVersion,
node_version: process.version,
};

writeJsonToFile(environment, 'environment.json', RESULTS_DIR);
await updateCycle(specExecution.cycle_id, environment);
}

const {stats, tests, spec} = result.runs[0];

const specPatch = {
Expand Down Expand Up @@ -184,6 +152,10 @@ async function testLoop() {
return testLoop(); // eslint-disable-line consistent-return
}

if (spec.summary) {
printSummary(spec.summary);
}

if (!spec.execution || !spec.execution.file) {
console.log(chalk.magenta(spec.message));
return;
Expand All @@ -193,10 +165,9 @@ async function testLoop() {
return total + parseInt(item.count, 10);
}, 0);

printSummary(spec.summary);
console.log(chalk.magenta(`(Testing ${currentTestCount} of ${spec.cycle.specs_registered}) - `, spec.execution.file));

await runTest(spec.execution);
await runTest(spec.execution, currentTestCount);

// Reset retry count on at least one successful run
retries = 0;
Expand Down
12 changes: 6 additions & 6 deletions e2e/run_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ async function runTests() {
// Write test environment details once only
if (i === 0) {
const environment = {
cypressVersion: result.cypressVersion,
browserName: result.browserName,
browserVersion: result.browserVersion,
cypress_version: result.cypressVersion,
browser_name: result.browserName,
browser_version: result.browserVersion,
headless,
osName: result.osName,
osVersion: result.osVersion,
nodeVersion: process.version,
os_name: result.osName,
os_version: result.osVersion,
node_version: process.version,
};

writeJsonToFile(environment, 'environment.json', RESULTS_DIR);
Expand Down
9 changes: 0 additions & 9 deletions e2e/save_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
* Environment variables:
* For saving artifacts to AWS S3
* - AWS_S3_BUCKET, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
* For saving reports to Automation dashboard
* - DASHBOARD_ENABLE, DASHBOARD_ENDPOINT and DASHBOARD_TOKEN
* For saving test cases to Test Management
* - TM4J_ENABLE=true|false
* - TM4J_API_KEY=[api_key]
Expand All @@ -40,7 +38,6 @@ const {
} = require('./utils/report');
const {saveArtifacts} = require('./utils/artifacts');
const {MOCHAWESOME_REPORT_DIR, RESULTS_DIR} = require('./utils/constants');
const {saveDashboard} = require('./utils/dashboard');
const {createTestCycle, createTestExecutions} = require('./utils/test_cases');

require('dotenv').config();
Expand All @@ -50,7 +47,6 @@ const saveReport = async () => {
BRANCH,
BUILD_ID,
BUILD_TAG,
DASHBOARD_ENABLE,
DIAGNOSTIC_WEBHOOK_URL,
DIAGNOSTIC_USER_ID,
DIAGNOSTIC_TEAM_ID,
Expand Down Expand Up @@ -107,11 +103,6 @@ const saveReport = async () => {
await sendReport('test info for diagnostic analysis', DIAGNOSTIC_WEBHOOK_URL, data);
}

// Save data to automation dashboard
if (DASHBOARD_ENABLE === 'true') {
await saveDashboard(jsonReport, BRANCH);
}

// Save test cases to Test Management
if (TM4J_ENABLE === 'true') {
await createTestExecutions(jsonReport, testCycle);
Expand Down
Loading