mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Add setupNconf function
This commit is contained in:
41
test/api/v3/unit/libs/setupNconf.test.js
Normal file
41
test/api/v3/unit/libs/setupNconf.test.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import setupNconf from '../../../../../website/src/libs/api-v3/setupNconf';
|
||||||
|
|
||||||
|
import nconf from 'nconf';
|
||||||
|
|
||||||
|
describe('setupNconf', () => {
|
||||||
|
afterEach(() => {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets up nconf to load command line arguments', () => {
|
||||||
|
sandbox.spy(nconf, 'argv');
|
||||||
|
|
||||||
|
setupNconf();
|
||||||
|
|
||||||
|
expect(nconf.argv).to.be.calledOnce;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets up nconf to load environmental variables', () => {
|
||||||
|
sandbox.spy(nconf, 'env');
|
||||||
|
|
||||||
|
setupNconf();
|
||||||
|
|
||||||
|
expect(nconf.env).to.be.calledOnce;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets up nconf to load variables from config file', () => {
|
||||||
|
sandbox.spy(nconf, 'file');
|
||||||
|
|
||||||
|
setupNconf();
|
||||||
|
|
||||||
|
expect(nconf.file).to.be.calledOnce;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets IS_PROD variable', () => {
|
||||||
|
expect(nconf.get('IS_PROD')).to.exist;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets IS_DEV variable', () => {
|
||||||
|
expect(nconf.get('IS_DEV')).to.exist;
|
||||||
|
});
|
||||||
|
});
|
||||||
14
website/src/libs/api-v3/setupNconf.js
Normal file
14
website/src/libs/api-v3/setupNconf.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import nconf from 'nconf';
|
||||||
|
import { join, resolve } from 'path';
|
||||||
|
|
||||||
|
const PATH_TO_CONFIG = join(resolve(__dirname, '../../../../config.json'));
|
||||||
|
|
||||||
|
export default function setupNconf () {
|
||||||
|
nconf
|
||||||
|
.argv()
|
||||||
|
.env()
|
||||||
|
.file('user', PATH_TO_CONFIG);
|
||||||
|
|
||||||
|
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
|
||||||
|
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user