-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for loading environment variables from a file
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { describe, it, beforeEach } from 'node:test'; | ||
import * as assert from "node:assert"; | ||
import makeCliApplication from "./helpers/makeCliApplication.js"; | ||
import { Env } from "@aedart/support/env"; | ||
|
||
describe('@aedart/cli', () => { | ||
|
||
describe('env', () => { | ||
|
||
beforeEach(() => { | ||
Env.clear(); | ||
}); | ||
|
||
it('loads default .env file', async () => { | ||
const cli = makeCliApplication({ | ||
writeOut: () => { | ||
// Ignore output | ||
} | ||
}); | ||
const core = cli.core; | ||
|
||
let hasLoadedEnv = false; | ||
core.destroying(() => { | ||
hasLoadedEnv = Env.get('APP_ENV') === 'testing'; | ||
}); | ||
|
||
// --------------------------------------------------------------- // | ||
|
||
await cli.run([], { from: 'user' }); | ||
|
||
assert.ok(hasLoadedEnv, 'environment file not loaded'); | ||
}); | ||
|
||
it('can load custom environment file', async () => { | ||
const cli = makeCliApplication({ | ||
writeOut: () => { | ||
// Ignore output | ||
} | ||
}); | ||
const core = cli.core; | ||
|
||
let hasLoadedEnv = false; | ||
core.destroying(() => { | ||
hasLoadedEnv = Env.get('CUSTOM_KEY') === 'custom'; | ||
}); | ||
|
||
// --------------------------------------------------------------- // | ||
|
||
await cli.run([ | ||
'--env=tests/cli/packages/cli/fixtures/.custom' | ||
], { from: 'user' }); | ||
|
||
assert.ok(hasLoadedEnv, 'custom environment file not loaded'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Custom environment file | ||
|
||
# Application Environment | ||
# NOTE: Key might NOT be set, if previously defined in `process.env`! | ||
APP_ENV=custom | ||
|
||
# A custom key... | ||
CUSTOM_KEY=custom |