Skip to content

Commit

Permalink
Nala base reporter CircleCi url update (#285)
Browse files Browse the repository at this point in the history
Update base-reporter.js

updated circleci link for nala test results report printout.
  • Loading branch information
amauch-adobe authored Mar 7, 2024
1 parent 2ac1492 commit 59bc4a4
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions utils/reporters/base-reporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { sendSlackMessage } from '../../libs/slack.js';

// Playwright will include ANSI color characters and regex from below
// Playwright will include ANSI color characters and regex from below
// https://github.com/microsoft/playwright/issues/13522
// https://github.com/chalk/ansi-regex/blob/main/index.js#L3

Expand All @@ -11,7 +11,7 @@ const pattern = [

const ansiRegex = new RegExp(pattern, 'g');

// limit failed status
// limit failed status
const failedStatus = ['failed', 'flaky', 'timedOut', 'interrupted'];

function stripAnsi(str) {
Expand All @@ -34,16 +34,16 @@ class BaseReporter {

}

async onTestEnd(test, result) {
const { title, retries, _projectId } = test;
async onTestEnd(test, result) {
const { title, retries, _projectId } = test;
const { name, tags, url, browser, env, branch, repo} = this.parseTestTitle(title, _projectId);
const {
status,
duration,
error: { message: errorMessage, value: errorValue, stack: errorStack } = {},
retry,
} = result;

if (retry < retries && status === 'failed') {
return;
}
Expand All @@ -52,7 +52,7 @@ class BaseReporter {
name,
tags,
url,
env,
env,
browser,
branch,
repo,
Expand Down Expand Up @@ -86,10 +86,10 @@ class BaseReporter {
} catch (error){
console.log('----Failed to publish result to slack channel----');
}
}
}
}

printResultSummary() {
printResultSummary() {
const totalTests = this.results.length;
const passPercentage = ((this.passedTests / totalTests) * 100).toFixed(2);
const failPercentage = ((this.failedTests / totalTests) * 100).toFixed(2);
Expand All @@ -99,19 +99,19 @@ class BaseReporter {
let exeEnv = 'Local Environment';
let runUrl = 'Local Environment';
let runName = 'Nala Local Run';

if (process.env.GITHUB_ACTIONS === 'true') {
exeEnv = 'GitHub Actions Environment';
const repo = process.env.GITHUB_REPOSITORY;
const runId = process.env.GITHUB_RUN_ID;
const prNumber = process.env.GITHUB_REF.split('/')[2];
runUrl = `https://github.com/${repo}/actions/runs/${runId}`;
runUrl = `https://github.com/${repo}/actions/runs/${runId}`;
runName = `${process.env.WORKFLOW_NAME ? (process.env.WORKFLOW_NAME || 'Nala Daily Run') : 'Nala PR Run'} (${prNumber})`;
} else if (process.env.CIRCLECI) {
exeEnv = 'CircleCI Environment';
const workflowId = process.env.CIRCLE_WORKFLOW_ID;
const jobNumber = process.env.CIRCLE_BUILD_NUM;
runUrl = `https://app.circleci.adobe.com/pipelines/github/wcms/nala/${jobNumber}/workflows/${workflowId}/jobs/${jobNumber}`;
runUrl = `https://app.circle.ci.adobe.com/pipelines/github/wcms/nala/${jobNumber}/workflows/${workflowId}/jobs/${jobNumber}`;
runName = 'Nala CircleCI/Stage Run';
}

Expand All @@ -124,7 +124,7 @@ class BaseReporter {
** Application URL : ${envURL}
** Executed on : ${exeEnv}
** Execution details : ${runUrl}
** Workflow name : ${runName}` ;
** Workflow name : ${runName}` ;

console.log(summary);

Expand All @@ -145,27 +145,27 @@ class BaseReporter {
/**
This method takes test title and projectId strings and then processes it .
@param {string, string} str - The input string to be processed
@returns {'name', 'tags', 'url', 'browser', 'env', 'branch' and 'repo'}
@returns {'name', 'tags', 'url', 'browser', 'env', 'branch' and 'repo'}
*/
parseTestTitle(title, projectId) {
let env = 'live';
let browser = 'chrome';
let branch;
let repo;
let url;

const titleParts = title.split('@');
const name = titleParts[1].trim();
const tags = titleParts.slice(2).map(tag => tag.trim());

const projectConfig = this.config.projects.find(project => project.name === projectId);

// Get baseURL from project config
if (projectConfig?.use?.baseURL) {
({ baseURL: url, defaultBrowserType: browser } = projectConfig.use);
} else if (this.config.baseURL) {
url = this.config.baseURL;
}
url = this.config.baseURL;
}
// Get environment from baseURL
if (url.includes('prod')) {
env = 'prod';
Expand Down

0 comments on commit 59bc4a4

Please sign in to comment.