Skip to content

Commit

Permalink
Feature: Mochawesome parser (#64)
Browse files Browse the repository at this point in the history
* set each suite's skipped tests to the sum of pending and skipped tests for the mocha parser

* Revert "set each suite's skipped tests to the sum of pending and skipped tests for the mocha parser"

This reverts commit eaa50d7.

* add mochawesome parser

* update mocha parser description

* init mochawesome parser

* update tests to consider mocha & mochawesome parsers

* mochawesome reporter that considers skipped & pending tests

* undo split into two different parsers for mocha & mochawesome

* implement new mochawesome parser test for tests marked as skipped but not pending

* rename mochawesome test files to match their purpose

* rename mochawesome pending tests test description

* undo change since 'skipped' test state does not exist

* update node_version matrix to latest

* fix reference error when wrong reporter type was passed

---------

Co-authored-by: Joaquín Muleiro <[email protected]>
  • Loading branch information
jmuleiro and psh-deploys authored May 10, 2024
1 parent aef028c commit 56290a4
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node-version: [14.x, 16.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -31,4 +31,4 @@ jobs:
- run: npm install
- run: npm run test
env:
CI: true
CI: true
2 changes: 1 addition & 1 deletion src/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function getParser(type) {
case 'cucumber':
return cucumber;
default:
throw `UnSupported Result Type - ${options.type}`;
throw `UnSupported Result Type - ${type}`;
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/parsers/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ function formatMochaJsonReport(raw_json) {
test.state = "pending";
test.duration = 0;
});
if (raw_json.hasOwnProperty('skipped')) {
raw_json.skipped.forEach(test => {
test.state = "pending";
test.duration = 0;
});
raw_json.pending.concat(raw_json.skipped);
}

const rawTests = [...raw_json.passes, ...raw_json.failures, ...raw_json.pending];
const testSuites = [...new Set(rawTests.map(test => test.fullTitle.split(' ' + test.title)[0]))];
Expand Down
120 changes: 120 additions & 0 deletions tests/data/mocha/awesome/pending-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"stats": {
"suites": 1,
"tests": 2,
"passes": 1,
"pending": 1,
"failures": 0,
"start": "2022-06-11T08:23:09.912Z",
"end": "2022-06-11T08:23:09.915Z",
"duration": 3,
"testsRegistered": 2,
"passPercent": 100,
"pendingPercent": 50,
"other": 0,
"hasOther": false,
"skipped": 0,
"hasSkipped": false
},
"results": [
{
"uuid": "a3892a10-4d6a-4729-a479-4744cfb1f025",
"title": "",
"fullFile": "",
"file": "",
"beforeHooks": [],
"afterHooks": [],
"tests": [],
"suites": [
{
"uuid": "e450ecce-78d4-4013-8f88-5fa87007b564",
"title": "Example Suite",
"fullFile": "",
"file": "",
"beforeHooks": [],
"afterHooks": [],
"tests": [
{
"title": "first sample test",
"fullTitle": "Example Suite first sample test",
"timedOut": false,
"duration": 1,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "",
"err": {},
"uuid": "5f4fc8ba-fbf0-4439-a084-4199ad46f812",
"parentUUID": "e450ecce-78d4-4013-8f88-5fa87007b564",
"isHook": false,
"skipped": false
},
{
"title": "second sample test",
"fullTitle": "Example Suite second sample test",
"timedOut": false,
"duration": 0,
"state": "pending",
"speed": null,
"pass": false,
"fail": false,
"pending": true,
"context": null,
"code": "",
"err": {},
"uuid": "9fc0d5f8-dc37-4139-b39f-9ca6e041aca3",
"parentUUID": "e450ecce-78d4-4013-8f88-5fa87007b564",
"isHook": false,
"skipped": false
}
],
"suites": [],
"passes": [
"5f4fc8ba-fbf0-4439-a084-4199ad46f812"
],
"failures": [],
"pending": [
"9fc0d5f8-dc37-4139-b39f-9ca6e041aca3"
],
"skipped": [],
"duration": 1,
"root": false,
"rootEmpty": false,
"_timeout": 2000
}
],
"passes": [],
"failures": [],
"pending": [],
"skipped": [],
"duration": 0,
"root": true,
"rootEmpty": true,
"_timeout": 2000
}
],
"meta": {
"mocha": {
"version": "10.0.0"
},
"mochawesome": {
"options": {
"quiet": false,
"reportFilename": "mochawesome",
"saveHtml": true,
"saveJson": true,
"consoleReporter": "spec",
"useInlineDiffs": false,
"code": true
},
"version": "7.1.3"
},
"marge": {
"options": null,
"version": "6.2.0"
}
}
}
108 changes: 73 additions & 35 deletions tests/data/mocha/awesome/skipped-tests.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"stats": {
"suites": 1,
"tests": 2,
"passes": 1,
"suites": 2,
"tests": 3,
"passes": 2,
"pending": 1,
"failures": 0,
"start": "2022-06-11T08:23:09.912Z",
"end": "2022-06-11T08:23:09.915Z",
"duration": 3,
"testsRegistered": 2,
"start": "2024-05-07T11:20:22.939Z",
"end": "2024-05-07T11:20:36.937Z",
"duration": 13998,
"testsRegistered": 3,
"passPercent": 100,
"pendingPercent": 50,
"pendingPercent": 33.33333333333333,
"other": 0,
"hasOther": false,
"skipped": 0,
"hasSkipped": false
"skipped": 1,
"hasSkipped": true
},
"results": [
{
"uuid": "a3892a10-4d6a-4729-a479-4744cfb1f025",
"uuid": "d24cce19-085f-4624-a944-31df51760920",
"title": "",
"fullFile": "",
"file": "",
Expand All @@ -27,60 +27,98 @@
"tests": [],
"suites": [
{
"uuid": "e450ecce-78d4-4013-8f88-5fa87007b564",
"uuid": "48b750c9-49b3-4de7-9394-60e708bb083e",
"title": "Example Suite",
"fullFile": "",
"file": "",
"beforeHooks": [],
"afterHooks": [],
"tests": [
{
"title": "first sample test",
"fullTitle": "Example Suite first sample test",
"timedOut": false,
"duration": 1,
"title": "first skipped test",
"fullTitle": "Example Suite first skipped test",
"timedOut": null,
"duration": 0,
"state": "pending",
"speed": null,
"pass": false,
"fail": false,
"pending": false,
"context": null,
"code": "",
"err": {},
"uuid": "e41e7b19-b93e-474d-8002-2ed0e440ceb9",
"parentUUID": "48b750c9-49b3-4de7-9394-60e708bb083e",
"isHook": false,
"skipped": true
}
],
"suites": [],
"passes": [],
"failures": [],
"pending": [],
"skipped": [
"e41e7b19-b93e-474d-8002-2ed0e440ceb9"
],
"duration": 0,
"root": false,
"rootEmpty": false,
"_timeout": 2000
},
{
"uuid": "14031a6a-ac0c-4f57-a78f-1a42fc515944",
"title": "Second Example Suite",
"fullFile": "",
"file": "",
"beforeHooks": [],
"afterHooks": [],
"tests": [
{
"title": "first passed test",
"fullTitle": "Second Example Suite first passed test",
"timedOut": null,
"duration": 8912,
"state": "passed",
"speed": "fast",
"speed": "medium",
"pass": true,
"fail": false,
"pending": false,
"context": null,
"code": "",
"err": {},
"uuid": "5f4fc8ba-fbf0-4439-a084-4199ad46f812",
"parentUUID": "e450ecce-78d4-4013-8f88-5fa87007b564",
"uuid": "4bcefde0-a72b-4e5b-be08-c18df00ec6fe",
"parentUUID": "14031a6a-ac0c-4f57-a78f-1a42fc515944",
"isHook": false,
"skipped": false
},
{
"title": "second sample test",
"fullTitle": "Example Suite second sample test",
"timedOut": false,
"duration": 0,
"state": "pending",
"speed": null,
"pass": false,
"title": "second passed test",
"fullTitle": "Second Example Suite second passed test",
"timedOut": null,
"duration": 4734,
"state": "passed",
"speed": "fast",
"pass": true,
"fail": false,
"pending": true,
"pending": false,
"context": null,
"code": "",
"err": {},
"uuid": "9fc0d5f8-dc37-4139-b39f-9ca6e041aca3",
"parentUUID": "e450ecce-78d4-4013-8f88-5fa87007b564",
"uuid": "da1340b1-4494-4911-8225-7b44f75f7ae5",
"parentUUID": "14031a6a-ac0c-4f57-a78f-1a42fc515944",
"isHook": false,
"skipped": false
}
],
"suites": [],
"passes": [
"5f4fc8ba-fbf0-4439-a084-4199ad46f812"
"4bcefde0-a72b-4e5b-be08-c18df00ec6fe",
"da1340b1-4494-4911-8225-7b44f75f7ae5"
],
"failures": [],
"pending": [
"9fc0d5f8-dc37-4139-b39f-9ca6e041aca3"
],
"pending": [],
"skipped": [],
"duration": 1,
"duration": 13646,
"root": false,
"rootEmpty": false,
"_timeout": 2000
Expand All @@ -98,7 +136,7 @@
],
"meta": {
"mocha": {
"version": "10.0.0"
"version": "7.0.1"
},
"mochawesome": {
"options": {
Expand Down
Loading

0 comments on commit 56290a4

Please sign in to comment.