Comparing version 1.7.7 to 1.7.8
@@ -118,3 +118,7 @@ 'use strict'; | ||
value: function save(newPath) { | ||
_fs2.default.writeFileSync(_path2.default.normalize(newPath || this._path), JSON.stringify(this._config, null, 4) + '\n', 'utf8'); | ||
if (arguments.length === 0 && this._path === null) { | ||
throw new Error('No path provided.'); | ||
} else { | ||
_fs2.default.writeFileSync(_path2.default.normalize(newPath || this._path), JSON.stringify(this._config, null, 4) + '\n', 'utf8'); | ||
} | ||
} | ||
@@ -121,0 +125,0 @@ }, { |
{ | ||
"name": "cz", | ||
"version": "1.7.7", | ||
"version": "1.7.8", | ||
"description": "A simple config utility for nodejs", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"test": "xo && npm run build && npm run coverage", | ||
"gen_test_files": "echo '{}' > ./test/config.json && echo '' > ./test/emptyConfig.json", | ||
"gen_test_files": "echo '{}' > ./test/config.json && echo '' > ./test/emptyConfig.json && echo '{}' > ./test/anotherEmptyConfig.json", | ||
"coverage": "npm run gen_test_files && npm run mocha && if-env CI=true && npm run push-coverage || echo ''", | ||
@@ -11,0 +11,0 @@ "push-coverage": "cat ./coverage/lcov.info | coveralls && rm -rf ./coverage && rm -rf ./nyc_output", |
@@ -15,2 +15,4 @@ 'use strict'; | ||
const emptyConfig = new Cz(); | ||
const anotherEmptyConfig = new Cz(); | ||
const theLastConfig = new Cz(); | ||
@@ -79,3 +81,3 @@ describe('set config using string param and string value', () => { | ||
describe('save config to file', () => { | ||
describe('save config to specified file', () => { | ||
before(() => { | ||
@@ -98,4 +100,33 @@ config.reset(); | ||
describe('load config from file', () => { | ||
describe('save config to already loaded file', () => { | ||
before(() => { | ||
const configPath = path.join(__dirname, './anotherEmptyConfig.json'); | ||
anotherEmptyConfig.load(configPath); | ||
anotherEmptyConfig.set('test', 'value'); | ||
anotherEmptyConfig.save(); | ||
}); | ||
it(`test should be value`, () => expect(anotherEmptyConfig.get('test')).to.equal('value')); | ||
it(`anotherEmptyConfig.json should contain {"test": "value"}`, () => { | ||
fs.readFile(path.join(__dirname, './anotherEmptyConfig.json'), 'utf8', (err, data) => { | ||
if (err) { | ||
throw err; | ||
} | ||
expect(JSON.parse(data).test).to.equal('value'); | ||
}); | ||
}); | ||
}); | ||
describe('save config without providing path', () => { | ||
before(() => { | ||
theLastConfig.set('test', 'value'); | ||
}); | ||
it(`theLastConfig.save() should throw an error since it has no path`, () => { | ||
expect(() => theLastConfig.save()).to.throw('No path provided.'); | ||
}); | ||
}); | ||
describe('load config from specified file', () => { | ||
before(() => { | ||
config.reset(); | ||
@@ -102,0 +133,0 @@ config.load(path.join(__dirname, './config.json')); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
332317
24
714