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

[AstroDB] getViteConfig throws in Vitest - Cannot read properties of undefined (reading 'ASTRO_DATABASE_FILE') #11414

Closed
1 task
haivuw opened this issue Jul 4, 2024 · 1 comment · Fixed by #11435
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) help wanted Please help with this issue! pkg: db

Comments

@haivuw
Copy link
Contributor

haivuw commented Jul 4, 2024

Astro Info

Astro                    v4.11.5
Node                     v20.10.0
System                   Linux (x64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             astro:db
                         @astrojs/db/file-url

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

There's an error if I run vitest with astro's getViteConfig, and the default database .astro/content.db is not seeded:

➜  astrodb-vitest-repro git:(main) px vitest run
20:46:26 [types] Added src/env.d.ts type declarations.

 RUN  v1.6.0 /home/hl/ws/test/astrodb-vitest-repro

20:46:26 [astro:db] New local database created.
20:46:26 [ERROR] [astro:db] Cannot read properties of undefined (reading 'ASTRO_DATABASE_FILE')
 ✓ src/test.test.ts (1)
   ✓ test

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  20:46:26
   Duration  584ms (transform 8ms, setup 0ms, collect 8ms, tests 1ms, environment 0ms, prepare 43ms)

Moreover, if I import the db in the test file (import { db } from "astro:db") and set vitest's poolOptions.threads.singleThread to true, the test will fail half of the time.

What's the expected result?

No error should be showing when running vitest. Test database should be seeded.

Link to Minimal Reproducible Example

https://github.com/haivuw/astrodb-vitest-repro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jul 4, 2024
@haivuw haivuw changed the title getViteConfig throws in Vitest - Cannot read properties of undefined (reading 'ASTRO_DATABASE_FILE') [AstroDB] getViteConfig throws in Vitest - Cannot read properties of undefined (reading 'ASTRO_DATABASE_FILE') Jul 4, 2024
@haivuw
Copy link
Contributor Author

haivuw commented Jul 4, 2024

This is what it shows in my private project:

 FAIL  src/auth/verify-email.test.ts [ src/auth/verify-email.test.ts ]
TypeError: Cannot read properties of undefined (reading 'ASTRO_DATABASE_FILE')
 ❯ eval astro:db:seed:7:87
 ❯ instantiateModule node_modules/.pnpm/vite@5.3.3_@types+node@20.14.9/node_modules/vite/dist/node/chunks/dep-CzJTQ5q7.js:53451:5

If I run ASTRO_DATABASE_FILE=test.db pnpm exec vitest run, test.db is created as expected, but it won't be seeded, and I still see the error.

@matthewp matthewp added - P3: minor bug An edge case that only affects very specific usage (priority) pkg: db help wanted Please help with this issue! and removed needs triage Issue needs to be triaged labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) help wanted Please help with this issue! pkg: db
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants