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

Upgrade to jest 22 #832

Merged
merged 6 commits into from Mar 7, 2018
Merged

Conversation

julienw
Copy link
Contributor

@julienw julienw commented Mar 6, 2018

No description provided.

.babelrc Outdated
[
"transform-class-properties"
"transform-builtin-extend",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed so that "XXX instanceof SubclassedError" works... Once we stop transpiling classes we can also remove this...

@@ -83,6 +83,9 @@ let requestIdleCallbackPolyfill: (

if (typeof window === 'object' && window.requestIdleCallback) {
requestIdleCallbackPolyfill = window.requestIdleCallback;
} else if (typeof process === 'object' && process.nextTick) {
// Node environment
requestIdleCallbackPolyfill = process.nextTick;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done so that we can easily use fake timers and still have requestIdleCallback works

@@ -38,7 +40,7 @@ const kTwoWeeksInMilliseconds = 2 * 7 * 24 * 60 * 60 * 1000;
* @class SymbolStoreDB
* @classdesc Where does this description show up?
*/
export class SymbolStoreDB {
export default class SymbolStoreDB {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done so that I could mock it with jest... I couldn't find how to do with a named export :/

@@ -69,7 +69,7 @@ exports[`renders FlameGraph correctly 1`] = `
<div
className="flameGraphLabels grippy"
title="thread: \\"Empty\\" (0)
process: \\"default\\" (0)"
process: \\"default\\" (0)"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like they changed how they generate snapshot for multiline string attributes

@@ -337,7 +337,18 @@ Array [
Array [
"set fillStyle",
Object {
"addColorStop": [Function],
"addColorStop": [MockFunction] {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now Jest can serialize mock functions' calls !

getSymbolTable: jest.fn().mockResolvedValue(exampleSymbolTable),
}));

window.TextDecoder = TextDecoder;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Various issues here, coming from the fact that we don't have indexedDB in this test file, and so SymbolStoreDB was broken. The errors weren't transmitted back to the test, but because in SymbolStore._getSymbolTable we're storing stuff in the database but not waiting for it in the promise, the errors were "leaking" in other tests.

So I took the path of:

  1. Throwing back unexpected errors to the top level calls, failing the right tests
  2. Fixing the tests by mocking SymbolStoreDB itself, making it returning a proper value so that we don't try to store data, etc. We don't need this in this test.

This proved quite a lot of work :)

): JestMockFn<TArguments, TReturn>,
mockResolvedValueOnce(
value: ExtractPromiseValue<TReturn>
): JestMockFn<TArguments, TReturn>,
Copy link
Contributor Author

@julienw julienw Mar 6, 2018

Choose a reason for hiding this comment

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

This is the important stuff.
This is not working as expected really, but enough for this PR I think. I fired a PR at flow-typed: flow-typed/flow-typed#1918, see comments there

// flow-typed signature: d5b32a3045854623325a334220fbc654
// flow-typed version: c7c67b81c1/jest_v20.x.x/flow_>=v0.39.x
// flow-typed signature: 18018da6c1a1d95b4ab1c64bb5fe86ca
// flow-typed version: c1ad61e7d4/jest_v22.x.x/flow_>=v0.39.x
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Too much changes in this file because of prettier, I'll revert most of the changes before landing...

@julienw julienw requested a review from mstange March 6, 2018 17:58
@codecov
Copy link

codecov bot commented Mar 6, 2018

Codecov Report

Merging #832 into master will increase coverage by 0.46%.
The diff coverage is 64.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #832      +/-   ##
==========================================
+ Coverage   66.92%   67.38%   +0.46%     
==========================================
  Files         127      128       +1     
  Lines        7344     5817    -1527     
  Branches     1670      884     -786     
==========================================
- Hits         4915     3920     -995     
+ Misses       2133     1632     -501     
+ Partials      296      265      -31
Impacted Files Coverage Δ
src/profile-logic/symbol-store-db.js 87.23% <ø> (-0.84%) ⬇️
src/profile-logic/symbolication.js 91.76% <0%> (-3.09%) ⬇️
src/profile-logic/symbol-store-db-worker.js 0% <0%> (ø) ⬆️
src/profile-logic/errors.js 100% <100%> (ø)
src/utils/errors.js 100% <100%> (ø) ⬆️
src/actions/receive-profile.js 63.46% <100%> (-9.13%) ⬇️
src/profile-logic/symbol-store.js 80% <33.33%> (-0.49%) ⬇️
src/utils/flow.js 56.25% <0%> (-15.98%) ⬇️
src/utils/dom-rect.js 0% <0%> (-10%) ⬇️
... and 115 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 31228a1...5ddd883. Read the comment docs.

Copy link
Contributor

@mstange mstange left a comment

Choose a reason for hiding this comment

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

Thanks for the explanations. I don't know very much about all this, but what you say makes sense and the changes look non-controversial.

@jasonLaster
Copy link
Contributor

Nice @julienw

@mstange
Copy link
Contributor

mstange commented Mar 6, 2018

There are some test failures.

@julienw
Copy link
Contributor Author

julienw commented Mar 7, 2018

This is weird, these test failures look like something I fixed...

@julienw
Copy link
Contributor Author

julienw commented Mar 7, 2018

Ah, this is fun, the error happens only with --coverage.

Especially this introduces a specialized Error for symbolication, so
that we can distinguish errors and more easily debug tests by rethrowing
unexpected errors.
@julienw
Copy link
Contributor Author

julienw commented Mar 7, 2018

My theory is that when collecting coverage some more instrumentation is added to the files and as a result the babel transform doesn't work anymore.

I removed the transforms, and instead I manually added a line to the constructor:

   constructor(message: string, library: Library, error?: Error) {
     super(message);
    // Workaround for a babel issue when extending Errors
    (this: any).__proto__ = SymbolsNotFoundError.prototype;
     this.name = 'SymbolsNotFoundError';
     this.library = library;
     this.error = error;
   }

Other alternatives:

  • compare the property name instead of using instanceof
  • do not subclass Error but just call the Error.call(this, message) in the constructor (we should check if this captures the stack properly)

@julienw julienw merged commit 0161ae4 into firefox-devtools:master Mar 7, 2018
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

3 participants