Mailspring/spec/n1-spec-runner/master-after-each.es6
Halla Moore 0e5aebb91d fix(tests): Allow the masterBefore/AfterEach functions to be async
Summary:
The global `before/afterEach` functions were made async, but the
`masterBefore/AfterEach` functions were applied to the references
in `jasmineExports` instead of the global references. Fix that,
and await for `destroyTestDatabase()`. Also fix a random test
failure about not receiving any json.

This diff is necessary for D3878 to work properly.

Test Plan: ran the tests

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3890
2017-02-10 15:38:55 -08:00

51 lines
1.6 KiB
JavaScript

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()