|
1 | 1 | import { assert } from 'chai'; |
| 2 | +import chalk from 'chalk'; |
2 | 3 | import fs from 'fs'; |
3 | 4 | import YAML from 'yamljs'; |
4 | 5 | import * as utils from '../lib/src/_utils'; |
@@ -142,18 +143,34 @@ describe('_utils.js', () => { |
142 | 143 | b: 2 |
143 | 144 | }; |
144 | 145 |
|
| 146 | + const customFilename = process.cwd() + '/test/.temp/.custom-grenrc'; |
| 147 | + const customFileContent = { |
| 148 | + c: 3, |
| 149 | + d: 4 |
| 150 | + }; |
| 151 | + |
145 | 152 | beforeEach(() => { |
146 | 153 | fs.writeFileSync(filename, JSON.stringify(fileContent)); |
| 154 | + fs.writeFileSync(customFilename, JSON.stringify(customFileContent)); |
147 | 155 | }); |
148 | 156 |
|
149 | 157 | it('Should always return an Object', () => { |
150 | 158 | assert.isOk(typeof utils.getConfigFromFile(process.cwd() + '/test/.temp') === 'object', 'The type is an object'); |
151 | 159 | assert.deepEqual(utils.getConfigFromFile(process.cwd() + '/test/.temp'), fileContent, 'Given the right path'); |
| 160 | + assert.deepEqual(utils.getConfigFromFile(process.cwd() + '/test/.temp', '.custom-grenrc'), customFileContent, 'Given a custom path'); |
152 | 161 | assert.deepEqual(utils.getConfigFromFile(process.cwd() + '/test'), {}, 'Given a path with no config file'); |
153 | 162 | }); |
154 | 163 |
|
| 164 | + it('Should throw on non-existent custom config file', () => { |
| 165 | + assert.throws( |
| 166 | + () => utils.getConfigFromFile(process.cwd() + '/test/.temp', '.non-existing-grenrc'), |
| 167 | + chalk.red('Could not find custom config file: .non-existing-grenrc') |
| 168 | + ); |
| 169 | + }); |
| 170 | + |
155 | 171 | afterEach(() => { |
156 | 172 | fs.unlinkSync(filename); |
| 173 | + fs.unlinkSync(customFilename); |
157 | 174 | }); |
158 | 175 | }); |
159 | 176 |
|
|
0 commit comments