newman-reporter-qase
Advanced tools
@@ -156,2 +156,41 @@ "use strict"; | ||
} | ||
}); | ||
runner.on('beforeItem', function (err, args) { | ||
var item = args.item; | ||
var name = _this.itemName(args); | ||
var ids = _this.extractIds(item.events); | ||
if (name) { | ||
_this.log('Test', name, 'starting, case ids:', ids); | ||
_this.prePending[name] = { | ||
name: name, | ||
result: src_1.ResultCreateStatusEnum.PASSED, | ||
duration: 0, | ||
ids: ids, | ||
startStamp: Date.now(), | ||
}; | ||
} | ||
}); | ||
runner.on('request', function (err, args) { | ||
var name = _this.itemName(args); | ||
if (name && _this.prePending[name]) { | ||
_this.prePending[name].response = args.response; | ||
} | ||
}); | ||
runner.on('assertion', function (err, args) { | ||
var name = _this.itemName(args); | ||
if (name && _this.prePending[name] && err) { | ||
_this.prePending[name].result = src_1.ResultCreateStatusEnum.FAILED; | ||
_this.prePending[name].err = err; | ||
} | ||
}); | ||
runner.on('item', function (err, args) { | ||
var name = _this.itemName(args); | ||
if (name && _this.prePending[name]) { | ||
var item = _this.prePending[name]; | ||
item.endStamp = Date.now(); | ||
item.duration = item.endStamp - item.startStamp; | ||
_this.logTestItem(_this.prePending[name]); | ||
} | ||
}); | ||
runner.on('beforeDone', function () { | ||
void _this.checkProject(_this.options.projectCode, function (prjExists) { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -181,3 +220,4 @@ var providedRunId; | ||
else { | ||
return [2 /*return*/, this.createRun(this.getEnv(Envs.runName) || this.options.runName, this.getEnv(Envs.runDescription) || this.options.runDescription, function (created) { | ||
return [2 /*return*/, this.createRun(this.getEnv(Envs.runName) || this.options.runName, this.getEnv(Envs.runDescription) || | ||
this.options.runDescription, function (created) { | ||
var _a; | ||
@@ -197,57 +237,19 @@ if (created) { | ||
}); | ||
}); }); | ||
}); | ||
runner.on('beforeItem', function (err, args) { | ||
var item = args.item; | ||
var name = _this.itemName(args); | ||
var ids = _this.extractIds(item.events); | ||
if (name) { | ||
_this.log('Test', name, 'starting, case ids:', ids); | ||
_this.prePending[name] = { | ||
name: name, | ||
result: src_1.ResultCreateStatusEnum.PASSED, | ||
duration: 0, | ||
ids: ids, | ||
startStamp: Date.now(), | ||
}); }).then(function () { | ||
var config = { | ||
apiToken: _this.getEnv(Envs.apiToken) || _this.options.apiToken || '', | ||
basePath: _this.getEnv(Envs.basePath) || _this.options.basePath, | ||
headers: _this.createHeaders(), | ||
code: _this.options.projectCode, | ||
runId: Number(_this.runId), | ||
body: { | ||
results: _this.createBulkResultsBodyObject(), | ||
}, | ||
}; | ||
} | ||
}); | ||
runner.on('request', function (err, args) { | ||
var name = _this.itemName(args); | ||
if (name && _this.prePending[name]) { | ||
_this.prePending[name].response = args.response; | ||
} | ||
}); | ||
runner.on('assertion', function (err, args) { | ||
var name = _this.itemName(args); | ||
if (name && _this.prePending[name] && err) { | ||
_this.prePending[name].result = src_1.ResultCreateStatusEnum.FAILED; | ||
_this.prePending[name].err = err; | ||
} | ||
}); | ||
runner.on('item', function (err, args) { | ||
var name = _this.itemName(args); | ||
if (name && _this.prePending[name]) { | ||
var item = _this.prePending[name]; | ||
item.endStamp = Date.now(); | ||
item.duration = item.endStamp - item.startStamp; | ||
_this.logTestItem(_this.prePending[name]); | ||
} | ||
}); | ||
runner.on('beforeDone', function () { | ||
var config = { | ||
apiToken: _this.getEnv(Envs.apiToken) || _this.options.apiToken || '', | ||
basePath: _this.getEnv(Envs.basePath) || _this.options.basePath, | ||
headers: _this.createHeaders(), | ||
code: _this.options.projectCode, | ||
runId: Number(_this.runId), | ||
body: { | ||
results: _this.createBulkResultsBodyObject(), | ||
}, | ||
}; | ||
child_process_1.spawnSync('node', [__dirname + "/reportBulk.js"], { | ||
stdio: 'inherit', | ||
env: Object.assign(process.env, { | ||
reporting_config: JSON.stringify(config), | ||
}), | ||
child_process_1.spawnSync('node', [__dirname + "/reportBulk.js"], { | ||
stdio: 'inherit', | ||
env: Object.assign(process.env, { | ||
reporting_config: JSON.stringify(config), | ||
}), | ||
}); | ||
}); | ||
@@ -377,16 +379,35 @@ }); | ||
NewmanQaseReporter.prototype.createBulkResultsBodyObject = function () { | ||
var _this = this; | ||
var prePandingValuesArray = Object.values(this.prePending); | ||
return prePandingValuesArray.reduce(function (accum, test) { | ||
var _a; | ||
var ids = test.ids; | ||
var testsByIdArray = ids.map(function (id) { | ||
var _a; | ||
return ({ | ||
case_id: Number(id), | ||
status: test.result, | ||
time_ms: test.duration, | ||
stacktrace: (_a = test.err) === null || _a === void 0 ? void 0 : _a.stack, | ||
comment: test.err ? test.err.message : '', | ||
if (ids && ids.length > 0) { | ||
var testsByIdArray = ids.map(function (id) { | ||
var _a; | ||
return ({ | ||
case_id: Number(id), | ||
status: test.result, | ||
time_ms: test.duration, | ||
stacktrace: (_a = test.err) === null || _a === void 0 ? void 0 : _a.stack, | ||
comment: test.err ? test.err.message : '', | ||
}); | ||
}); | ||
}); | ||
return __spreadArrays(accum, testsByIdArray); | ||
return __spreadArrays(accum, testsByIdArray); | ||
} | ||
else { | ||
var testByIdArray = [ | ||
{ | ||
case: { | ||
title: test.name, | ||
suite_title: _this.options.rootSuiteTitle || 'Autocreated Root Suite', | ||
}, | ||
status: test.result, | ||
time_ms: test.duration, | ||
stacktrace: (_a = test.err) === null || _a === void 0 ? void 0 : _a.stack, | ||
comment: test.err ? test.err.message : '', | ||
}, | ||
]; | ||
return __spreadArrays(accum, testByIdArray); | ||
} | ||
}, []); | ||
@@ -393,0 +414,0 @@ }; |
@@ -7,3 +7,3 @@ { | ||
"scripts": { | ||
"test": "newman run ./sample-collection.json -r qase --reporter-qase-logging --reporter-qase-projectCode DEMO --reporter-qase-apiToken $QASE_API_TOKEN" | ||
"test": "newman run ./sample-collection.json -r qase --reporter-qase-logging --reporter-qase-projectCode project_code --reporter-qase-apiToken api_key --reporter-qase-rootSuiteTitle 'Newman tests'" | ||
}, | ||
@@ -10,0 +10,0 @@ "keywords": [], |
{ | ||
"info": { | ||
"name": "Sample Postman Collection", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json", | ||
"description": "A sample collection to demonstrate collections as a set of related requests" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "A simple GET request", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"type": "text/javascript", | ||
"exec": [ | ||
"// qase: 1,2,3,4 ", | ||
"pm.test('expect response be 200', function () {", | ||
" pm.response.to.be.ok", | ||
"})", | ||
"pm.test('expect response json contain args', function () {", | ||
" pm.expect(pm.response.json().args).to.have.property('source')", | ||
" .and.equal('newman-sample-github-collection')", | ||
"})" | ||
] | ||
} | ||
} | ||
], | ||
"info": { | ||
"_postman_id": "549b1242-0882-4fbe-8e6e-aa77b58dceec", | ||
"name": "Example collection", | ||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", | ||
"description": "A sample collection to demonstrate collections as a set of related requests" | ||
}, | ||
"item": [ | ||
{ | ||
"name": "Example folder", | ||
"item": [ | ||
{ | ||
"name": "A simple GET request with ids", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"type": "text/javascript", | ||
"exec": [ | ||
"// qase: 222 ", | ||
"pm.test('Status code is 200', function () {", | ||
" pm.response.to.have.status(200);", | ||
"})", | ||
"pm.test('expect response json contain args', function () {", | ||
" pm.expect(pm.response.json().args).to.have.property('source')", | ||
" .and.equal('newman-sample-github-collection')", | ||
"})" | ||
] | ||
} | ||
} | ||
], | ||
"request": { | ||
"method": "GET", | ||
"header": [], | ||
"url": { | ||
"raw": "https://postman-echo.com/get?source=newman-sample-github-collection", | ||
"protocol": "https", | ||
"host": [ | ||
"postman-echo", | ||
"com" | ||
], | ||
"path": [ | ||
"get" | ||
], | ||
"query": [ | ||
{ | ||
"key": "source", | ||
"value": "newman-sample-github-collection" | ||
} | ||
] | ||
} | ||
}, | ||
"response": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "A simple GET request without ids", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"pm.test('Status code is 200', function () {", | ||
" pm.response.to.be.ok;", | ||
"})" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"url": "https://postman-echo.com/g", | ||
"method": "GET" | ||
}, | ||
"response": [] | ||
}, | ||
{ | ||
"name": "A simple GET request without ids 2", | ||
"event": [ | ||
{ | ||
"listen": "test", | ||
"script": { | ||
"exec": [ | ||
"pm.test('Response time is less than 200ms', function () {", | ||
" pm.expect(pm.response.responseTime).to.be.below(10);", | ||
"})" | ||
], | ||
"type": "text/javascript" | ||
} | ||
} | ||
], | ||
"request": { | ||
"url": "https://postman-echo.com/get?source=newman-sample-github-collection", | ||
"method": "GET" | ||
} | ||
} | ||
] | ||
}, | ||
"response": [] | ||
} | ||
] | ||
} |
{ | ||
"name": "newman-reporter-qase", | ||
"version": "v1.0.6-alpha.1", | ||
"version": "v1.0.6-alpha.2", | ||
"description": "Qase TMS Newman Reporter", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -14,2 +14,10 @@ > # Qase TMS Newman reporter | ||
### Define in tests | ||
The Newman reporter has the ability to auto-generate test cases | ||
and suites from your test data. | ||
But if necessary, you can independently register the ID of already | ||
existing test cases from TMS before the executing tests. | ||
Example: | ||
```js | ||
@@ -24,10 +32,11 @@ //qase: 10 | ||
You should also have an active item in the project settings at | ||
``` | ||
https://app.qase.io/project/QASE_PROJECT_CODE/settings/options | ||
``` | ||
option in the `Test Runs` block: | ||
options in the `Test Runs` block: | ||
``` | ||
Auto create test cases | ||
``` | ||
and | ||
``` | ||
Allow submitting results in bulk | ||
@@ -45,4 +54,5 @@ ``` | ||
--reporter-qase-basePath https://api.qase.io/v1 \ # URL Qase.io | ||
--reporter-qase-runName "API test Execution" \ # Specify Run name using CLI parameters | ||
--reporter-qase-runDescription "Check API consistency" \ # Specify Run description using CLI parameters | ||
--reporter-qase-runName 'API test Execution' \ # Specify Run name using CLI parameters | ||
--reporter-qase-runDescription 'Check API consistency' \ # Specify Run description using CLI parameters | ||
--reporter-qase-rootSuiteTitle 'Newman tests' \ # A parent suite for your autocreated tests | ||
-x # WA for issue https://github.com/postmanlabs/newman/issues/2148#issuecomment-665229759 | ||
@@ -61,4 +71,8 @@ ``` | ||
<p align="center"> | ||
<img src="./examples/screenshots/demo.gif"> | ||
</p> | ||
<!-- references --> | ||
[auth]: https://developers.qase.io/#authentication |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
7472153
501.57%13
8.33%19752
0.44%75
22.95%2
-33.33%