Skip to content

Commit

Permalink
feature: added new parameter "autoCollectParams"
Browse files Browse the repository at this point in the history
This parameter affects the behavior of the reporter when collecting parameters.
  • Loading branch information
gibiw committed Oct 2, 2024
1 parent 5136697 commit b26ef31
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 22 deletions.
32 changes: 19 additions & 13 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 qase-newman/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# qase-newman@2.1.0
# qase-newman@2.0.2

## What's new

Expand Down
25 changes: 23 additions & 2 deletions qase-newman/docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,26 @@ When you run the tests, the following behavior is expected:

- In the **`Status code is 201`** test, both `userId` and `user.name` will be passed as parameters.
- In the **`Response has correct userId`** test, only the `userId` parameter will be passed.
- In the **`Response has correct name`** test, all relevant parameters from the data file will be passed, including
`userId`, `user.name`, and `user.age`.
- In the **`Response has correct name`** test, by default, test will not have any parameters passed. But you can enable
specific option in config file to pass all parameters from data file if test have not commented `qase.parameters`
line.

```json
{
"debug": true,
"testops": {
"api": {
"token": "api_key"
},
"project": "project_code",
"run": {
"complete": true
}
},
"framework": {
"newman": {
"autoCollectParams": true
}
}
}
```
3 changes: 2 additions & 1 deletion qase-newman/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newman-reporter-qase",
"version": "2.1.0",
"version": "2.0.2",
"description": "Qase TMS Newman Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -47,6 +47,7 @@
"@types/jest": "^29.5.2",
"@types/newman": "^5.3.6",
"@types/postman-collection": "^3.5.7",
"ajv": "^8.17.1",
"jest": "^29.5.0",
"postman-collection": "^4.1.7",
"ts-jest": "^29.1.0"
Expand Down
31 changes: 31 additions & 0 deletions qase-newman/src/configSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { JSONSchemaType } from 'ajv';

import { FrameworkOptionsType } from 'qase-javascript-commons';

import { ReporterOptionsType } from './options';

export const configSchema: JSONSchemaType<FrameworkOptionsType<'newman', ReporterOptionsType>> = {
type: 'object',
nullable: true,

properties: {
framework: {
type: 'object',
nullable: true,

properties: {
newman: {
type: 'object',
nullable: true,

properties: {
autoCollectParams: {
type: 'boolean',
nullable: true,
},
},
},
},
},
},
};
3 changes: 3 additions & 0 deletions qase-newman/src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ReporterOptionsType {
autoCollectParams?: boolean;
}
26 changes: 21 additions & 5 deletions qase-newman/src/reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventEmitter } from 'events';

import { configSchema } from './configSchema';
import semver from 'semver';
import { NewmanRunExecution, NewmanRunOptions } from 'newman';
import { EventList, PropertyBase, PropertyBaseDefinition } from 'postman-collection';
Expand Down Expand Up @@ -107,21 +108,30 @@ export class NewmanQaseReporter {
* @private
*/
private reporter: ReporterInterface;

/**
* @type {Map<string, TestResultType>}
* @private
*/
private pendingResultMap = new Map<string, TestResultType>();
private pendingResultMap: Map<string, TestResultType> = new Map<string, TestResultType>();

/**
* @type {Map<string, number>}
* @private
*/
private timerMap = new Map<string, number>();
private timerMap: Map<string, number> = new Map<string, number>();

/**
* @type {Record<string, string>[]}
* @private
*/
private parameters: Record<string, string>[] = [];
private readonly parameters: Record<string, string>[] = [];

/**
* @type {boolean}
* @private
*/
private autoCollectParams: boolean;

/**
* @param {EventEmitter} emitter
Expand All @@ -133,7 +143,7 @@ export class NewmanQaseReporter {
emitter: EventEmitter,
options: NewmanQaseOptionsType,
collectionOptions: NewmanRunOptions,
configLoader = new ConfigLoader(),
configLoader = new ConfigLoader(configSchema),
) {
const config = configLoader.load();

Expand All @@ -144,6 +154,8 @@ export class NewmanQaseReporter {
reporterName: 'newman-reporter-qase',
});

this.autoCollectParams = config?.framework?.newman?.autoCollectParams ?? false;

this.parameters = this.getParameters(collectionOptions.iterationData);
this.addRunnerListeners(emitter);
}
Expand Down Expand Up @@ -305,7 +317,11 @@ export class NewmanQaseReporter {
const params = NewmanQaseReporter.getParameters(events);

if (params.length === 0) {
return availableParameters;
if (this.autoCollectParams) {
return availableParameters;
}

return {};
}

return params.reduce<Record<string, string>>((filteredParams, param) => {
Expand Down

0 comments on commit b26ef31

Please sign in to comment.