Skip to content

Commit

Permalink
Fix: Add conditional use of .env.test file
Browse files Browse the repository at this point in the history
Signed-off-by: Kaung Zin Hein <[email protected]>
  • Loading branch information
Zen-cronic committed Feb 21, 2025
1 parent ce8adcf commit b95fa07
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ docker-run:
docker run -it --rm --name $(DOCKER_IMAGE_NAME)-01 $(DOCKER_IMAGE_NAME)

test:
npx tsx --test ${TEST_FILES}
NODE_ENV=test npx tsx --test ${TEST_FILES}

lint:
npx tsc --noemit
Expand Down
2 changes: 0 additions & 2 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { Knex, default as knex } from 'knex';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';
import './env.ts';
import dotenv from 'dotenv';
dotenv.config({ path: './.env.test' });

let settings: Knex.Config | null = null;
const db: Knex = knex(getSettings());
Expand Down
8 changes: 7 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ if (process.env.PUBLIC_URI === undefined) {
// that we may be missing a .env file.
//
// This is the only required environment variable.
dotenv.config({path: dirname(fileURLToPath(import.meta.url)) + '/../.env'});
if(process.env.NODE_ENV === 'test'){
dotenv.config({ path: './.env.test' });
}
else{
dotenv.config({path: dirname(fileURLToPath(import.meta.url)) + '/../.env'});
}

} else {
console.warn('/env.js was loaded twice?');
}

0 comments on commit b95fa07

Please sign in to comment.