-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: move cli/core to jest #5386
Conversation
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.
What happens to coverage? (Apparently jest can collect on its own. But regardless we should probably do that later)
I don't think --watch
works correctly on our project. It doesn't associate related files, it seems.
'**/lighthouse-core/**/*-test.js', | ||
'**/lighthouse-cli/**/*-test.js', | ||
], | ||
}; |
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.
let's set the timeout to 2000ms, since that's what we use in mocha. (otherwise it'll default to 5000ms)
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.
how important is this one? do we think 2s was a good feature? :)
in jest you do this via jest.setTimeout
which requires a bootstrap file, and AFAICT cannot be done through config https://facebook.github.io/jest/docs/en/configuration.html
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.
oic. hmmmmmmmm well nevermind then.
@@ -0,0 +1,7 @@ | |||
module.exports = { |
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 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.
done
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.
we could go for /* eslint-env jest */
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.
ya @wardpeet I made that change 👍 :)
@@ -27,7 +27,7 @@ function assertTraceEventsEqual(traceEventsA, traceEventsB) { | |||
/* eslint-env mocha */ |
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.
gotta replace all these with eslint-env jeset
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.
done
package.json
Outdated
|
||
"unit-core": "mocha --reporter dot \"lighthouse-core/test/**/*-test.js\"", | ||
"unit-cli": "mocha --reporter dot \"lighthouse-cli/test/**/*-test.js\"", | ||
"unit-core": "jest \"lighthouse-core/\"", |
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 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.
yeah not sure how we should do this one, since we reuse lots of commands, suggestions?
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 just went with a :ci
copy of unit-core
👍
Also this is mad cool. Excited for this. :D |
for whatever reason this appears to drop our coverage % down quite a bit. not sure what's happening, though. https://codecov.io/gh/GoogleChrome/lighthouse/pull/5386 |
not sure what's up with the coverage freaking out 🤔 |
OK I sorted out the coverage problem thanks to jestjs/jest#3190 (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.
I wasn't there for the conversation, so what's the advantage here in changing?
It's a pretty transparent change so the code side doesn't seem to matter much, but it does seem significantly slower in CI, at least
hostname: parsedUrl.hostname, | ||
origin: parsedUrl.origin, | ||
}; | ||
try { |
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.
why was this needed?
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.
well we only need this or a fix on the _renderTextURL
to be looser on its try/catch (we check instanceof TypeError), but it seemed like a good catch on passing invalid URLs to parseURL
. We pass through several 'Unknown'
strings to this function which throw
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.
hmm, but why was it needed for this PR? If it's throwing shouldn't it have caused a failure before, too? Or is the problem something else.
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.
well again it isn't strictly needed, but seemed like a good idea anyhow.
full details:
in jest's jsdom env, the URL class throws an error that isn't instanceof TypeError
_renderTextURL
which normally catches TypeErrors thrown by this method was then throwing
this isn't needed anymore because along the way I turned off default jsdom environment, but it seemed like a good idea to keep, it seems like you don't think so though so I'll revert :)
@@ -28,7 +28,7 @@ function noUrlManifestParser(manifestSrc) { | |||
return manifestParser(manifestSrc, EXAMPLE_MANIFEST_URL, EXAMPLE_DOC_URL); | |||
} | |||
|
|||
/* eslint-env mocha */ | |||
/* eslint-env jest */ |
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.
delete this one?
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.
done
package.json
Outdated
"coverage": "nyc yarn unit && nyc report --reporter html", | ||
"smoke:silentcoverage": "nyc --silent yarn smoke && nyc report --reporter text-lcov > smoke-coverage.lcov", | ||
"coverage:smoke": "nyc yarn smoke && nyc report --reporter html", | ||
"unit:silentcoverage": "nyc --silent --clean yarn unit:ci && nyc report --reporter text-lcov > unit-coverage.lcov", |
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.
one unfortunate side of this (at least judging from that comment in the jest issue) is that subprocesses don't automatically collect coverage. I don't believe we do that in any unit tests, but it is a handy thing to lose
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.
since jest automatically collects coverage with --coverage
, are the lcov files written anywhere so we drop the nyc
calls (for non-smoke tests) altogether?
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.
if we use jest everywhere we won't need nyc for the unit tests at all and we can use the lcov/html files they generate in ./coverage
right now, jest coverage output is just disabled and it lets nyc collect/combine everything since we still need it for the mocha cases
package.json
Outdated
"unit:silentcoverage": "nyc --silent --clean yarn unit:ci && nyc report --reporter text-lcov > unit-coverage.lcov", | ||
"coverage": "nyc --clean yarn unit:ci && nyc report --reporter html", | ||
"smoke:silentcoverage": "nyc --silent --clean yarn smoke && nyc report --reporter text-lcov > smoke-coverage.lcov", | ||
"coverage:smoke": "nyc --clean yarn smoke && nyc report --reporter html", |
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.
FWIW I believe --clean
is the 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.
removed
so what's the story here, are we sold on jest? sticking with mocha? undecided? :) |
@patrickhulce I'm not hearing any people saying no that means we can go for Jest, right? 😛 |
I like the way you think @wardpeet, I'm thinking auto-merge in 48 hours if no more objections? ;) |
They might not even notice 😄 |
The advantages that I'm jazzed about:
The disadvantages that I'm bummed about:
On the whole though i think it'll be an improved experience. |
Alright merge conflicts fixed! @paulirish do you still have requested changes? |
package.json
Outdated
@@ -93,6 +96,7 @@ | |||
"gulp": "^3.9.1", | |||
"gulp-replace": "^0.5.4", | |||
"gulp-util": "^3.0.7", | |||
"jest": "^23.0.1", |
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.
can now use 23.2.0
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.
done
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 still don't see what's "mad cool" about this, but I guess we'll see eventually? :)
Ideally we can get rid of nyc and mocha in the future so we don't have to maintain all three.
hostname: parsedUrl.hostname, | ||
origin: parsedUrl.origin, | ||
}; | ||
try { |
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.
hmm, but why was it needed for this PR? If it's throwing shouldn't it have caused a failure before, too? Or is the problem something else.
in pursuit of #5383
only real code changes are before -> beforeAll, after -> afterAll, and moving .timeout
lots of noise from
eslint-env mocha
though :/it also caught a bug that's not clear at all how the mocha tests were passing in CLI case where requiring in the yargs getFlags invokes process.exit (!!!!!). there's another psuedobug where we pass in 'Unknown' strings to our parseURL function which can throw
I'm not using jest's built-in expectations/coverage/anything yet to keep the diff small and easily revertable if folks don't like it.