Skip to content

Commit

Permalink
(indexeddb) test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 9, 2019
1 parent cdb0ec0 commit 75807b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const openDB = (name, initDB) => globals.createPromise((resolve, reject)
request.onsuccess = event => {
const db = event.target.result
db.onversionchange = () => { db.close() }
addEventListener('unload', () => db.close())
if (typeof addEventListener !== 'undefined') {
addEventListener('unload', () => db.close())
}
resolve(db)
}
})
Expand Down
9 changes: 7 additions & 2 deletions indexeddb.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import * as idb from './indexeddb.js'
import * as environment from './environment.js'
import * as promise from './promise.js'

if (environment.isNode) {
// @ts-ignore
global.indexedDB = require('fake-indexeddb')
// @ts-ignore
global.IDBKeyRange = require('fake-indexeddb/lib/FDBKeyRange')
}

const initTestDB = db => idb.createStores(db, [['test']])
const testDBName = 'idb-test'

Expand All @@ -14,7 +21,6 @@ const createTransaction = db => db.transaction(['test'], 'readwrite')
const getStore = t => idb.getStore(t, 'test')

export const testIdbIteration = async () => {
t.skip(!environment.isBrowser)
t.describe('create, then iterate some keys')
await idb.deleteDB(testDBName)
const db = await idb.openDB(testDBName, initTestDB)
Expand All @@ -37,7 +43,6 @@ export const testIdbIteration = async () => {
}

export const testIdbIterationNoAwait = () => {
t.skip(!environment.isBrowser)
t.describe('create, then iterate some keys')
return idb.deleteDB(testDBName)
.then(() => idb.openDB(testDBName, initTestDB))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"dependencies": {},
"devDependencies": {
"fake-indexeddb": "^2.0.5",
"live-server": "^1.2.1",
"nyc": "^13.3.0",
"rollup": "^1.1.2",
Expand Down

0 comments on commit 75807b3

Please sign in to comment.