adds mocha polyfill to clear it.each errors #3383
Merged
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.
Wherever
it.each
is called, but only ininsomnia-inso
andinsomnia-app
, we see the following error:if you dig in, you'll see that this is due to these projects importing
insomnia-testing
which uses the Mocha types. What's shown here is that TypeScript is getting the types from two places for the same global definition forit
(look at the pane on the right):so now, going back to
each
, if you hover over the error it tells you where there's a problem:Jest defines:
while Mocha defines:
So we know it's from Mocha because the error complained about
TestFunction
. Another way we know is you can just look at thejest.It
definition, and sure enough, you'll see thateach
is defined.The problem, then, is that mocha's
TestFunction
is missingeach
and since they're both merged global definitions, that isn't something TypeScript will allow. The thing is, though... we're not using Mocha. There's no way to tell TypeScript this since they're both globals.Other people seemed to solve this by making it a dev dependency (cypress-io/cypress#6690 (comment), soundcloud/intervene#3) but it already is for us, and, anyway, our situation is different because we actually need to consume and re-export these types from
insomnia-testing
so this wouldn't solve our issue.This isn't a problem for other packages in the project, e.g. o2k (see
generate.test.ts
) which do not import insomnia-testing.Therefore, I've opted to solve this by adding a fake ambient definition for
Mocha.TestFunction['each']
. This makes the errors go away and I don't think there's any real risk to us because we're not actually using mocha.That said, I'll mention @reynolek that the long-term fix for us (in my non-product-person non-decision-making opinion) is to remove mocha from all projects and just use jest and jest-runner for insomnia-testing. There are many other reasons to do this, but this hack we have to now impose is just another one to add to the pile.