Repository navigation
Add Web Test Runner plugin - #2295
Conversation
commit: |
webpro
left a comment
There was a problem hiding this comment.
Thanks, good to have Web Test Runner covered! In Chai, for example, the config file and the dependencies it imports are no longer reported. Two things are still missing: the test files listed in the config, and test files passed after --. Details inline.
|
|
||
| const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependencies, enablers); | ||
|
|
||
| const entry = ['web-test-runner.config.{js,cjs,mjs}']; |
There was a problem hiding this comment.
The description leaves files and groups out of scope, but Web Test Runner has no default for them and errors out without either, so tests are typically listed in the config. In tab-container-element, turbo and htmx, the test files listed there are still reported as unused (1, 7 and 50 files), and so are dependencies like @open-wc/testing.
Could this become config, with a resolveFromAST that reads the top-level files and each inline groups[].files, mapped like --files including ! patterns? Please keep the read limited to those two locations: a files key inside a plugin's options would otherwise be picked up too, which can hide unused files or exclude real tests.
A non-default files pattern in the fixture, with the test asserting that file is used, would cover it.
| 'watch', | ||
| ], | ||
| resolveInputs: (parsed, { cwd }) => | ||
| [...parsed._, ...[parsed.files ?? []].flat()].map(id => { |
There was a problem hiding this comment.
Test files after --, as in wtr -- alpha.js beta.js, end up in parsed['--']. Web Test Runner runs them, but Knip reports them and their dependencies as unused:
| [...parsed._, ...[parsed.files ?? []].flat()].map(id => { | |
| [...parsed._, ...(parsed['--'] ?? []), ...[parsed.files ?? []].flat()].map(id => { |
Knip reported the test files a Web Test Runner config lists in `files` and in inline `groups[].files` as unused, and the same for files passed after `--` on the command line, which the runner executes. The plugin now parses the config with `resolveFromAST`, reading only those two locations, and maps both to entries relative to the config file. Its argument parser appends `parsed['--']`. Both keep `!` patterns. The fixture config lists one file, excludes another and names a group file, a plugin option carries a `files` key that must not count, and a script passes a file after `--`.
|
The plugin now reads the top-level The fixture covers a listed file, an excluded one, a group file, a nested key that must not count, and a script passing a file after Against turbo and htmx at their current commits, 5 and 50 test files stop being reported, with no new file or dependency findings; helpers those tests import are now reachable, so their exports get checked. |
webpro
left a comment
There was a problem hiding this comment.
Thanks, Knip now reads Web Test Runner configs and the test files they run.
|
🚀 This pull request is included in v6.45.0. See Release 6.45.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
Recognize Web Test Runner configs so their imported plugins, browser launchers and helpers are kept. On Chai's config, this removes unused reports for
@web/dev-server-rollupand@rollup/plugin-commonjs.Test files are picked up from the config too: the top-level
filesand each inlinegroups[].files,!patterns included, plus files passed after--on either binary. Afileskey inside a plugin's options is not read. On htmx, that clears 50 reported test files; on Turbo, 5 files and@open-wc/testing.The plugin follows
web-test-runner.config.{js,cjs,mjs},--configon both binaries, and explicit test paths relative to the command's working directory, includingyarn --cwd.Verified with the real runner, base/branch comparisons on public projects,
pnpm run ci, and the full Node test suite (1,681 tests).