|
1 | 1 | import test from 'ava'; |
2 | 2 | import path from 'path'; |
3 | 3 | import json from 'json-extra'; |
| 4 | +import fs from 'fs'; |
4 | 5 | import getConfig from '../lib/getConfig'; |
5 | 6 |
|
6 | 7 | const cwd = process.cwd(); |
7 | 8 | const fixtures = path.join(cwd, 'test', 'fixtures'); |
8 | 9 |
|
9 | 10 | test('read config from a specific path', (t) => { |
10 | | - t.deepEqual(getConfig(path.join(fixtures, '.sgcrc')), json.readToObjSync(path.join(fixtures, '.sgcrc'))) |
| 11 | + t.deepEqual(getConfig(path.join(fixtures, '.sgcrc')), json.readToObjSync(path.join(fixtures, '.sgcrc'))); |
| 12 | +}); |
| 13 | + |
| 14 | +test('read config from a .sgcrc_default', (t) => { |
| 15 | + t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default'))); |
11 | 16 | }); |
12 | 17 |
|
13 | 18 | test('read config from package.json', (t) => { |
14 | | - t.deepEqual(getConfig(), json.readToObjSync(path.join(fixtures, '.sgcrc'))) |
| 19 | + let sgcrc = json.readToObjSync(path.join(fixtures, '.sgcrc')); |
| 20 | + let packageJson = json.readToObjSync(path.join(cwd, 'package.json')); |
| 21 | + packageJson.sgc = sgcrc; |
| 22 | + |
| 23 | + // copy package.json to package.json.back |
| 24 | + Promise.resolve(fs.createReadStream(cwd + '/package.json') |
| 25 | + .pipe(fs.createWriteStream(cwd + '/package.json.back'))) |
| 26 | + .then(() => { |
| 27 | + // delete package.json |
| 28 | + fs.unlink(cwd + '/package.json'); |
| 29 | + }) |
| 30 | + .then(() => { |
| 31 | + // write new package.json with the sgc property |
| 32 | + fs.writeFile(cwd + '/package.json', JSON.stringify(packageJson), () => { |
| 33 | + // perform test |
| 34 | + t.deepEqual(getConfig(), sgcrc); |
| 35 | + }); |
| 36 | + }).then(() => { |
| 37 | + // delete package.json |
| 38 | + fs.unlink(cwd + '/package.json'); |
| 39 | + }).then(() => { |
| 40 | + // restore package.json from package.json.back |
| 41 | + fs.rename(cwd + '/package.json.back', cwd + '/package.json'); |
| 42 | + }); |
15 | 43 | }); |
0 commit comments