mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Add support for passing in custom env file to nconf.
This commit is contained in:
@@ -3,29 +3,39 @@ import setupNconf from '../../../../../website/src/libs/api-v3/setupNconf';
|
|||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
|
|
||||||
describe('setupNconf', () => {
|
describe('setupNconf', () => {
|
||||||
before(() => {
|
beforeEach(() => {
|
||||||
sandbox.spy(nconf, 'argv');
|
sandbox.stub(nconf, 'argv').returnsThis();
|
||||||
sandbox.spy(nconf, 'env');
|
sandbox.stub(nconf, 'env').returnsThis();
|
||||||
sandbox.spy(nconf, 'file');
|
sandbox.stub(nconf, 'file').returnsThis();
|
||||||
|
|
||||||
setupNconf();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(() => {
|
afterEach(() => {
|
||||||
sandbox.restore();
|
sandbox.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets up nconf', () => {
|
it('sets up nconf', () => {
|
||||||
|
setupNconf();
|
||||||
|
|
||||||
expect(nconf.argv).to.be.calledOnce;
|
expect(nconf.argv).to.be.calledOnce;
|
||||||
expect(nconf.env).to.be.calledOnce;
|
expect(nconf.env).to.be.calledOnce;
|
||||||
expect(nconf.file).to.be.calledOnce;
|
expect(nconf.file).to.be.calledOnce;
|
||||||
|
expect(nconf.file).to.be.calledWithMatch('user', /\/config.json$/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets IS_PROD variable', () => {
|
it('sets IS_PROD variable', () => {
|
||||||
|
setupNconf();
|
||||||
expect(nconf.get('IS_PROD')).to.exist;
|
expect(nconf.get('IS_PROD')).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets IS_DEV variable', () => {
|
it('sets IS_DEV variable', () => {
|
||||||
|
setupNconf();
|
||||||
expect(nconf.get('IS_DEV')).to.exist;
|
expect(nconf.get('IS_DEV')).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows a custom config.json file to be passed in', () => {
|
||||||
|
setupNconf('customfile.json');
|
||||||
|
|
||||||
|
expect(nconf.file).to.be.calledOnce;
|
||||||
|
expect(nconf.file).to.be.calledWithMatch('user', 'customfile.json');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ global.sandbox = sinon.sandbox.create();
|
|||||||
//------------------------------
|
//------------------------------
|
||||||
// Load nconf for unit tests
|
// Load nconf for unit tests
|
||||||
//------------------------------
|
//------------------------------
|
||||||
require('../../website/src/libs/api-v3/setupNconf')();
|
require('../../website/src/libs/api-v3/setupNconf')('./config.json.example');
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import { join, resolve } from 'path';
|
|||||||
|
|
||||||
const PATH_TO_CONFIG = join(resolve(__dirname, '../../../../config.json'));
|
const PATH_TO_CONFIG = join(resolve(__dirname, '../../../../config.json'));
|
||||||
|
|
||||||
export default function setupNconf () {
|
export default function setupNconf (file) {
|
||||||
|
file = file || PATH_TO_CONFIG;
|
||||||
|
|
||||||
nconf
|
nconf
|
||||||
.argv()
|
.argv()
|
||||||
.env()
|
.env()
|
||||||
.file('user', PATH_TO_CONFIG);
|
.file('user', file);
|
||||||
|
|
||||||
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
|
nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
|
||||||
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
|
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
|
||||||
|
|||||||
Reference in New Issue
Block a user