Cypress mocha-junit-reporter - pass test filename to reporter output filename
Asked Answered
M

1

8

I'm using Cypress to run a suite of automated tests.
The current version of cypress provides mocha-junit-reporter out of the box, and provides configuration options to pass to the reporter. One of the options is the 'mochaFile'.
I'm using the recommended [hash] tag to output reports across multiple spec files.
this results in a flat mess of files that look like 'results/test-output-abc12345.xml'.

What I want instead is for the test file's relative path and filename to be pass in as the reporter's output file path.
This would give me a structured, feature first view of the output, and in Azure Dev Ops, which aggregates the test output, it would give me correct filenames to detect intermittently failing tests.

Things I've tried that haven't worked:
I've tried to use hooks to modify Cypress's config or set environment variables to try to override the reporterOptions/mochaFile per test at (hopefully) the right time.
I've tried to grab the outputted defaultly-named xml file, and copy it to the correct path+filename given the Cypress.spec.name context, but I can't seem to find the right hook or time to do this.
after and afterEach don't work - I don't think the test report has saved the file yet.

Using a plugin, hooking to some event on test:before:run or test:after:run seem promising, but I'm flying blind since I can't debug into it, so I've been unsucessful in modifying the reporter's output path or copying the file.

I'd love it if someone could show a working example using mocha-junit-reporter, or even a different mocha compatible reporter, if the reporter would play well with Azure Dev Ops, and can help me discover intermittently failing tests.

Magda answered 9/1, 2020 at 21:57 Comment(1)
Hey, you need reports per spec file specifically? Would combining them to one file satisfy you?Pointdevice
C
0

In case anyone else stumbles in here, Mocha reporter added extra placeholders a couple of years ago: https://github.com/michaelleeallen/mocha-junit-reporter/pull/163

reporterOptions: {
  mochaFile: `./results/[suiteName].xml`
},

[suiteName] will be replaced by the name of the test suite, in the filename of the generated report

Carcinoma answered 26/3 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.