-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathglobal-config.js
57 lines (48 loc) · 1.79 KB
/
global-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const assert = require('assert');
const fs = require('fs');
const sinon = require('sinon');
const globalConfig = require('../lib/utils/global-config');
describe('global config', () => {
beforeEach(function () {
this.sandbox = sinon.createSandbox();
});
afterEach(function () {
this.sandbox.restore();
});
describe('.getAll()', () => {
it('when config file exists', function () {
this.sandbox.stub(fs, 'existsSync').returns(true);
this.sandbox.stub(fs, 'readFileSync').returns('{"foo": "bar"}');
assert.deepStrictEqual(globalConfig.getAll(), {foo: 'bar'});
});
it('when config file doesn\'t exists', function () {
this.sandbox.stub(fs, 'existsSync').returns(false);
assert.deepStrictEqual(globalConfig.getAll(), {});
});
});
describe('.hasContent()', () => {
it('when config is present', function () {
this.sandbox.stub(fs, 'existsSync').returns(true);
this.sandbox.stub(fs, 'readFileSync').returns('{"foo": "bar"}');
assert(globalConfig.hasContent());
});
it('when config is not present', function () {
this.sandbox.stub(fs, 'existsSync').returns(true);
this.sandbox.stub(fs, 'readFileSync').returns('{}');
assert(!globalConfig.hasContent());
});
});
it('.remove()', function () {
this.sandbox.stub(fs, 'existsSync').returns(true);
this.sandbox.stub(fs, 'writeFileSync');
this.sandbox.stub(fs, 'readFileSync').returns('{"foo": "bar", "baz": "qux"}');
globalConfig.remove('foo');
sinon.assert.calledWith(fs.writeFileSync, globalConfig.path, '{\n "baz": "qux"\n}');
});
it('.removeAll()', function () {
this.sandbox.stub(fs, 'writeFileSync');
globalConfig.removeAll();
sinon.assert.calledWith(fs.writeFileSync, globalConfig.path, '{}');
});
});