Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Is there an easy way to reset all data in the RAM database? #2

Closed
jcalfee opened this issue Jul 8, 2015 · 7 comments
Closed

Comments

@jcalfee
Copy link

jcalfee commented Jul 8, 2015

I'm using fakeIndexedDB in my unit tests. It would be great to make one method call and delete all object stores. This would be used after each test.

@dumbmatter
Copy link
Owner

You want it to delete all object stores, or delete all data within all object stores while leaving the stores there? Because if it's the former, you could just use fakeIndexedDB.deleteDatabase since a database with no object stores isn't doing you much good.

@jcalfee
Copy link
Author

jcalfee commented Jul 8, 2015

A clean slate. The idea is that each unit test should re-build everything it needs and should not be influenced by or depend on another test. That keeps is simple.

Thanks for the help. I have other requests like this they seem to work. Is it possible that the call back for deleteDatabase is not implemented? Below the done() is not being called and there is no error.

before( done => {
        var request = fakeIndexedDB.deleteDatabase("graphene_db")
        request.onsuccess = ()=>{ done() }
        request.onerror = e => {console.error(e)}
 })

@jcalfee
Copy link
Author

jcalfee commented Jul 8, 2015

I see you seem to be very well tested in this area in your own unit tests (via the version 1.0.3 tag) .... It must be something in my code. I'll let you know if I come up with something useful. Thanks again.

@jcalfee jcalfee closed this as completed Jul 8, 2015
@dumbmatter
Copy link
Owner

Make sure you call db.close first, I might not be handling deleting an open
database correctly. Need to investigate more.
On Jul 8, 2015 9:53 AM, "James Calfee" notifications@github.com wrote:

I see you seem to be very well tested in this area in your own unit tests
(via the version 1.0.3 tag) .... It must be something in my code. I'll let
you know if I come up with something useful. Thanks again.


Reply to this email directly or view it on GitHub
#2 (comment)
.

@dumbmatter
Copy link
Owner

Yeah, there is definitely a problem with deleting databases that still have open connections. This hangs:

var fakeIndexedDB = require('fake-indexeddb');
fakeIndexedDB.open('test', 1);
fakeIndexedDB.deleteDatabase('test');

The same problem occurs when running a versionchange transaction on databases that still have open connections:

var fakeIndexedDB = require('fake-indexeddb');
fakeIndexedDB.open('test', 1);
fakeIndexedDB.open('test', 2);

In both cases, the spec says something like:

Fire a versionchange event at each open database. Then fire a blocked event at each database that is still open. Then wait for all databases to be closed before proceeding.

But... I don't understand what is actually supposed to be closing the databases. Nothing in fakeIndexedDB does it, so it gets stuck waiting for all databases to close before proceeding.

Probably it is described in the spec somewhere and I am just missing it. Maybe someone will help me.

@dumbmatter dumbmatter reopened this Jul 9, 2015
@spralle
Copy link

spralle commented May 6, 2017

I had a problem getting proper deleteDatabase to work (data seemed to be there when I opened again) and no time to figure out why so I did something ugly but worked for me idb._databases.clear();

@ghost

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants