-
Notifications
You must be signed in to change notification settings - Fork 372
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
Upgrade to jest 22 #832
Changes from all commits
ea76fd1
55f9155
8bdb24b
eee56d1
ba5e947
5ddd883
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// @flow | ||
|
||
import type { Library } from './symbol-store'; | ||
|
||
// Used during the symbolication process to express that we couldn't find | ||
// symbols for a specific library | ||
export class SymbolsNotFoundError extends Error { | ||
library: Library; | ||
error: ?Error; | ||
|
||
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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
// @flow | ||
|
||
import { SymbolsNotFoundError } from './errors'; | ||
|
||
import type { | ||
IDBFactory, | ||
IDBDatabase, | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :/ |
||
_dbPromise: Promise<IDBDatabase> | null; | ||
_maxCount: number; | ||
_maxAge: number; // in milliseconds | ||
|
@@ -196,7 +198,10 @@ export class SymbolStoreDB { | |
updateDateReq.onsuccess = () => resolve([addrs, index, buffer]); | ||
} else { | ||
reject( | ||
new Error('The requested library does not exist in the database.') | ||
new SymbolsNotFoundError( | ||
'The requested library does not exist in the database.', | ||
{ debugName, breakpadId } | ||
) | ||
); | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ exports[`renders FlameGraph correctly 1`] = ` | |
<div | ||
className="flameGraphLabels grippy" | ||
title="thread: \\"Empty\\" (0) | ||
process: \\"default\\" (0)" | ||
process: \\"default\\" (0)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like they changed how they generate snapshot for multiline string attributes |
||
> | ||
<span> | ||
Empty | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ exports[`renders MarkerChart correctly 1`] = ` | |
<div | ||
className="markerChartLabels grippy" | ||
title="thread: \\"Empty\\" (0) | ||
process: \\"default\\" (0)" | ||
process: \\"default\\" (0)" | ||
> | ||
<span | ||
className="markerChartLabelsName" | ||
|
@@ -337,7 +337,18 @@ Array [ | |
Array [ | ||
"set fillStyle", | ||
Object { | ||
"addColorStop": [Function], | ||
"addColorStop": [MockFunction] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now Jest can serialize mock functions' calls ! |
||
"calls": Array [ | ||
Array [ | ||
0, | ||
"rgba(255, 255, 255, 0.8)", | ||
], | ||
Array [ | ||
1, | ||
"rgba(255, 255, 255, 0.0)", | ||
], | ||
], | ||
}, | ||
}, | ||
], | ||
Array [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
// @flow | ||
|
||
import sinon from 'sinon'; | ||
|
||
import { blankStore } from '../fixtures/stores'; | ||
import * as ProfileViewSelectors from '../../reducers/profile-view'; | ||
import * as UrlStateSelectors from '../../reducers/url-state'; | ||
|
@@ -18,6 +19,13 @@ import { | |
import preprocessedProfile from '../fixtures/profiles/profile-2d-canvas.json'; | ||
import getGeckoProfile from '../fixtures/profiles/gecko-profile'; | ||
|
||
// Mocking SymbolStoreDB | ||
import exampleSymbolTable from '../fixtures/example-symbol-table'; | ||
import SymbolStoreDB from '../../profile-logic/symbol-store-db'; | ||
jest.mock('../../profile-logic/symbol-store-db'); | ||
|
||
import { TextDecoder } from 'text-encoding'; | ||
|
||
describe('actions/receive-profile', function() { | ||
/** | ||
* This function allows to observe all state changes in a Redux store while | ||
|
@@ -66,13 +74,23 @@ describe('actions/receive-profile', function() { | |
getSymbolTable: () => Promise.resolve(), | ||
}; | ||
window.geckoProfilerPromise = Promise.resolve(geckoProfiler); | ||
|
||
// This is a mock implementation because of the `mock` call above, but | ||
// Flow doesn't know this. | ||
(SymbolStoreDB: any).mockImplementation(() => ({ | ||
getSymbolTable: jest.fn().mockResolvedValue(exampleSymbolTable), | ||
})); | ||
|
||
window.TextDecoder = TextDecoder; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 So I took the path of:
This proved quite a lot of work :) |
||
}); | ||
|
||
afterEach(function() { | ||
clock.restore(); | ||
|
||
geckoProfiler = null; | ||
delete window.geckoProfilerPromise; | ||
delete window.TextDecoder; | ||
delete window.requestIdleCallback; | ||
}); | ||
|
||
it('can retrieve a profile from the addon', async function() { | ||
|
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.
This is done so that we can easily use fake timers and still have requestIdleCallback works