You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to read the mochawesome json report to identify the test cases status.
When i am trying to read the file using javascript, i am not able to parse the Tests Array.
Info as below
Sample Mochawesome Report:
{
"stats": {
"suites": 0,
"tests": 3,
"passes": 3,
"pending": 0,
"failures": 0,
"start": "2021-09-21T17:52:19.461Z",
"end": "2021-09-21T17:52:19.468Z",
"duration": 7,
"testsRegistered": 3,
"passPercent": 100,
"pendingPercent": 0,
"other": 0,
"hasOther": false,
"skipped": 0,
"hasSkipped": false
},
"results": [
{
"uuid": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"title": "",
"fullFile": "",
"file": "",
"beforeHooks": [],
"afterHooks": [],
"tests": [
{
"title": "4444_should return -1 when the value is not present",
"fullTitle": "4444_should return -1 when the value is not present",
"timedOut": false,
"duration": 0,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "assert.equal([1, 2, 3].indexOf(4), -1);",
"err": {},
"uuid": "962318a6-50d1-4f66-a6b6-5b8b8428c825",
"parentUUID": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"isHook": false,
"skipped": false
},
{
"title": "5555 return -1 when the value is not present",
"fullTitle": "5555 return -1 when the value is not present",
"timedOut": false,
"duration": 0,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "assert.equal([1, 2, 3].indexOf(4), -1);",
"err": {},
"uuid": "08c82b45-0cf1-4646-aeda-4b1026fccc5e",
"parentUUID": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"isHook": false,
"skipped": false
},
{
"title": "6666_should return -1 when the value is not present",
"fullTitle": "6666_should return -1 when the value is not present",
"timedOut": false,
"duration": 0,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "assert.equal([1, 2, 3].indexOf(4), -1);",
"err": {},
"uuid": "435849c6-78ca-49b1-84bc-69b0c02027d0",
"parentUUID": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"isHook": false,
"skipped": false
}
],
"suites": [],
"passes": [
"962318a6-50d1-4f66-a6b6-5b8b8428c825",
"08c82b45-0cf1-4646-aeda-4b1026fccc5e",
"435849c6-78ca-49b1-84bc-69b0c02027d0"
],
"failures": [],
"pending": [],
"skipped": [],
"duration": 0,
"root": true,
"rootEmpty": false,
"_timeout": 2000
}
],
"meta": {
"mocha": {
"version": "9.1.1"
},
"mochawesome": {
"options": {
"quiet": false,
"reportFilename": "mochawesome",
"saveHtml": true,
"saveJson": true,
"consoleReporter": "spec",
"useInlineDiffs": false,
"code": true
},
"version": "6.2.2"
},
"marge": {
"options": null,
"version": "5.2.0"
}
}
}
Javascript code:
function publishResults()
{
var outputReport = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf8');
var rpt=JSON.parse(outputReport);
console.log(rpt);
}
Output console:
If we notice, tests property inside results array property, it is reported as '[Array]' instead of the values.
Is there anyway to get those values or am i mission something on the coding part?
The text was updated successfully, but these errors were encountered:
The tests are being parsed correctly. The issue is you are hitting a depth limit with console.log. Take a look at this related question on SO. You should be able to use one of the solutions to print the entire object.
Hi,
I am trying to read the mochawesome json report to identify the test cases status.
When i am trying to read the file using javascript, i am not able to parse the Tests Array.
Info as below
Sample Mochawesome Report:
{
"stats": {
"suites": 0,
"tests": 3,
"passes": 3,
"pending": 0,
"failures": 0,
"start": "2021-09-21T17:52:19.461Z",
"end": "2021-09-21T17:52:19.468Z",
"duration": 7,
"testsRegistered": 3,
"passPercent": 100,
"pendingPercent": 0,
"other": 0,
"hasOther": false,
"skipped": 0,
"hasSkipped": false
},
"results": [
{
"uuid": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"title": "",
"fullFile": "",
"file": "",
"beforeHooks": [],
"afterHooks": [],
"tests": [
{
"title": "4444_should return -1 when the value is not present",
"fullTitle": "4444_should return -1 when the value is not present",
"timedOut": false,
"duration": 0,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "assert.equal([1, 2, 3].indexOf(4), -1);",
"err": {},
"uuid": "962318a6-50d1-4f66-a6b6-5b8b8428c825",
"parentUUID": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"isHook": false,
"skipped": false
},
{
"title": "5555 return -1 when the value is not present",
"fullTitle": "5555 return -1 when the value is not present",
"timedOut": false,
"duration": 0,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "assert.equal([1, 2, 3].indexOf(4), -1);",
"err": {},
"uuid": "08c82b45-0cf1-4646-aeda-4b1026fccc5e",
"parentUUID": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"isHook": false,
"skipped": false
},
{
"title": "6666_should return -1 when the value is not present",
"fullTitle": "6666_should return -1 when the value is not present",
"timedOut": false,
"duration": 0,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "assert.equal([1, 2, 3].indexOf(4), -1);",
"err": {},
"uuid": "435849c6-78ca-49b1-84bc-69b0c02027d0",
"parentUUID": "e73ad4ea-2b61-4e37-94d9-a4097d9cea3c",
"isHook": false,
"skipped": false
}
],
"suites": [],
"passes": [
"962318a6-50d1-4f66-a6b6-5b8b8428c825",
"08c82b45-0cf1-4646-aeda-4b1026fccc5e",
"435849c6-78ca-49b1-84bc-69b0c02027d0"
],
"failures": [],
"pending": [],
"skipped": [],
"duration": 0,
"root": true,
"rootEmpty": false,
"_timeout": 2000
}
],
"meta": {
"mocha": {
"version": "9.1.1"
},
"mochawesome": {
"options": {
"quiet": false,
"reportFilename": "mochawesome",
"saveHtml": true,
"saveJson": true,
"consoleReporter": "spec",
"useInlineDiffs": false,
"code": true
},
"version": "6.2.2"
},
"marge": {
"options": null,
"version": "5.2.0"
}
}
}
Javascript code:
function publishResults()
{
var outputReport = fs.readFileSync('./mochawesome-report/mochawesome.json', 'utf8');
var rpt=JSON.parse(outputReport);
console.log(rpt);
}
Output console:
If we notice, tests property inside results array property, it is reported as '[Array]' instead of the values.
Is there anyway to get those values or am i mission something on the coding part?
The text was updated successfully, but these errors were encountered: