|
1 | 1 | const path = require('path'); |
2 | | -const _ = require('lodash'); |
| 2 | +const config = require('../../src/config'); |
3 | 3 | const mergeConfig = require('../../src/merge_config'); |
4 | 4 |
|
5 | | -test('bad config', async function() { |
6 | | - try { |
7 | | - await mergeConfig({ config: 'DOES-NOT-EXIST' }); |
8 | | - } catch (err) { |
9 | | - expect(err).toBeTruthy(); |
10 | | - } |
11 | | -}); |
| 5 | +describe('single config tests', function () { |
| 6 | + beforeEach(function () { |
| 7 | + config.reset(); |
| 8 | + }); |
12 | 9 |
|
13 | | -test('right merging package configuration', async function() { |
14 | | - // Omit configuration from output, for simplicity |
15 | | - const nc = _.curryRight(_.omit, 2)([ |
16 | | - 'config', |
17 | | - 'no-package', |
18 | | - 'parseExtension', |
19 | | - 'project-homepage', |
20 | | - 'project-version', |
21 | | - 'project-description' |
22 | | - ]); |
23 | | - return mergeConfig({ |
24 | | - config: path.join(__dirname, '../config_fixture/config.json'), |
25 | | - 'no-package': true, |
26 | | - 'project-name': 'cool Documentation' |
27 | | - }) |
28 | | - .then(nc) |
29 | | - .then(res => { |
30 | | - expect(res).toEqual({ |
31 | | - 'project-name': 'cool Documentation', |
32 | | - foo: 'bar' |
33 | | - }); |
| 10 | + test('Should be failed on bad config', async function () { |
| 11 | + try { |
| 12 | + await mergeConfig({ config: 'DOES-NOT-EXIST' }); |
| 13 | + } catch (err) { |
| 14 | + expect(err).toBeTruthy(); |
| 15 | + return; |
| 16 | + } |
| 17 | + return Promise.reject(new Error('should be failed on bad config')); |
| 18 | + }); |
| 19 | + |
| 20 | + test('right merging package configuration', async function () { |
| 21 | + const list = [ |
| 22 | + 'config', |
| 23 | + 'no-package', |
| 24 | + 'parseExtension', |
| 25 | + 'project-homepage', |
| 26 | + 'project-version', |
| 27 | + 'project-description' |
| 28 | + ]; |
| 29 | + await mergeConfig({ |
| 30 | + config: path.join(__dirname, '../config_fixture/config.json'), |
| 31 | + 'no-package': true, |
| 32 | + 'project-name': 'cool Documentation' |
34 | 33 | }); |
35 | | -}); |
36 | 34 |
|
37 | | -test('nc(mergeConfig)', async function() { |
38 | | - // Omit configuration from output, for simplicity |
39 | | - const nc = _.curryRight(_.omit, 2)([ |
| 35 | + const res = config.globalConfig; |
| 36 | + list.forEach(key => delete res[key]); |
| 37 | + expect(res).toEqual({ |
| 38 | + 'project-name': 'cool Documentation', |
| 39 | + foo: 'bar' |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + const list = [ |
40 | 44 | 'config', |
41 | 45 | 'no-package', |
42 | 46 | 'parseExtension', |
43 | 47 | 'project-homepage', |
44 | 48 | 'project-name', |
45 | 49 | 'project-version', |
46 | 50 | 'project-description' |
47 | | - ]); |
| 51 | + ]; |
48 | 52 |
|
49 | | - return Promise.all( |
| 53 | + [ |
| 54 | + [ |
| 55 | + { config: path.join(__dirname, '../config_fixture/config.json') }, |
| 56 | + { foo: 'bar' } |
| 57 | + ], |
| 58 | + [ |
| 59 | + { |
| 60 | + passThrough: true, |
| 61 | + config: path.join(__dirname, '../config_fixture/config.json') |
| 62 | + }, |
| 63 | + { foo: 'bar', passThrough: true } |
| 64 | + ], |
| 65 | + [ |
| 66 | + { |
| 67 | + config: path.join(__dirname, '../config_fixture/config_comments.json') |
| 68 | + }, |
| 69 | + { foo: 'bar' } |
| 70 | + ], |
| 71 | + [ |
| 72 | + { config: path.join(__dirname, '../config_fixture/config.yaml') }, |
| 73 | + { foo: 'bar' } |
| 74 | + ], |
50 | 75 | [ |
51 | | - [ |
52 | | - { config: path.join(__dirname, '../config_fixture/config.json') }, |
53 | | - { foo: 'bar' } |
54 | | - ], |
55 | | - [ |
56 | | - { |
57 | | - passThrough: true, |
58 | | - config: path.join(__dirname, '../config_fixture/config.json') |
59 | | - }, |
60 | | - { foo: 'bar', passThrough: true } |
61 | | - ], |
62 | | - [ |
63 | | - { |
64 | | - config: path.join(__dirname, '../config_fixture/config_comments.json') |
65 | | - }, |
66 | | - { foo: 'bar' } |
67 | | - ], |
68 | | - [ |
69 | | - { config: path.join(__dirname, '../config_fixture/config.yaml') }, |
70 | | - { foo: 'bar' } |
71 | | - ], |
72 | | - [ |
73 | | - { config: path.join(__dirname, '../config_fixture/config.yml') }, |
74 | | - { foo: 'bar' } |
75 | | - ], |
76 | | - [ |
77 | | - { config: path.join(__dirname, '../config_fixture/config') }, |
78 | | - { foo: 'bar' } |
79 | | - ], |
80 | | - [ |
81 | | - { config: path.join(__dirname, '../config_fixture/config_links.yml') }, |
82 | | - { foo: 'hello [link](https://github.com/my/link) world' } |
83 | | - ], |
84 | | - [ |
85 | | - { config: path.join(__dirname, '../config_fixture/config_file.yml') }, |
86 | | - { |
87 | | - toc: [ |
88 | | - { |
89 | | - name: 'snowflake', |
90 | | - file: path.join(__dirname, '../fixture/snowflake.md') |
91 | | - } |
92 | | - ] |
93 | | - } |
94 | | - ] |
95 | | - ].map(pair => |
96 | | - mergeConfig(Object.assign(pair[0], { 'no-package': true })) |
97 | | - .then(nc) |
98 | | - .then(res => { |
99 | | - expect(res).toEqual(pair[1]); |
100 | | - }) |
101 | | - ) |
102 | | - ); |
| 76 | + { config: path.join(__dirname, '../config_fixture/config.yml') }, |
| 77 | + { foo: 'bar' } |
| 78 | + ], |
| 79 | + [ |
| 80 | + { config: path.join(__dirname, '../config_fixture/config') }, |
| 81 | + { foo: 'bar' } |
| 82 | + ], |
| 83 | + [ |
| 84 | + { |
| 85 | + config: path.join(__dirname, '../config_fixture/config_links.yml') |
| 86 | + }, |
| 87 | + { foo: 'hello [link](https://github.com/my/link) world' } |
| 88 | + ], |
| 89 | + [ |
| 90 | + { config: path.join(__dirname, '../config_fixture/config_file.yml') }, |
| 91 | + { |
| 92 | + toc: [ |
| 93 | + { |
| 94 | + name: 'snowflake', |
| 95 | + file: path.join(__dirname, '../fixture/snowflake.md') |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + ] |
| 100 | + ].forEach((pair, index) => { |
| 101 | + test(`nc(mergeConfig) ${index}`, async function () { |
| 102 | + await mergeConfig(Object.assign(pair[0], { 'no-package': true })); |
| 103 | + const res = config.globalConfig; |
| 104 | + list.forEach(key => delete res[key]); |
| 105 | + expect(res).toEqual(pair[1]); |
| 106 | + }); |
| 107 | + }); |
103 | 108 | }); |
0 commit comments