Tests: delete indexeddbs after running

This commit is contained in:
Richard van der Hoff 2017-06-14 17:08:49 +01:00
parent 59da904353
commit 5ff59b0c23
2 changed files with 40 additions and 6 deletions

View file

@ -30,7 +30,7 @@ import sdk from 'matrix-react-sdk';
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
import * as languageHandler from 'matrix-react-sdk/lib/languageHandler'; import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
import test_utils from '../test-utils'; import * as test_utils from '../test-utils';
import MockHttpBackend from '../mock-request'; import MockHttpBackend from '../mock-request';
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils'; import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
@ -68,12 +68,19 @@ describe('loading:', function () {
}); });
}); });
afterEach(function() { afterEach(async function() {
if (parentDiv) { if (parentDiv) {
ReactDOM.unmountComponentAtNode(parentDiv); ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove(); parentDiv.remove();
parentDiv = null; parentDiv = null;
} }
// unmounting should have cleared the MatrixClientPeg
expect(MatrixClientPeg.get()).toBe(null);
// clear the indexeddbs so we can start from a clean slate next time.
await test_utils.deleteIndexedDB('matrix-js-sdk:crypto');
await test_utils.deleteIndexedDB('matrix-js-sdk:riot-web-sync');
}); });
/* simulate the load process done by index.js /* simulate the load process done by index.js

View file

@ -7,7 +7,7 @@ var q = require('q');
* name to stdout. * name to stdout.
* @param {Mocha.Context} context The test context * @param {Mocha.Context} context The test context
*/ */
module.exports.beforeEach = function(context) { export function beforeEach(context) {
var desc = context.currentTest.fullTitle(); var desc = context.currentTest.fullTitle();
console.log(); console.log();
console.log(desc); console.log(desc);
@ -16,13 +16,40 @@ module.exports.beforeEach = function(context) {
// some tests store things in localstorage. Improve independence of tests // some tests store things in localstorage. Improve independence of tests
// by making sure that they don't inherit any old state. // by making sure that they don't inherit any old state.
window.localStorage.clear(); window.localStorage.clear();
}; }
/** /**
* returns true if the current environment supports webrtc * returns true if the current environment supports webrtc
*/ */
module.exports.browserSupportsWebRTC = function() { export function browserSupportsWebRTC() {
var n = global.window.navigator; var n = global.window.navigator;
return n.getUserMedia || n.webkitGetUserMedia || return n.getUserMedia || n.webkitGetUserMedia ||
n.mozGetUserMedia; n.mozGetUserMedia;
}; }
export function deleteIndexedDB(dbName) {
return new q.Promise((resolve, reject) => {
if (!window.indexedDB) {
resolve();
return;
}
console.log(`Removing indexeddb instance: ${dbName}`);
const req = window.indexedDB.deleteDatabase(dbName);
req.onblocked = () => {
console.log(`can't yet delete indexeddb because it is open elsewhere`);
};
req.onerror = (ev) => {
reject(new Error(
"unable to delete indexeddb: " + ev.target.error,
));
};
req.onsuccess = () => {
console.log(`Removed indexeddb instance: ${dbName}`);
resolve();
};
});
}