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.
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
tests: start replacing jest with mocha, starting with unit-cli #13568
tests: start replacing jest with mocha, starting with unit-cli #13568
Changes from 17 commits
e15d486
b57b6d6
5f1f6be
2bd3231
f92351a
e10c0ac
2f7f891
c4d591b
d4d4830
5b2b8b0
5b03510
b553be9
e7eb722
8f8eaea
b084502
939e1d0
dbb8e60
2b3e56b
4f96ce4
d00d94a
071ae8e
b311566
71198a5
0cebb33
7f0a250
1092625
9bea135
7e3912d
e4d3a62
b3c9ecf
39eef45
4cff085
8eedc78
6656a0b
74336c5
c8c69a0
b497806
8ab1d52
bc1c959
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eslint-env mocha now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with jest
import yargs from 'yargs
here and in the test file results inyargs.getGroups()
working in the test file. That function is added to the module dynamically after being called, which is why this test did this seemingly no-op call togetFlags
.But, that property is only added to the module object in jest because ... reasons? The modules aren't really es modules, I guess, and es module objects are read-only, IIRC.
Anyhow, the
getGroups
method is also added to the yargs parser object, so to get to that I split up the implementation across two functions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no timeout parameter for mocha hook functions, but there is for jest lifecycle functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mocha does
global.before
, jest doesglobal.beforeAll
. To make transition slightly easier, I thought having the same interface for some parts would be helpful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some type collisions here inside node_modules (across globals declared by jest and mocha) that I need help dealing with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
patch-package could work, just deleting the lines that declare the global vars in mocha (and relying on the mocha-setup to coerce the jest-defined interface and use the mocha functions there)
I think this is unavoidable, unless we make the switch to mocha in one giant PR.
cypress-io/cypress#6690 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the problem that we have jest and mocha tests in the same namespace? We could use project references to split cli unit tests up in that case. Or is using jest-mock/snapshots/expect enough to clash with the mocha types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both do toplevel
declare var
, so the global namespace.I don't see how project references would resolve it–rather, I don't know enough about using projects in TS to know how it'd solve things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const {describe, it} = require('mocha')
works (though the globals still exist), so we could also convert to using actual imports rather than the terrible global thing all these test runners do. This person apparently keeps a fork of@types/mocha
but with only local declarations: mochajs/mocha#956 (comment) 🤷But it might just be easier to use project references.
Really they wouldn't even be project references here, it would just be a different tsconfig which doesn't include the jest types (or the mocha types, depending on where we put it). This is the same as e.g. the treemap tsconfig, where we only include the
tabulator-tables
types fromnode_modules
, and exclude all the other types (like we don't want any of the@types/node
globals muddying up code suggestions in code that's only going to run in the browser):lighthouse/treemap/tsconfig.json
Lines 8 to 9 in 82772f9
FWIW projects references are just that, multiple tsconfigs, with the addition of the
references
section where one tsconfig can reference another as a type dependency, e.g. treemap pulling in'../report/'
as a dependency in the exact same way it's pulling intabulator-tables
as one. It's much more analogous to our multiple eslintrc files than yarn/npm workspaces or lerna or whatever.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run into complications with this approach because referencing files outside of a tsconfig project is not allowed.