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

feat: add out-of-box support for .env files #527

Merged
merged 4 commits into from
Jul 9, 2024
Merged

feat: add out-of-box support for .env files #527

merged 4 commits into from
Jul 9, 2024

Conversation

wellwelwel
Copy link
Owner

@wellwelwel wellwelwel commented Jul 9, 2024

Support read an environment file and sets the environment variables.

CLI

Loading the .env by default:

npx poku --env-file

Loading a custom .env:

npx poku --env-file='path/to/my/.env'

API (in-code)

You can set a .env file directly in a specif test or by using it globally.

Loading the .env by default:

import { envFile } from 'poku';

await envFile();

Loading a custom .env:

import { envFile, poku } from 'poku';

await envFile('path/to/my/.env');

await poku('./');

Note

It's not possible to retrieve files from directories above the current process, e.g. ../.env.


Important

Poku is made entirely for testing purposes, please don't use this functionality outside of testing.


Real Examples

  • .env.test
HOST='localhost'
PORT='8080'

Then, in a test file, you can use it as:

import { assert } from 'poku';

const host = process.env.HOST;
const port = process.env.PORT;

// Your tests come here

Then, run your tests

npx poku --env-file='.env.test'

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e9ae81b) to head (04f54b8).

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #527    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           24        26     +2     
  Lines         2751      2860   +109     
  Branches       459       484    +25     
==========================================
+ Hits          2751      2860   +109     
Flag Coverage Δ
linux 99.33% <100.00%> (+0.02%) ⬆️
osx 100.00% <100.00%> (ø)
windows 99.26% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wellwelwel wellwelwel marked this pull request as ready for review July 9, 2024 08:56
@wellwelwel wellwelwel merged commit 4ef3ecf into main Jul 9, 2024
28 checks passed
@wellwelwel wellwelwel deleted the env branch July 9, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant