This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
/
config.test.js
75 lines (59 loc) 路 2.21 KB
/
config.test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const assert = require('chai').assert;
const sinon = require('sinon');
const sandbox = sinon.createSandbox();
const { getConfig } = require('../lib/config');
const exitCodes = require('../lib/exit-codes');
beforeEach(function() {
sandbox.stub(process, 'exit');
sandbox.spy(console, 'error');
});
afterEach(function() {
sandbox.restore();
});
describe('Config', function() {
it('getConfig, custom config with comments', function() {
assert.deepEqual(getConfig('./test/configs/comment.json'), {
relativePath: 'test/configs/comment.json',
data: { report: ['console'] }
});
});
it('getConfig, default config', function() {
const result = getConfig(null);
assert.equal(result.relativePath, '.yaspellerrc');
assert.ok(Object.keys(result.data).length);
});
it('getConfig, throw', function() {
getConfig('test/configs/error_parsing.json');
assert.equal(process.exit.args[0], exitCodes.ERROR_CONFIG);
});
it('getConfig, unknown properties', function() {
getConfig('test/configs/unknown_properties.json');
const count = console.error.args.length;
assert.equal(count, 2);
});
it('getConfig, wrong property type', function() {
getConfig('test/configs/wrong_prop_type.json');
const count = console.error.args.length;
assert.equal(count, 2);
});
it('getConfig from package.json', function() {
process.chdir('./test/configs');
assert.deepEqual(getConfig(null).data, { lang: 'en,ru' });
process.chdir('../../');
});
it('getConfig from yaspellerrc.js', function() {
process.chdir('./test/configs/rc.js');
assert.deepEqual(getConfig(null).data, { report: ['rc.js'] });
process.chdir('../../../');
});
it('getConfig from yaspellerrc.json', function() {
process.chdir('./test/configs/json');
assert.deepEqual(getConfig(null).data, { report: ['json'] });
process.chdir('../../../');
});
it('getConfig from yaspellerrc', function() {
process.chdir('./test/configs/rc');
assert.deepEqual(getConfig(null).data, { report: ['rc'] });
process.chdir('../../../');
});
});