From addecceeba7d9b71b5d522abe8651617b3f3ee09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Muleiro?= Date: Fri, 10 May 2024 14:47:39 -0300 Subject: [PATCH 1/4] update node_version matrix to latest --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 8511e1f0b2af778c81ef440313ddb0c8ffdd652f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Muleiro?= Date: Fri, 10 May 2024 14:48:19 -0300 Subject: [PATCH 2/4] fix reference error when wrong reporter type was passed --- src/parsers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}`; } } From 56290a441bd6a6db5d989d1e2a9fe610f0663a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Muleiro?= Date: Fri, 10 May 2024 15:04:05 -0300 Subject: [PATCH 3/4] Feature: Mochawesome parser (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 eaa50d742596cd71d77f75e4634ff723a1d112e2. * 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 --- .github/workflows/build.yml | 4 +- src/parsers/index.js | 2 +- src/parsers/mocha.js | 7 ++ tests/data/mocha/awesome/pending-tests.json | 120 ++++++++++++++++++++ tests/data/mocha/awesome/skipped-tests.json | 108 ++++++++++++------ tests/parser.mocha.spec.js | 97 +++++++++++++++- 6 files changed, 298 insertions(+), 40 deletions(-) create mode 100644 tests/data/mocha/awesome/pending-tests.json 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 From f3eff75799db1b222deb01ea10f6ca590af4db65 Mon Sep 17 00:00:00 2001 From: Anudeep Date: Sat, 11 May 2024 09:13:10 +0530 Subject: [PATCH 4/4] chore: bump version to 0.1.15 --- .github/workflows/publish.yml | 2 +- .vscode/settings.json | 5 ++++- package-lock.json | 4 ++-- package.json | 5 +++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc765cb..c39394c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ jobs: # Setup .npmrc file to publish to npm - uses: actions/setup-node@v2 with: - node-version: '14.x' + node-version: '18.x' registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm test diff --git a/.vscode/settings.json b/.vscode/settings.json index 0a10ca5..6173ae7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,5 +3,8 @@ "files.exclude": { "**/coverage": true, "**/node_modules": true - } + }, + "cSpell.words": [ + "testbeats" + ] } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 69c29c5..e223dbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "test-results-parser", - "version": "0.1.14", + "version": "0.1.15", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "test-results-parser", - "version": "0.1.14", + "version": "0.1.15", "license": "MIT", "dependencies": { "fast-xml-parser": "^4.3.2", diff --git a/package.json b/package.json index 18ba71d..7815204 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "test-results-parser", - "version": "0.1.14", + "version": "0.1.15", "description": "Parse test results from JUnit, TestNG, xUnit, cucumber and many more", "main": "src/index.js", "types": "./src/index.d.ts", @@ -23,7 +23,8 @@ "automation", "mocha", "cucumber", - "nUnit" + "nUnit", + "testbeats" ], "author": "Anudeep ", "license": "MIT",