๐ Cypress: JUnit reporter is incorrectly reported as unlisted dependency
duncan-thacker opened this issue ยท 4 comments
Prerequisites
- I'm using the latest version
- I've read the relevant documentation
- I've searched for existing issues
- I've checked the list of known issues
- I've read the issue reproduction guide
Reproduction url
https://codesandbox.io/p/sandbox/musing-gagarin-d4vvr9
Reproduction access
- I've made sure the reproduction is publicly accessible
Description of the issue
In a Cypress config, setting "reporter": "junit"
causes knip to incorrectly report junit
as an unlisted dependency. Cypress bundles a junit reporter (see https://docs.cypress.io/guides/tooling/reporters) and does not depend on the junit
package (I verified this by installing Cypress and then doing npm ls junit
). The Junit functionality appears to be somewhere inside the Cypress package.
Here is the report knip produces:
Unlisted dependencies (1)
junit cypress.config.ts
Looking at the plugin code for cypress, it appears to assume all listed reporters are package names, even though this isn't correct (not sure I've read this correctly!)
https://github.com/webpro-nl/knip/blob/main/packages/knip/src/plugins/cypress/helpers.ts
Workarounds
I can install the junit
package but that seems wasteful. I could also switch to another Junit reporter (e.g. mocha-junit-reporter
) but that also seems pointless.
Thanks for the report, @duncan-thacker!
Looking at the plugin code for cypress, it appears to assume all listed reporters are package names, even though this isn't correct (not sure I've read this correctly!)
Yeah that's where the "magic" happens. Any chance you'd be up for a pull request?
Potentially - I would probably need some help though as
- I'm not 100% confident how the code works
- It's not clear from the Cypress docs whether the
reporter
field might need resolving in some cases. I'll need to go digging through the source to figure it out. The changelogs seem to mention "mocha-junit-reporter" a lot, but it doesn't seem to be a cypress dependency, so I'm a bit confused...
If I get time I'll give this a go.
Looks like we can ignore the largest part of this file. resolveEntry
tries to resolve to package or (local) entry file (which it already does). Maybe we could just filter junit
out of the reporters? And mocha-junit-reporter
is an external package so wouldn't need special treatment I think.
Yeah, according to this page https://docs.cypress.io/guides/tooling/reporters we can also filter out teamcity