diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c33c85e..136113b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -31,4 +31,4 @@ jobs: - run: npm install - run: npm run test env: - CI: true \ No newline at end of file + CI: true diff --git a/src/parsers/index.js b/src/parsers/index.js index da77cfa..802b7ce 100644 --- a/src/parsers/index.js +++ b/src/parsers/index.js @@ -48,7 +48,7 @@ function getParser(type) { case 'cucumber': return cucumber; default: - throw `UnSupported Result Type - ${options.type}`; + throw `UnSupported Result Type - ${type}`; } } diff --git a/src/parsers/mocha.js b/src/parsers/mocha.js index 01aa96f..81ede55 100644 --- a/src/parsers/mocha.js +++ b/src/parsers/mocha.js @@ -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]))]; diff --git a/tests/data/mocha/awesome/pending-tests.json b/tests/data/mocha/awesome/pending-tests.json new file mode 100644 index 0000000..5883696 --- /dev/null +++ b/tests/data/mocha/awesome/pending-tests.json @@ -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" + } + } +} \ No newline at end of file diff --git a/tests/data/mocha/awesome/skipped-tests.json b/tests/data/mocha/awesome/skipped-tests.json index 5883696..6d76c9a 100644 --- a/tests/data/mocha/awesome/skipped-tests.json +++ b/tests/data/mocha/awesome/skipped-tests.json @@ -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": "", @@ -27,7 +27,7 @@ "tests": [], "suites": [ { - "uuid": "e450ecce-78d4-4013-8f88-5fa87007b564", + "uuid": "48b750c9-49b3-4de7-9394-60e708bb083e", "title": "Example Suite", "fullFile": "", "file": "", @@ -35,52 +35,90 @@ "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 @@ -98,7 +136,7 @@ ], "meta": { "mocha": { - "version": "10.0.0" + "version": "7.0.1" }, "mochawesome": { "options": { diff --git a/tests/parser.mocha.spec.js b/tests/parser.mocha.spec.js index 3ca96e2..aa30846 100644 --- a/tests/parser.mocha.spec.js +++ b/tests/parser.mocha.spec.js @@ -333,8 +333,8 @@ describe('Parser - Mocha Awesome Json', () => { }); }); - it('suite with skipped tests', () => { - const result = parse({ type: 'mocha', files: [`${testDataPath}/skipped-tests.json`] }); + it('suite with pending tests', () => { + const result = parse({ type: 'mocha', files: [`${testDataPath}/pending-tests.json`] }); assert.deepEqual(result, { id: '', name: '', @@ -594,4 +594,97 @@ describe('Parser - Mocha Awesome Json', () => { assert.notEqual(null, result2); }); + it('supports skipped tests', () => { + const result = parse({ type: 'mocha', files: [`${testDataPath}/skipped-tests.json`] }); + assert.deepEqual(result, { + duration: 13998, + errors: 0, + failed: 0, + id: "", + name: "", + passed: 2, + retried: 0, + skipped: 1, + status: "PASS", + total: 3, + suites: [ + { + cases: [ + { + attachments: [], + duration: 0, + errors: 0, + failed: 0, + failure: "", + id: "", + meta_data: new Map(), + name: "first skipped test", + passed: 0, + skipped: 0, + stack_trace: "", + status: "SKIP", + steps: [], + total: 0 + } + ], + duration: 0, + errors: 0, + failed: 0, + id: "", + meta_data: new Map(), + name: "Example Suite", + passed: 0, + skipped: 0, + status: "FAIL", + total: 1 + }, + { + cases: [ + { + attachments: [], + duration: 8912, + errors: 0, + failed: 0, + failure: "", + id: "", + meta_data: new Map(), + name: "first passed test", + passed: 0, + skipped: 0, + stack_trace: "", + status: "PASS", + steps: [], + total: 0 + }, + { + attachments: [], + duration: 4734, + errors: 0, + failed: 0, + failure: "", + id: "", + meta_data: new Map(), + name: "second passed test", + passed: 0, + skipped: 0, + stack_trace: "", + status: "PASS", + steps: [], + total: 0 + } + ], + duration: 13646, + errors: 0, + failed: 0, + id: "", + meta_data: new Map(), + name: "Second Example Suite", + passed: 2, + skipped: 0, + status: "PASS", + total: 2 + } + ], + }); + }); }); \ No newline at end of file