Skip to content

Commit a7ed0ec

Browse files
aichbauerJPeer264
authored andcommitted
✅ Test: update test for package.json, fs-extra
1 parent ca85dad commit a7ed0ec

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

test/getConfig.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava';
22
import path from 'path';
33
import json from 'json-extra';
4-
import fs from 'fs';
4+
import fs from 'fs-extra';
55
import getConfig from '../lib/getConfig';
66

77
const cwd = process.cwd();
@@ -20,24 +20,11 @@ test('read config from package.json', (t) => {
2020
let packageJson = json.readToObjSync(path.join(cwd, 'package.json'));
2121
packageJson.sgc = sgcrc;
2222

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-
});
23+
fs.createReadStream(cwd + '/package.json')
24+
.pipe(fs.createWriteStream(cwd + '/package.json.back'));
25+
fs.unlinkSync(cwd + '/package.json');
26+
fs.writeFileSync(cwd + '/package.json', JSON.stringify(packageJson));
27+
t.deepEqual(getConfig(), sgcrc);
28+
fs.unlinkSync(cwd + '/package.json');
29+
fs.renameSync(cwd + '/package.json.back', cwd + '/package.json');
4330
});

0 commit comments

Comments
 (0)