Skip to content

Commit e6a9bb4

Browse files
committed
Ignore .env when testing
Tests should not depend on local artifacts.
1 parent c0372b1 commit e6a9bb4

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ The easiest way to install and use JSKOS Server as stand-alone application is wi
112112

113113
You can customize the application settings via a configuration file. By default, this configuration file resides in `config/config.json`. However, it is possible to adjust this path via the `CONFIG_FILE` environment variable. Note that the given path has to be either absolute (i.e. starting with `/`) or relative to the `config/` folder. The configuration file is validated and JSKOS Server will refuse to start on configuration errors.
114114

115-
Configuration is also affected by environment variable `NODE_ENV` being either `development` (default), `test` (when run with `npm test`), or `production`. In `test` the default config file is `./config.test.json` instead of `config.json`. In `production` HTTPS URIs are forced for entities created on POST requests.
116-
117-
You can either provide the environment variables during the command to start the server, or in a `.env` file in the root folder.
115+
Configuration is also affected by environment variable `NODE_ENV` being either `development` (default), `test` (when run with `npm test`), or `production`. In `test` the default config file is `./config.test.json` instead of `config.json`. In `production` HTTPS URIs are forced for entities created on POST requests. Environment variable `CONFIG_FILE` can also be set in `.env` file in the root folder unless `NODE_ENV` is `test`.
118116

119117
#### Validation of configuration
120118

config/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { validateConfig, setupConfig } from "../config/setup.js"
22
import fs from "node:fs"
33
import path from "node:path"
4+
import * as dotenv from "dotenv"
45

56
// Prepare environment
6-
import * as dotenv from "dotenv"
7-
dotenv.config()
87
const env = process.env.NODE_ENV
8+
if (env !== "test") {
9+
dotenv.config()
10+
}
911

1012
// Get config file path and adjust if it's relative
1113
let configFile = process.env.CONFIG_FILE || (env === "test" ? "./config.test.json" : "./config.json")

0 commit comments

Comments
 (0)