1- import fs from 'fs-extra' ;
21import os from 'os' ;
32import test from 'ava' ;
43import path from 'path' ;
4+ import fs from 'fs-extra' ;
55import json from 'json-extra' ;
6+
67import getConfig from '../lib/getConfig' ;
78
89const cwd = process . cwd ( ) ;
910const homedir = os . homedir ( ) ;
1011const fixtures = path . join ( cwd , 'test' , 'fixtures' ) ;
11- const randomString = Math . random ( ) . toString ( 36 ) . replace ( / [ ^ a - z ] + / g, '' ) . substr ( 0 , 10 ) ;
12+ const date = new Date ( ) ;
13+ const datetime = date . toISOString ( ) . slice ( 0 , 10 ) ;
14+ const randomString = Math . random ( ) . toString ( 36 ) . replace ( / [ ^ a - z ] + / g, '' ) . substr ( 0 , 4 ) ;
1215
1316let globalExist = false ;
1417
@@ -17,13 +20,13 @@ let globalExist = false;
1720test . before ( ( ) => {
1821 if ( fs . existsSync ( path . join ( homedir , '.sgcrc' ) ) ) {
1922 globalExist = true ;
20- fs . renameSync ( path . join ( homedir , '.sgcrc' ) , path . join ( homedir , `.sgcrc.${ randomString } .back` ) ) ;
23+ fs . renameSync ( path . join ( homedir , '.sgcrc' ) , path . join ( homedir , `.sgcrc.${ randomString } - ${ datetime } .back` ) ) ;
2124 }
2225} ) ;
2326
2427test . after ( ( ) => {
2528 if ( globalExist ) {
26- fs . renameSync ( path . join ( homedir , `.sgcrc.${ randomString } .back` ) , path . join ( homedir , '.sgcrc' ) ) ;
29+ fs . renameSync ( path . join ( homedir , `.sgcrc.${ randomString } - ${ datetime } .back` ) , path . join ( homedir , '.sgcrc' ) ) ;
2730 }
2831} ) ;
2932
@@ -42,14 +45,14 @@ test('read config from package.json', (t) => {
4245 packageJson . sgc = sgcrc ;
4346
4447 // manipulate local package
45- fs . renameSync ( path . join ( cwd , 'package.json' ) , path . join ( cwd , `package.json.${ randomString } .back` ) ) ;
48+ fs . renameSync ( path . join ( cwd , 'package.json' ) , path . join ( cwd , `package.json.${ randomString } - ${ datetime } .back` ) ) ;
4649 fs . writeFileSync ( path . join ( cwd , 'package.json' ) , JSON . stringify ( packageJson ) ) ;
4750
4851 t . deepEqual ( getConfig ( ) , sgcrc ) ;
4952
5053 // revert local package
5154 fs . removeSync ( path . join ( cwd , 'package.json' ) ) ;
52- fs . renameSync ( path . join ( cwd , `package.json.${ randomString } .back` ) , path . join ( cwd , 'package.json' ) ) ;
55+ fs . renameSync ( path . join ( cwd , `package.json.${ randomString } - ${ datetime } .back` ) , path . join ( cwd , 'package.json' ) ) ;
5356} ) ;
5457
5558test ( 'read global config' , ( t ) => {
0 commit comments