11import test from 'ava' ;
22import path from 'path' ;
33import json from 'json-extra' ;
4- import fs from 'fs' ;
4+ import fs from 'fs-extra ' ;
55import getConfig from '../lib/getConfig' ;
66
77const 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