This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
master-after-each.es6
51 lines (42 loc) · 1.59 KB
/
master-after-each.es6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pathwatcher from 'pathwatcher';
import ReactTestUtils from 'react-addons-test-utils';
import {TaskQueue} from 'nylas-exports'
// TODO the local-sync package should be moved as part of nylas-mail core,
// instead of being a separate package
import {destroyTestDatabase} from '../../internal_packages/local-sync/spec/helpers'
class MasterAfterEach {
setup(loadSettings, afterEach) {
const styleElementsToRestore = NylasEnv.styles.getSnapshot();
const self = this
afterEach(async function masterAfterEach() {
await destroyTestDatabase()
NylasEnv.packages.deactivatePackages();
NylasEnv.menu.template = [];
if (NylasEnv.state) {
delete NylasEnv.state.packageStates;
}
if (!window.debugContent) {
document.getElementById('jasmine-content').innerHTML = '';
}
ReactTestUtils.unmountAll();
jasmine.unspy(NylasEnv, 'saveSync');
self.ensureNoPathSubscriptions();
NylasEnv.styles.restoreSnapshot(styleElementsToRestore);
this.removeAllSpies();
if (TaskQueue._queue.length > 0) {
console.inspect(TaskQueue._queue)
TaskQueue._queue = []
throw new Error("Your test forgot to clean up the TaskQueue")
}
waits(0);
}); // yield to ui thread to make screen update more frequently
}
ensureNoPathSubscriptions() {
const watchedPaths = pathwatcher.getWatchedPaths();
pathwatcher.closeAllWatchers();
if (watchedPaths.length > 0) {
throw new Error(`Leaking subscriptions for paths: ${watchedPaths.join(", ")}`);
}
}
}
export default new MasterAfterEach()