Skip to content

Commit 9814eef

Browse files
aichbauerJPeer264
authored andcommitted
✅ Test: add test for .sgcrc_default, updated test for package.json .sgc
1 parent 4de8063 commit 9814eef

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

test/getConfig.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
import test from 'ava';
22
import path from 'path';
33
import json from 'json-extra';
4+
import fs from 'fs';
45
import getConfig from '../lib/getConfig';
56

67
const cwd = process.cwd();
78
const fixtures = path.join(cwd, 'test', 'fixtures');
89

910
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')));
1116
});
1217

1318
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+
});
1543
});

0 commit comments

Comments
 (0)