Skip to content

fix(test-runner-mocha): move @types/mocha to dev dependency #2523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

dgp1130
Copy link
Contributor

@dgp1130 dgp1130 commented Oct 31, 2023

Having an @types/* package with global symbols like it and describe 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 on mocha to restrict the specific versions which it supports as this seems to be configurable to the user. I think users are supposed to npm install mocha @types/mocha --save-dev as I couldn't find any other non-dev dependency on mocha, 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

  1. Moved @types/mocha to devDependencies.
  2. Ran npm install to update the lockfile.
  3. This also bumped a few unrelated deps, so I reverted those changes to limit this to just the @types/mocha change.

@changeset-bot
Copy link

changeset-bot bot commented Oct 31, 2023

🦋 Changeset detected

Latest commit: 60dda46

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@web/test-runner-mocha Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Having an `@types/*` package with global symbols like `it` and `describe` forces these global types on downstream consumers which may not use them. 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](angular/angular-cli@d95bb63) for a motivating example.
Copy link
Contributor

@koddsson koddsson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good I'm not sure about the default test framework discussion but it might be good to talk about. You can open up a discussion about it here in the repo if you'd like.

@koddsson koddsson merged commit 93e4578 into modernweb-dev:master Oct 31, 2023
@dgp1130 dgp1130 deleted the mocha-types branch September 7, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants