fix(test-runner-mocha): move @types/mocha
to dev dependency
#2523
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Having an
@types/*
package with global symbols likeit
anddescribe
forces these global types on downstream consumers which may not use them. TypeScript is fairly aggressive at pulling in globals from transitive dependencies, meaning that@types/mocha
is applied to application code, which can cause challenges. For example, Jasmine types overlap and conflict with Mocha types, but transitively including@types/mocha
through@web/test-runner-mocha
makes Jasmine impossible to use with Web Test Runner. See this commit for a motivating example.One potential alternative solution I did not explore here but want to state for posterity: I think it is debatable whether
@web/test-runner
should have a dependency on@web/test-runner-mocha
, given that Mocha is only one possible test framework which can be used. If a test environment is using Jasmine or any other framework it would make sense that it should not depend on@web/test-runner-mocha
yet that dependency is unavoidable here.It seemed like Mocha being the default test runner was an intentional decision so I didn't try to change that. However I wonder if the better relationship between these two packages would be an optional peer dependency in
@web/test-runner
on@web/test-runner-mocha
. Set up instructions or a script could configure this peer dependency by default, however I can understand the cost here and why it might be better to always include@web/test-runner-mocha
and accept that some users just won't invoke that code path.I suspect
@web/test-runner-mocha
also probably wants a peer dependency onmocha
to restrict the specific versions which it supports as this seems to be configurable to the user. I think users are supposed tonpm install mocha @types/mocha --save-dev
as I couldn't find any other non-dev dependency onmocha
, though the docs don't state that. I didn't try adding a peer dep in this PR to keep it simple.What I did
@types/mocha
todevDependencies
.npm install
to update the lockfile.@types/mocha
change.