Skip to content
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

Merged
merged 13 commits into from
Jun 29, 2018
Merged

tests: move cli/core to jest #5386

merged 13 commits into from
Jun 29, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented May 30, 2018

in pursuit of #5383

Before After
image image

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.

@patrickhulce patrickhulce changed the title tests: move core to jest tests: move cli/core to jest May 30, 2018
Copy link
Member

@paulirish paulirish left a 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',
],
};
Copy link
Member

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)

Copy link
Collaborator Author

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

Copy link
Member

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 = {
Copy link
Member

Choose a reason for hiding this comment

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

gotta disable eslint

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@wardpeet wardpeet Jun 3, 2018

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 */

Copy link
Collaborator Author

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 */
Copy link
Member

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

Copy link
Collaborator Author

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/\"",
Copy link
Member

Choose a reason for hiding this comment

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

looks like we want to runInBand on CI?

image
vs
image

Copy link
Collaborator Author

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?

Copy link
Collaborator Author

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 👍

@paulirish
Copy link
Member

Also this is mad cool. Excited for this. :D

@paulirish
Copy link
Member

coverage

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

@patrickhulce
Copy link
Collaborator Author

not sure what's up with the coverage freaking out 🤔

@patrickhulce
Copy link
Collaborator Author

OK I sorted out the coverage problem thanks to jestjs/jest#3190 (comment) 😃 🎉

Copy link
Member

@brendankenny brendankenny left a 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 {
Copy link
Member

Choose a reason for hiding this comment

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

why was this needed?

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator Author

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 */
Copy link
Member

Choose a reason for hiding this comment

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

delete this one?

Copy link
Collaborator Author

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",
Copy link
Member

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

Copy link
Member

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?

Copy link
Collaborator Author

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",
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

@patrickhulce
Copy link
Collaborator Author

so what's the story here, are we sold on jest? sticking with mocha? undecided? :)

@wardpeet
Copy link
Collaborator

@patrickhulce I'm not hearing any people saying no that means we can go for Jest, right? 😛

@patrickhulce
Copy link
Collaborator Author

I like the way you think @wardpeet, I'm thinking auto-merge in 48 hours if no more objections? ;)

@wardpeet
Copy link
Collaborator

They might not even notice 😄

@paulirish
Copy link
Member

The advantages that I'm jazzed about:

  • Way faster locally.
  • Display is very concise. You can see failing tests immediately, but passing tests don't scroll the view.
  • Update expectations snapshot with a keystroke sounds soooooo good.

The disadvantages that I'm bummed about:

  • A bit slower on travis.

On the whole though i think it'll be an improved experience.

@patrickhulce
Copy link
Collaborator Author

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",
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Member

@brendankenny brendankenny left a 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 {
Copy link
Member

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.

@paulirish paulirish merged commit aa43403 into master Jun 29, 2018
@paulirish paulirish deleted the jest branch June 29, 2018 01:45
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.

None yet

4 participants