Skip to content

Commit 5ff59b0

Browse files
committed
Tests: delete indexeddbs after running
1 parent 59da904 commit 5ff59b0

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

‎test/app-tests/loading.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import sdk from 'matrix-react-sdk';
3030
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
3131
import * as languageHandler from 'matrix-react-sdk/lib/languageHandler';
3232

33-
import test_utils from '../test-utils';
33+
import * as test_utils from '../test-utils';
3434
import MockHttpBackend from '../mock-request';
3535
import {parseQs, parseQsFromFragment} from '../../src/vector/url_utils';
3636

@@ -68,12 +68,19 @@ describe('loading:', function () {
6868
});
6969
});
7070

71-
afterEach(function() {
71+
afterEach(async function() {
7272
if (parentDiv) {
7373
ReactDOM.unmountComponentAtNode(parentDiv);
7474
parentDiv.remove();
7575
parentDiv = null;
7676
}
77+
78+
// unmounting should have cleared the MatrixClientPeg
79+
expect(MatrixClientPeg.get()).toBe(null);
80+
81+
// clear the indexeddbs so we can start from a clean slate next time.
82+
await test_utils.deleteIndexedDB('matrix-js-sdk:crypto');
83+
await test_utils.deleteIndexedDB('matrix-js-sdk:riot-web-sync');
7784
});
7885

7986
/* simulate the load process done by index.js

‎test/test-utils.js‎

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var q = require('q');
77
* name to stdout.
88
* @param {Mocha.Context} context The test context
99
*/
10-
module.exports.beforeEach = function(context) {
10+
export function beforeEach(context) {
1111
var desc = context.currentTest.fullTitle();
1212
console.log();
1313
console.log(desc);
@@ -16,13 +16,40 @@ module.exports.beforeEach = function(context) {
1616
// some tests store things in localstorage. Improve independence of tests
1717
// by making sure that they don't inherit any old state.
1818
window.localStorage.clear();
19-
};
19+
}
2020

2121
/**
2222
* returns true if the current environment supports webrtc
2323
*/
24-
module.exports.browserSupportsWebRTC = function() {
24+
export function browserSupportsWebRTC() {
2525
var n = global.window.navigator;
2626
return n.getUserMedia || n.webkitGetUserMedia ||
2727
n.mozGetUserMedia;
28-
};
28+
}
29+
30+
export function deleteIndexedDB(dbName) {
31+
return new q.Promise((resolve, reject) => {
32+
if (!window.indexedDB) {
33+
resolve();
34+
return;
35+
}
36+
37+
console.log(`Removing indexeddb instance: ${dbName}`);
38+
const req = window.indexedDB.deleteDatabase(dbName);
39+
40+
req.onblocked = () => {
41+
console.log(`can't yet delete indexeddb because it is open elsewhere`);
42+
};
43+
44+
req.onerror = (ev) => {
45+
reject(new Error(
46+
"unable to delete indexeddb: " + ev.target.error,
47+
));
48+
};
49+
50+
req.onsuccess = () => {
51+
console.log(`Removed indexeddb instance: ${dbName}`);
52+
resolve();
53+
};
54+
});
55+
}

0 commit comments

Comments
 (0)