Skip to content

Commit c5b5550

Browse files
committed
🔨 Refactor: add datetime to testfiles
1 parent 2fba853 commit c5b5550

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

test/getConfig.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import getConfig from '../lib/getConfig';
99
const cwd = process.cwd();
1010
const homedir = os.homedir();
1111
const fixtures = path.join(cwd, 'test', 'fixtures');
12-
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);
1315

1416
let globalExist = false;
1517

@@ -18,13 +20,13 @@ let globalExist = false;
1820
test.before(() => {
1921
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
2022
globalExist = true;
21-
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`));
2224
}
2325
});
2426

2527
test.after(() => {
2628
if (globalExist) {
27-
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'));
2830
}
2931
});
3032

@@ -43,14 +45,14 @@ test('read config from package.json', (t) => {
4345
packageJson.sgc = sgcrc;
4446

4547
// manipulate local package
46-
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`));
4749
fs.writeFileSync(path.join(cwd, 'package.json'), JSON.stringify(packageJson));
4850

4951
t.deepEqual(getConfig(), sgcrc);
5052

5153
// revert local package
5254
fs.removeSync(path.join(cwd, 'package.json'));
53-
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'));
5456
});
5557

5658
test('read global config', (t) => {

test/prompConfig.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import { choices, questions } from '../lib/promptConfig';
1010

1111
const cwd = process.cwd();
1212
const homedir = os.homedir();
13-
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
13+
const date = new Date();
14+
const datetime = date.toISOString().slice(0, 10);
15+
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 4);
1416

1517
let globalExist = false;
1618

@@ -19,13 +21,13 @@ let globalExist = false;
1921
test.before(() => {
2022
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
2123
globalExist = true;
22-
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}.back`));
24+
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}-${datetime}.back`));
2325
}
2426
});
2527

2628
test.after(() => {
2729
if (globalExist) {
28-
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}.back`), path.join(homedir, '.sgcrc'));
30+
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}-${datetime}.back`), path.join(homedir, '.sgcrc'));
2931
}
3032
});
3133

0 commit comments

Comments
 (0)