-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
fix: astrodb vite plugin throws in vitest and cannot seed database #11435
Conversation
🦋 Changeset detectedLatest commit: 905562c The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I couldn't run all tests #11441. Though |
Just ran into this issue, would be nice to have this merged. |
@haivuw can you update this PR |
@matthewp I resolved the conflicts but this test failed on Windows: The path to local db is malformed: /D:/a/astro/astro/packages/db/testixtures�asicsdistastro.db
I don't have the capacity to make sure all tests pass right now. So this is as far as I can do. |
@@ -124,12 +124,14 @@ export function getLocalVirtualModContents({ | |||
tables: DBTables; | |||
root: URL; | |||
}) { | |||
const { ASTRO_DATABASE_FILE } = getAstroEnv(); | |||
const envDbUrl = ASTRO_DATABASE_FILE ? `'${ASTRO_DATABASE_FILE}'` : undefined; |
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 don't think you need to stringify the string, because it's already a string. We already to such here:
astro/packages/db/src/core/integration/vite-plugin-db.ts
Lines 211 to 212 in ff522b9
const { ASTRO_DATABASE_FILE } = getAstroEnv(); | |
const dbUrl = normalizeDatabaseUrl(ASTRO_DATABASE_FILE, new URL(DB_PATH, root).href); |
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.
It will be
const dbUrl = normalizeDatabaseUrl(file://local.db, ${JSON.stringify(dbUrl)});
without stringification.
But I just realized I could have used JSON.stringify, so I'll update.
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 see. The failing test is definitely weird though, I wonder what's causing the failure
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 think the test passed before because ASTRO_DATABASE_URL was not passed to the plugin at all.
And this line of the test generates a malformed path on Windows:
astro/packages/db/test/local-prod.test.js
Line 39 in ff522b9
const prodDbPath = relative(process.cwd(), fileURLToPath(absoluteFileUrl)); |
which is
/D:/a/astro/astro/packages/db/testixtures�asicsdistastro.db
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.
Hopefully someone with Windows machine can fix that.
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.
Wait it passed now 💀
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'm not sure what magic JSON.stringify does here.
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Changes
Fixes #11414
import.meta.env
is undefined in the virtual module which make it throw and the database is not seeded.Testing
Tested by linking local @astrojs/db in my other project. Db was seeded ok.
Docs
just a minor bug fix