-
-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Labels
Description
Describe the bug
I'm using vitest for express testing but the extension is unusable for my use case. I want to:
- Spin up a container to be used by all tests once
- Pass the container URL in env variables so tests can reference it
- Run my tests (with the env variables defined here)
- Teardown my test containers
At present this isn't really possible with all of these approaches:
- globalSetup: This only runs once and then never again until you manually reload your tests (subsequent tests will not have proper setup). This can be circumvented with the
onTestsRerunhook but then the teardown script will only run when reload is selected. This also runs in a separate context so environment variables need to be manually injected into test context with theproject.providefunction, adding a lot of overhead. - custom reporters: This seemed promising but apparently reporters just don't run at all for some reason on the extension so this won’t work. Tried using
onTestRunStartandonFinishedhooks to perform setup and teardown respectively but this simply doesn't run at all when running tests by the extension
Currently it seems there’s no way to simply run a single global setup before all tests are ran so currently I’m just running via CLI until this can be resolved. Hopefully either by fixing reporters or by creating a pretest of some kind in the config.
Reproduction
https://github.com/MakoriSM/vitest-test
Output
This is my output whenever I run the onTestRerun hook setup version. Everything spins up (twice, once for each test environment I'd prefer only having 1 for all environments) but doesn't teardown. It includes extra console logs I've added:
[INFO 7:30:34 PM] Running 1 file(s): tests
[7:30:34 PM] Starting a test run because tests/unit/auth.service.test.ts tests/integration/basic.int.test.ts tests/integration/auth/basic.auth.int.test.ts triggered a watch rerun event
[7:30:34 PM] Enqueuing "noop test to preserve suite after Firebase migration"
[7:30:34 PM] Enqueuing "sets DATABASE_URL for per-file db"
[7:30:34 PM] Enqueuing "requires auth"
[7:30:34 PM] Enqueuing "accepts emulator token"
[7:30:34 PM] Enqueuing "noop test to preserve suite after Firebase migration"
[7:30:34 PM] Enqueuing "sets DATABASE_URL for per-file db"
[7:30:34 PM] Enqueuing "requires auth"
[7:30:34 PM] Enqueuing "accepts emulator token"
[7:30:34 PM] Enqueuing "noop test to preserve suite after Firebase migration"
[7:30:34 PM] Enqueuing "sets DATABASE_URL for per-file db"
[7:30:34 PM] Enqueuing "requires auth"
[7:30:34 PM] Enqueuing "accepts emulator token"
[INFO 7:30:34 PM] [Worker] globalSetup.ts: shouldSetupDb true
[INFO 7:30:36 PM] [Worker] globalSetup.ts: databaseUrl postgresql://postgres:password@localhost:32780/vitest_test
globalSetup.ts: toUrlWithDb postgresql://postgres:password@localhost:32780/vitest_test postgres
globalSetup.ts: toUrlWithDb postgresql://postgres:password@localhost:32780/vitest_test vitest_template
[INFO 7:30:38 PM] [Worker]
[INFO 7:30:39 PM] [Worker] Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "vitest_test", schema "public" at "localhost:32780"
[INFO 7:30:39 PM] [Worker]
🚀 Your database is now in sync with your Prisma schema. Done in 98ms
⠙
[INFO 7:30:42 PM] [Worker] globalSetup.ts: endpoint http://localhost:32781
[INFO 7:30:54 PM] [Worker] globalSetup.ts: shouldSetupDb true
[INFO 7:30:56 PM] [Worker] globalSetup.ts: databaseUrl postgresql://postgres:password@localhost:32783/vitest_test
globalSetup.ts: toUrlWithDb postgresql://postgres:password@localhost:32783/vitest_test postgres
globalSetup.ts: toUrlWithDb postgresql://postgres:password@localhost:32783/vitest_test vitest_template
[INFO 7:30:58 PM] [Worker]
[INFO 7:30:59 PM] [Worker] Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "vitest_test", schema "public" at "localhost:32783"
[INFO 7:30:59 PM] [Worker]
🚀 Your database is now in sync with your Prisma schema. Done in 148ms
⠙
[INFO 7:31:02 PM] [Worker] globalSetup.ts: endpoint http://localhost:32784
[7:31:15 PM] No task result for "auth.service.test.ts [unit]", ignoring
[7:31:15 PM] No task result for "AuthService", ignoring
[7:31:15 PM] Enqueuing "noop test to preserve suite after Firebase migration" because it was just collected
[7:31:15 PM] No errors found for "auth.service.test.ts [unit]"
[7:31:15 PM] No errors found for "AuthService"
[7:31:15 PM] Marking "noop test to preserve suite after Firebase migration" as passed
[7:31:15 PM] No errors found for "auth.service.test.ts [unit]"
[7:31:15 PM] No task result for "basic.int.test.ts [int]", ignoring
[7:31:15 PM] No task result for "basic infra smoke", ignoring
[7:31:15 PM] Enqueuing "sets DATABASE_URL for per-file db" because it was just collected
[7:31:15 PM] No errors found for "basic.int.test.ts [int]"
[7:31:15 PM] No errors found for "basic.int.test.ts [int]"
[7:31:15 PM] No errors found for "basic infra smoke"
[7:31:15 PM] Marking "sets DATABASE_URL for per-file db" as passed
[7:31:15 PM] No errors found for "basic.int.test.ts [int]"
[7:31:15 PM] No task result for "basic.auth.int.test.ts [int-auth]", ignoring
[7:31:15 PM] Enqueuing "requires auth" because it was just collected
[7:31:15 PM] Enqueuing "accepts emulator token" because it was just collected
[7:31:15 PM] No errors found for "basic.auth.int.test.ts [int-auth]"
[7:31:15 PM] No errors found for "basic.auth.int.test.ts [int-auth]"
[7:31:16 PM] Marking "requires auth" as passed
[7:31:16 PM] Marking "accepts emulator token" as passed
[7:31:16 PM] No errors found for "basic.auth.int.test.ts [int-auth]"
[7:31:16 PM] Ending test run
[7:31:16 PM] Test run promise is finished, the queue is 0
[7:31:16 PM] [VSCODE] Ignoring file: node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.jsonExtension Version
1.32.0
Vitest Version
3.2.4
Validations
- Check that you are using the latest version of the extension
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
eightHundreds