Skip to content
Snippets Groups Projects
Commit a680b8f8 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Fix constructor

parent d24103ad
No related branches found
No related tags found
1 merge request!8Fix constructor
Pipeline #65508 passed
......@@ -2,7 +2,7 @@ var fs = require('fs')
var path = require('path')
var merge = require('lodash.merge')
module.exports = function(basePath = undefined, envPrefix = undefined) {
function createConfig(basePath = undefined, envPrefix = undefined) {
let configDefaults
let configLocal
let envPrefixUpper = envPrefix ? envPrefix.toUpperCase() + "_" : ''
......@@ -104,4 +104,5 @@ module.exports = function(basePath = undefined, envPrefix = undefined) {
}
config._reload()
return config
}
\ No newline at end of file
}
module.exports = { createConfig };
\ No newline at end of file
const fs = require('fs').promises
const Config = require('./index')
const createConfig = require('./index').createConfig
let jsonDefaults = {
setting:"defaultvalue",
......@@ -25,7 +25,7 @@ describe('config', function() {
it('should only have values from config.defaults.json', async function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
let config = new Config()
let config = createConfig()
await fs.unlink('config.defaults.json')
expect(config.setting).toBe('defaultvalue')
......@@ -34,7 +34,7 @@ describe('config', function() {
it('should only have values from config.json', async function() {
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
let config = new Config()
let config = createConfig()
await fs.unlink('config.json')
expect(config.setting).toBe('localvalue')
......@@ -44,7 +44,7 @@ describe('config', function() {
it('should have both values with preference to config.json', async function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
let config = new Config()
let config = createConfig()
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
......@@ -57,7 +57,7 @@ describe('config', function() {
await fs.mkdir('tmp')
await fs.writeFile('tmp/config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('tmp/config.json', JSON.stringify(jsonLocals))
let config = new Config('tmp')
let config = createConfig('tmp')
await fs.unlink('tmp/config.json')
await fs.unlink('tmp/config.defaults.json')
await fs.rmdir('tmp')
......@@ -75,7 +75,7 @@ describe('config', function() {
process.env['ANOTHER_MORE'] = 'false'
process.env['EVEN_DEEPER_KEY'] = 'true'
let config = new Config()
let config =createConfig()
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
......@@ -98,7 +98,7 @@ describe('config', function() {
process.env['P_ANOTHER_MORE'] = 'false'
process.env['P_EVEN_DEEPER_KEY'] = 'true'
let config = new Config(undefined, 'p')
let config = createConfig(undefined, 'p')
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
......@@ -119,7 +119,7 @@ describe('config', function() {
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
await fs.writeFile('file.txt', 'value-from-file')
let config = new Config()
let config = createConfig()
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
......@@ -133,7 +133,7 @@ describe('config', function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
let config = new Config()
let config = createConfig()
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
......@@ -146,7 +146,7 @@ describe('config', function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
let config = new Config()
let config = createConfig()
expect(config.setting).toBe('localvalue')
......@@ -165,7 +165,7 @@ describe('config', function() {
await fs.writeFile('config.defaults.json', JSON.stringify(jsonDefaults))
await fs.writeFile('config.json', JSON.stringify(jsonLocals))
let config = new Config()
let config = createConfig()
await fs.unlink('config.json')
await fs.unlink('config.defaults.json')
......
{
"name": "@libs/config",
"version": "1.13.5",
"version": "1.13.6",
"description": "Simple Config with ENV Support",
"main": "index.js",
"scripts": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment