Skip to content

Commit

Permalink
release: qase-newman 2.0.0-beta.2
Browse files Browse the repository at this point in the history
Added support suites for the Newman reporter
  • Loading branch information
gibiw committed Jun 11, 2024
1 parent 8d59ec2 commit e98e705
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 31 deletions.
11 changes: 11 additions & 0 deletions qase-newman/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# [email protected]

## What's new

Add support for suites in test results.

# [email protected]

## What's new

First major beta release for the version 2 series of the Qase Newman reporter.
2 changes: 1 addition & 1 deletion qase-newman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"author": "Parviz Khavari <[email protected]>",
"license": "Apache-2.0",
"dependencies": {
"qase-javascript-commons": "^2.0.0-beta.8",
"qase-javascript-commons": "^2.0.8",
"semver": "^7.5.1"
},
"devDependencies": {
Expand Down
72 changes: 42 additions & 30 deletions qase-newman/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
import semver from 'semver';
import { NewmanRunExecution } from 'newman';
import {
EventList,
EventList, PropertyBase, PropertyBaseDefinition,
} from 'postman-collection';
import {
ConfigType,
Expand All @@ -13,7 +13,7 @@ import {
TestResultType,
getPackageVersion,
ConfigLoader,
composeOptions,
composeOptions, Relation, SuiteData,
} from 'qase-javascript-commons';

export type NewmanQaseOptionsType = ConfigType;
Expand Down Expand Up @@ -50,28 +50,28 @@ export class NewmanQaseReporter {
return ids;
}

// /**
// * @param {PropertyBase<PropertyBaseDefinition>} item
// * @param {string[]} titles
// * @returns {string[]}
// * @private
// */
// private static getParentTitles(
// item: PropertyBase<PropertyBaseDefinition>,
// titles: string[] = [],
// ) {
// const parent = item.parent();
//
// if (parent) {
// NewmanQaseReporter.getParentTitles(parent, titles);
// }
//
// if ('name' in item) {
// titles.push(String(item.name));
// }
//
// return titles;
// }
/**
* @param {PropertyBase<PropertyBaseDefinition>} item
* @param {string[]} titles
* @returns {string[]}
* @private
*/
private static getParentTitles(
item: PropertyBase<PropertyBaseDefinition>,
) {
const titles: string[] = [];

if ('name' in item) {
titles.push(String(item.name));
}

const parent = item.parent();
if (parent) {
titles.concat(NewmanQaseReporter.getParentTitles(parent));
}

return titles;
}

/**
* @type {ReporterInterface}
Expand Down Expand Up @@ -119,14 +119,29 @@ export class NewmanQaseReporter {
*/
private addRunnerListeners(runner: EventEmitter) {
runner.on('start', () => {
void this.reporter.startTestRun();
this.reporter.startTestRun();
});

runner.on(
'beforeItem',
(_err: Error | undefined, exec: NewmanRunExecution) => {
const { item } = exec;
// const parent = item.parent();
const parent = item.parent();
const suites = parent ? NewmanQaseReporter.getParentTitles(parent) : [];
let relation: Relation | null = null;
if (suites.length > 0) {
const data: SuiteData[] = suites.map(title => {
return {
title: title,
public_id: null,
};
});
relation = {
suite: {
data: data,
},
};
}
const ids = NewmanQaseReporter.getCaseIds(item.events);
this.pendingResultMap.set(item.id, {
attachments: [],
Expand All @@ -143,14 +158,13 @@ export class NewmanQaseReporter {
message: null,
muted: false,
params: {},
relations: {},
relations: relation,
run_id: null,
signature: '',
steps: [],
testops_id: ids.length > 0 ? ids : null,
id: item.id,
title: item.name,
// suiteTitle: parent ? NewmanQaseReporter.getParentTitles(parent) : [],
});

this.timerMap.set(item.id, Date.now());
Expand Down Expand Up @@ -181,8 +195,6 @@ export class NewmanQaseReporter {

if (timer) {
const now = Date.now();
pendingResult.execution.start_time = timer;
pendingResult.execution.end_time = now;
pendingResult.execution.duration = now - timer;
}

Expand Down

0 comments on commit e98e705

Please sign in to comment.