@@ -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