Skip to content

Accessing variables via process.env from node:process in deno test without --allow-env permission silently returns undefined #28125

Open
@lionel-rowe

Description

@lionel-rowe

Version: Deno 2.1.10

With the following file test.ts:

import process from 'node:process'

console.log(process.env.SOME_ENV_VAR)

deno run without --allow-env permission prompts as expected:

SOME_ENV_VAR=1 deno run test.ts
# ┏ ⚠️  Deno requests env access to "SOME_ENV_VAR".
# ┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.
# ┠─ Learn more at: https://docs.deno.com/go/--allow-env
# ┠─ Run again with --allow-env to bypass this prompt.
# ┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all env permissions) > 

However, deno test without --allow-env silently returns undefined (expected to throw error, as deno test doesn't prompt for permissions):

SOME_ENV_VAR=1 deno test test.ts
# Check file:///path/to/test.ts
# ------- pre-test output -------
# undefined
# ----- pre-test output end -----
# running 0 tests from ./test.ts
# 
# ok | 0 passed | 0 failed (2ms)

Conversely, deno testing the equivalent code with Deno.env.get('SOME_ENV_VAR') throws as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions