-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
dash in collection names (2) #3785
Conversation
test/unit/rx-database.test.ts
Outdated
schema: schemas.human | ||
} | ||
}); | ||
await wait(100); // required... but why ?! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is because the database/collection can be created lazy. You could run any query here instead, then you can be sure that everything is initialized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I got it.
We may expose the internal promise on RxStorage interface to have an explicit way to wait for the lazy creation ? I guess all storage plugins may need this king of lazy loading promise ?
Playing with "fake querie" or wait(100) seems to me quite obscur, specially in unit tests (more than the simple unit test performance issue).
test/unit/rx-database.test.ts
Outdated
* I have to use internal implementation for assertions. | ||
* Please @pubkey could you consider a such tool ? | ||
*/ | ||
if (config.storage.name !== 'dexie') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should remove this return when you want to prove that a bug exists.
This makes it easier to check the CI for any hints on what goes wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be great but how to deal with storage.settings.indexedDB.internalDatabase._databases.keys()
in assertion for other storages ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. That makes sense.
src/rx-database.ts
Outdated
@@ -772,7 +772,7 @@ export async function removeRxDatabase( | |||
const key = colDoc.key; | |||
const schema = colDoc.data.schema; | |||
const split = key.split('-'); | |||
const collectionName = split[0]; | |||
const collectionName = split[0]; // proposal : key.substring(0,key.lastIndexOf('-')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this proposed fix also work when both, the database and the collection have a dash in it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nop, in removeRxDatabase
the database name has already been removed.
This is probably another issue
I think I understood the problem now. Inside of the |
Yes, that sound right. |
I finally add |
I'm sorry but I really do not want to add another test dependency just to reproduce this single problem. I do not understand it and it adds more complexity.
I have no idea what this does. Can't we just reopen the database and check if the data was really deleted? |
I understand your reticences. I am convinced that the whole project could benefit from this lib (for test purpose). Especially for a such project with abstraction layers and plugins ! You really could test the genetic layer (ie rx-database) independently of any storage or plugin. I could introduce you the piece of code you mentioned. If you are not confident with this kind of tool please, tell me ! I could help.
This will create a proxy for the It could be beemed as the following pseudo code :
Back to our example you mentioned, the
A reported call looks like
In our case, I'm interested in the A agree, this looks probably cryptic (reduce() function often imply a bad readability according to me). So from the list of calls :
I got :
I hope make more sense for you now. Please tell me If understanding this is still difficult even with this short demonstration. As you could see, by this way, my test could apply for all storages, all environments. I could removed limitations for this test (the isDexie and isNode initially required) Anyway, you are the boss, it's your project so, your choices ^^ |
I know these mocking libraries. I think they lead people to writing untestable code together with unreadable tests. But your test has to prove that a RxCollection is deleted. So checking for an internal call to |
Hum, ok, up to you. On my opinion, we should test implementation layer by layer unless these are only functional tests. RxDb is made of layers, with public interfaces. I have done my best to make tests independent from storage implementation (specially for assertion). Please let me know you would done on your side. I always ready to learn from others ! |
I understand now. Reproducing the problem with plain RxDB API is not possible. I now changed the returned value from |
This PR contains:
collection names should not contains '-' otherwise database.remove() fails.