(Note this issue was split from #1821.)
I would like to implement my own local reporter as a script for a project. This would not be an npm package, just a local script. The --reporter documentation suggest this is possible: "To load a reporter from a local Node.js script, use --require instead." I can't get this working, and I've also tried adding my script to the to QUnit.config.reporters array, and just writing a function directly into the reporters object, but that didn't work (and seemed wrong anyway).
I did eventually get this working using the --reporter CLI option:
qunit --reporter /home/jakerella/my-project/test/reporter.cjs test/my-tests.cjs
Or I can navigate out of the qunit directory structure inside /node_modules: ../../../../test/reporter.cjs (ew)
This is because the require in find-reporter doesn't take into account the current working directory of the run. This is sort of okay, except that I want other people to be able to run the tests, so I'd have to document how to do this really well. I don't see a great way around this right now because I can't specify the "reporter" using QUnit.config or add my own reporter to the "reporters" built-in object.
I think there are a couple possibilities here:
- Add a "reporter" option to
QUnit.config for specifying a custom (local) reporter
- Detecting a custom reporter via a path prefix like
./ or ../ and then using path.resolve() inside find-reporter so that the file can be required using a relative path on the command line.
- Allowing the developer to add a reporter to the
reporters object and maybe using the filename as the key?
Let me know if any of these is of interest and I can probably submit a PR for it.
(Note this issue was split from #1821.)
I would like to implement my own local reporter as a script for a project. This would not be an npm package, just a local script. The --reporter documentation suggest this is possible: "To load a reporter from a local Node.js script, use --require instead." I can't get this working, and I've also tried adding my script to the to
QUnit.config.reportersarray, and just writing a function directly into thereportersobject, but that didn't work (and seemed wrong anyway).I did eventually get this working using the
--reporterCLI option:Or I can navigate out of the qunit directory structure inside
/node_modules:../../../../test/reporter.cjs(ew)This is because the
requirein find-reporter doesn't take into account the current working directory of the run. This is sort of okay, except that I want other people to be able to run the tests, so I'd have to document how to do this really well. I don't see a great way around this right now because I can't specify the "reporter" using QUnit.config or add my own reporter to the "reporters" built-in object.I think there are a couple possibilities here:
QUnit.configfor specifying a custom (local) reporter./or../and then usingpath.resolve()inside find-reporter so that the file can be required using a relative path on the command line.reportersobject and maybe using the filename as the key?Let me know if any of these is of interest and I can probably submit a PR for it.