Skip to content

Commit fa7fb37

Browse files
committed
✅ Test: add before and after test
1 parent c2de1b6 commit fa7fb37

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/prompConfig.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
import fs from 'fs-extra';
12
import test from 'ava';
23
import path from 'path';
34
import chalk from 'chalk';
45
import json from 'json-extra';
6+
import os from 'os';
57
import getConfig from '../lib/getConfig';
68
import { choices, questions } from '../lib/promptConfig';
79

810
const cwd = process.cwd();
11+
const homedir = os.homedir();
12+
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
13+
14+
let globalExist = false;
15+
16+
17+
// rename global .sgcrc
18+
test.before(() => {
19+
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
20+
globalExist = true;
21+
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}.back`));
22+
}
23+
});
24+
25+
test.after(() => {
26+
if (globalExist) {
27+
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}.back`), path.join(homedir, '.sgcrc'));
28+
}
29+
});
930

1031
test('get configuration file equals .sgcrc_default', (t) => {
1132
t.deepEqual(getConfig(), json.readToObjSync(path.join(cwd, '.sgcrc_default')));

0 commit comments

Comments
 (0)