[Sqlite|D1]: Add unit tests for the drizzle-orm/d1 driver
Motivation
While using drizzle-orm extensively in my projects, I noticed a few bugs in the D1 driver provided by Drizzle (see #528). Upon looking into the source code, I noticed that there are no unit tests run using the D1 driver.
In order to ensure a high level of stability for D1, I thought it would be a good idea to contribute and add unit tests 😀.
How the unit tests are written
The test content is taken directly from the better-sqlite.test.ts file. Most of the changes involve adding async/await as the D1 driver uses sqlite in async mode.
Due to the bugs involving joins in the D1 driver, most of the tests involving joins fail (in the same way mentioned in #528).
I've modified the assertion to pass for now, and marked each instance with a TODO comment.
The goal is to have this change committed before the actual fix is made, so that it's easier to establish correctness going forward
How D1 is emulated locally (why I'm using Miniflare v2)
Miniflare is the official emulator provided by Cloudflare for running their services locally.
Last week, Cloudflare released wrangler v3 and miniflare v3, which change the way emulation for services work, using the new workerd runtime. Unfortunately from what I could see, emulating D1 locally with it is not documented very well, and I couldn't figure out an easy way to set this up. So I opted to use miniflare v2, which is well documented.
@AdiRishi thanks a lot! You've done really great work
Please resolve the merge conflicts. Good job overall 👍
Done :)
@dankochetov I'm trying to keep the branch up to date as often as I can, any idea when this will be merged?
@AdiRishi one last thing - please sign your commits and force-push the branch, after that I'll merge it.
@dankochetov done 😄
Sorry, I thought they were signed. TIL that when you rebase your branch from the Github front-end, it doesn't automatically sign commits 😅
@dankochetov I've updated this PR again to resolve conflicts with the latest release. It's been a while now, will this get merged soon?
Hey @AdiRishi!
Sorry for the delayed response to this PR. I'm currently reviewing all of them for approval and merging. There is one conflict in this PR. I am already aware of the issue, so if you can address it, I will proceed with the merge.
The specific error is: Use of the "instanceof" operator is prohibited (no-instanceof/no-instanceof). This is due to the ESLint rule we implemented to ensure that we avoid using the "instanceof" operator for Drizzle models. However, I noticed that your tests are failing when checking for instanceof Date, which should be allowed. You can simply bypass the rule for those lines.
Here's an example of how we handled a similar situation in another set of tests: https://github.com/drizzle-team/drizzle-orm/blob/main/integration-tests/tests/better-sqlite.test.ts#L264
If you're unable to do it, I suppose I can edit this PR myself. However, I would prefer it if you could complete this one entirely
@AndriiSherman thanks for reviewing this 😄 . I've fixed the eslint errors and double checked that the tests pass locally. Should be all good to merge now 🚀