Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parsing 0 ms duration #49

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: 13 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
},
"homepage": "https://test-results-reporter.github.io",
"dependencies": {
"colon-notation": "^1.2.1",
"dotenv": "^14.3.0",
"phin-retry": "^1.0.3",
"pretty-ms": "^7.0.0",
"rosters": "0.0.1",
"sade": "^1.7.4",
"test-results-parser": "^0.0.11"
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const DATA_REF_PATTERN = /(\{[^\}]+\})/g;
const pretty_ms = require('pretty-ms');

function getPercentage(x, y) {
if (y > 0) {
Expand Down Expand Up @@ -47,8 +48,13 @@ function truncate(text, length) {
}
}

function getPrettyDuration(ms, format) {
return pretty_ms(parseInt(ms), { [format]: true, secondsDecimalDigits: 0 })
}

module.exports = {
getPercentage,
processData,
truncate,
getPrettyDuration
}
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface SlackInputs {
only_failures?: boolean;
title?: string;
title_suffix?: string;
duration?: string;
}

export interface TeamsInputs {
Expand All @@ -72,6 +73,7 @@ export interface TeamsInputs {
title?: string;
title_suffix?: string;
width?: string;
duration?: string;
}

export interface Target {
Expand Down
29 changes: 6 additions & 23 deletions src/targets/slack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const request = require('phin-retry');
const { getPercentage, truncate } = require('../helpers/helper');
const { toColonNotation } = require('colon-notation');
const { getPercentage, truncate, getPrettyDuration } = require('../helpers/helper');
const extension_manager = require('../extensions');
const { HOOK } = require('../helpers/constants');

Expand Down Expand Up @@ -44,7 +43,7 @@ function getMainPayload() {
function setMainBlock({ result, target, payload }) {
let text = `*${getTitleText(result, target)}*\n`;
text += `\n*Results*: ${getResultText(result)}`;
text += `\n*Duration*: ${getDurationText(result)}`;
text += `\n*Duration*: ${getPrettyDuration(result.duration, target.inputs.duration)}`;
payload.blocks.push({
"type": "section",
"text": {
Expand All @@ -67,10 +66,6 @@ function getResultText(result) {
return `${result.passed} / ${result.total} Passed (${percentage}%)`;
}

function getDurationText(result) {
return `${toColonNotation(parseInt(result.duration))}`;
}

function setSuiteBlock({ result, target, payload }) {
if (target.inputs.include_suites) {
for (let i = 0; i < result.suites.length; i++) {
Expand All @@ -80,7 +75,7 @@ function setSuiteBlock({ result, target, payload }) {
}
// if suites length eq to 1 then main block will include suite summary
if (result.suites.length > 1) {
payload.blocks.push(getSuiteSummary(suite));
payload.blocks.push(getSuiteSummary({ target, suite }));
}
if (target.inputs.include_failure_details) {
payload.blocks.push(getFailureDetails(suite));
Expand All @@ -89,23 +84,10 @@ function setSuiteBlock({ result, target, payload }) {
}
}

function getSuiteSummary(suite) {
let text = `*${getSuiteTitle(suite)}*\n`;
text += `\n*Results*: ${getResultText(suite)}`;
text += `\n*Duration*: ${getDurationText(suite)}`;
return {
"type": "section",
"text": {
"type": "mrkdwn",
"text": text
}
};
}

function getSuiteSummary(suite) {
function getSuiteSummary({ target, suite }) {
let text = `*${getSuiteTitle(suite)}*\n`;
text += `\n*Results*: ${getResultText(suite)}`;
text += `\n*Duration*: ${getDurationText(suite)}`;
text += `\n*Duration*: ${getPrettyDuration(suite.duration, target.inputs.duration )}`;
return {
"type": "section",
"text": {
Expand Down Expand Up @@ -167,6 +149,7 @@ const default_inputs = {
include_suites: true,
only_failure_suites: false,
include_failure_details: false,
duration: 'colonNotation'
}

module.exports = {
Expand Down
18 changes: 9 additions & 9 deletions src/targets/teams.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const request = require('phin-retry');
const { toColonNotation } = require('colon-notation');
const { getPercentage, truncate } = require('../helpers/helper');
const { getPercentage, truncate, getPrettyDuration } = require('../helpers/helper');
const extension_manager = require('../extensions');
const { HOOK } = require('../helpers/constants');

Expand All @@ -10,7 +9,7 @@ async function run({result, target}) {
const payload = getMainPayload(target);
await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.START });
setTitleBlock(result, { target, payload });
setMainBlock(result, { target, payload });
setMainBlock({ result, target, payload });
await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.POST_MAIN });
setSuiteBlock(result, { target, payload });
await extension_manager.run({ result, target, payload, root_payload, hook: HOOK.END });
Expand Down Expand Up @@ -76,7 +75,7 @@ function setTitleBlock(result, { target, payload }) {
});
}

function setMainBlock(result, { payload }) {
function setMainBlock({ result, target, payload }) {
const facts = [];
const percentage = getPercentage(result.passed, result.total);
facts.push({
Expand All @@ -85,7 +84,7 @@ function setMainBlock(result, { payload }) {
});
facts.push({
"title": "Duration:",
"value": `${toColonNotation(parseInt(result.duration))}`
"value": `${getPrettyDuration(result.duration, target.inputs.duration)}`
});
payload.body.push({
"type": "FactSet",
Expand All @@ -102,7 +101,7 @@ function setSuiteBlock(result, { target, payload }) {
}
// if suites length eq to 1 then main block will include suite summary
if (result.suites.length > 1) {
payload.body.push(...getSuiteSummary(suite));
payload.body.push(...getSuiteSummary({ suite, target }));
}
if (target.inputs.include_failure_details) {
payload.body.push(...getFailureDetailsFactSets(suite));
Expand All @@ -111,7 +110,7 @@ function setSuiteBlock(result, { target, payload }) {
}
}

function getSuiteSummary(suite) {
function getSuiteSummary({ suite, target }) {
const percentage = getPercentage(suite.passed, suite.total);
const emoji = suite.status === 'PASS' ? '✅' : '❌';
return [
Expand All @@ -131,7 +130,7 @@ function getSuiteSummary(suite) {
},
{
"title": "Duration:",
"value": `${toColonNotation(parseInt(suite.duration))}`
"value": `${getPrettyDuration(suite.duration, target.inputs.duration)}`
}
]
}
Expand Down Expand Up @@ -187,7 +186,8 @@ const default_inputs = {
include_suites: true,
only_failure_suites: false,
include_failure_details: false,
width: ""
width: '',
duration: 'colonNotation'
}

module.exports = {
Expand Down
26 changes: 13 additions & 13 deletions test/mocks/slack.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ addInteractionHandler('post test-summary to slack', () => {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 0:02"
}
}
]
Expand Down Expand Up @@ -49,14 +49,14 @@ addInteractionHandler('post test-summary to slack with multiple suites', () => {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 03:22"
"text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 3:22"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 09:05"
"text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 9:05"
}
}
]
Expand Down Expand Up @@ -119,7 +119,7 @@ addInteractionHandler('post failure-details to slack with multiple suites', () =
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 03:22"
"text": "*❌ desktop-chrome*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 3:22"
}
},
{
Expand All @@ -133,7 +133,7 @@ addInteractionHandler('post failure-details to slack with multiple suites', () =
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 09:05"
"text": "*❌ mobile-ios*\n\n*Results*: 2 / 5 Passed (40%)\n*Duration*: 9:05"
}
},
{
Expand Down Expand Up @@ -168,7 +168,7 @@ addInteractionHandler('post failure-details to slack with single suite', () => {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
}
},
{
Expand Down Expand Up @@ -203,7 +203,7 @@ addInteractionHandler('post test-summary with hyperlinks to slack - pass status'
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 4 / 4 Passed (100%)\n*Duration*: 0:02"
}
},
{
Expand Down Expand Up @@ -240,7 +240,7 @@ addInteractionHandler('post test-summary with hyperlinks to slack - fail status'
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
}
},
{
Expand Down Expand Up @@ -277,7 +277,7 @@ addInteractionHandler('post test-summary to slack with report portal analysis',
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
}
},
{
Expand Down Expand Up @@ -312,7 +312,7 @@ addInteractionHandler('post test-summary to slack with report portal analysis wi
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
}
},
{
Expand Down Expand Up @@ -350,7 +350,7 @@ addInteractionHandler('post test-summary with mentions to slack', () => {
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
}
},
{
Expand Down Expand Up @@ -385,7 +385,7 @@ addInteractionHandler('post test-summary to slack with qc-test-summary', (ctx) =
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
},
"accessory": {
"type": "image",
Expand Down Expand Up @@ -418,7 +418,7 @@ addInteractionHandler('post test-summary to slack with report portal history', (
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 00:02"
"text": "*Default suite*\n\n*Results*: 3 / 4 Passed (75%)\n*Duration*: 0:02"
}
},
{
Expand Down
Loading