Skip to content

Commit

Permalink
feat: fix bug (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Mar 25, 2024
1 parent f5f9a3e commit f2b291d
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 13 deletions.
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "test-results-reporter",
"version": "1.1.4",
"version": "1.1.5",
"description": "Publish test results to Microsoft Teams, Google Chat, Slack and InfluxDB",
"main": "src/index.js",
"types": "./src/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/beats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BASE_URL = process.env.TEST_BEATS_URL || "http://localhost:9393";
* @param {TestResult} result
*/
async function run(config, result) {
if (config.project && config.build && config.api_key) {
if (config.project && config.run && config.api_key) {
const run_id = await publishTestResults(config, result);
if (run_id) {
attachTestBeatsReportHyperLink(config, run_id);
Expand All @@ -25,7 +25,7 @@ async function publishTestResults(config, result) {
try {
const payload = {
project: config.project,
build: config.build,
run: config.run,
...result
}
const ci = getCIInformation();
Expand Down
4 changes: 2 additions & 2 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ export interface CustomResultOptions {
export interface PublishReport {
api_key?: string;
project?: string;
build?: string;
run?: string;
targets?: Target[];
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
}

export interface PublishConfig {
api_key?: string;
project?: string;
build?: string;
run?: string;
targets?: Target[];
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
reports?: PublishReport[];
Expand Down
5 changes: 3 additions & 2 deletions src/targets/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ function setMainBlock({ result, target, payload }) {
}

function setSuiteBlock({ result, target, payload }) {
let suite_attachments_length = 0;
if (target.inputs.include_suites) {
let texts = [];
for (let i = 0; i < result.suites.length && i < target.inputs.max_suites; i++) {
for (let i = 0; i < result.suites.length && suite_attachments_length < target.inputs.max_suites; i++) {
const suite = result.suites[i];
if (target.inputs.only_failures && suite.status !== 'FAIL') {
continue;
}
// if suites length eq to 1 then main block will include suite summary
if (result.suites.length > 1) {
texts.push(getSuiteSummary({ target, suite }));

suite_attachments_length += 1;
}
if (target.inputs.include_failure_details) {
texts.push(getFailureDetails(suite));
Expand Down
4 changes: 3 additions & 1 deletion src/targets/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,17 @@ function getResultText(result) {
}

function setSuiteBlock({ result, target, payload }) {
let suite_attachments_length = 0;
if (target.inputs.include_suites) {
for (let i = 0; i < result.suites.length && i < target.inputs.max_suites; i++) {
for (let i = 0; i < result.suites.length && suite_attachments_length < target.inputs.max_suites; i++) {
const suite = result.suites[i];
if (target.inputs.only_failures && suite.status !== 'FAIL') {
continue;
}
// if suites length eq to 1 then main block will include suite summary
if (result.suites.length > 1) {
payload.blocks.push(getSuiteSummary({ target, suite }));
suite_attachments_length += 1;
}
if (target.inputs.include_failure_details) {
// Only attach failure details block if there were failures
Expand Down
4 changes: 3 additions & 1 deletion src/targets/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ function setMainBlock({ result, target, payload }) {
}

function setSuiteBlock({ result, target, payload }) {
let suite_attachments_length = 0;
if (target.inputs.include_suites) {
for (let i = 0; i < result.suites.length && i < target.inputs.max_suites; i++) {
for (let i = 0; i < result.suites.length && suite_attachments_length < target.inputs.max_suites; i++) {
const suite = result.suites[i];
if (target.inputs.only_failures && suite.status !== 'FAIL') {
continue;
}
// if suites length eq to 1 then main block will include suite summary
if (result.suites.length > 1) {
payload.body.push(...getSuiteSummary({ suite, target }));
suite_attachments_length += 1;
}
if (target.inputs.include_failure_details) {
payload.body.push(...getFailureDetailsFactSets(suite));
Expand Down
4 changes: 2 additions & 2 deletions test/beats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('TestBeats', () => {
config: {
api_key: 'api-key',
project: 'project-name',
build: 'build-name',
run: 'build-name',
targets: [
{
name: 'teams',
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('TestBeats', () => {
config: {
api_key: 'api-key',
project: 'project-name',
build: 'build-name',
run: 'build-name',
targets: [
{
name: 'teams',
Expand Down
27 changes: 27 additions & 0 deletions test/mocks/slack.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,31 @@ addInteractionHandler('post test-summary with multiple suites and ci-info to to
status: 200
}
}
});

addInteractionHandler('post test-summary to slack with max suites as 1', () => {
return {
request: {
method: 'POST',
path: '/message',
body: {
"attachments": [
{
"color": "#DC143C",
"blocks": [
{
"@DATA:TEMPLATE@": "SLACK_ROOT_MULTIPLE_SUITES"
},
{
"@DATA:TEMPLATE@": "SLACK_SUITE_CHROME"
}
]
}
]
}
},
response: {
status: 200
}
}
});
30 changes: 30 additions & 0 deletions test/targets.slack.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,36 @@ describe('targets - slack - functional', () => {
assert.equal(mock.getInteraction(id).exercised, true);
});

it('should send test-summary using max_suites as 1', async () => {
const id = mock.addInteraction('post test-summary to slack with max suites as 1');
await publish({
config: {
"reports": [
{
"targets": [
{
"name": "slack",
"inputs": {
"url": "http://localhost:9393/message",
"max_suites": 1
}
}
],
"results": [
{
"type": "testng",
"files": [
"test/data/testng/multiple-suites.xml"
]
}
]
}
]
}
});
assert.equal(mock.getInteraction(id).exercised, true);
});

afterEach(() => {
mock.clearInteractions();
});
Expand Down

0 comments on commit f2b291d

Please sign in to comment.