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

Unable to run tests as vitest bootstrapping fails #388

Closed
4 tasks done
moltco opened this issue May 20, 2024 · 1 comment
Closed
4 tasks done

Unable to run tests as vitest bootstrapping fails #388

moltco opened this issue May 20, 2024 · 1 comment

Comments

@moltco
Copy link

moltco commented May 20, 2024

Describe the bug

Vitest VS extension appears not to be loading the default .env file when discovering tests. If I run yarn vitest the tests are executed as expected. If I specify manually the .env file then the VS Code extension seems to be behaving as exepcted. This issue only appears to be present in the VS extension.

The issue is similar to vitest-dev/vitest#2117 and https://stackoverflow.com/questions/61038365/node-js-not-recognizing-env-file If I manually add .env file to vitest.config.ts then the VS Code Extension works as expected.

Otherwise the discovery fails with "Config param DB_ID_HOST not defined" and the vitest output window shows:

[Worker] Collecting tests due to file changes: model/Org.test.t
[INFO 9:11:50 AM] [TEST] ❌ Config param DB_ID_HOST not defined.

The DB_ID_HOST obviously exists, Jest and Playwright have no issues with it and the code where the exception is raised works well.

The real issue here is: as the test dicovery has failed, I can't run any tests at the same level which renders the extension useless.

I would expect that the default .env file (ie in the root as per vitest.config.ts) is picked up by the extension and the vitest in general unless the user does not explicitly change this via the config file or otherwise. Alternatively the vitest quick guide needs to highlight that you must specify env for tests and extension to work.

image

Reproduction

Vitest.config.ts in case it helps reproduce

export default defineConfig({
  test: {
    name: "my test",
    root: "./src",
    },
});

The failing line of code (ie the one that throws error) is in the db layer initialized in a pretty standard way


const cn = {
  host: nodeutil.getSafeConfig("DB_ID_HOST"),
...
}

the getSafeConfig does very little - throws Error if process.env[paramName] === null || === undefined

Output

See screenshot and description above

Version

vitest/1.6.0 win32-x64 node-v20.13.1 Extension v0.10.7

Validations

Copy link

Hello @moltco. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 24, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants