Skip to content

Commit 5e9163e

Browse files
authored
Merge pull request #13 from JPeer264/fix/global-test
Fix/global test
2 parents 87f95ae + 6bbb556 commit 5e9163e

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
"bugs": {
3535
"url": "https://github.com/JPeer264/node-semantic-git-commit-cli/issues"
3636
},
37+
"keywords": [
38+
"semantic",
39+
"git",
40+
"commits",
41+
"cli",
42+
"fast",
43+
"enhance",
44+
"workflow"
45+
],
3746
"homepage": "https://github.com/JPeer264/node-semantic-git-commit-cli#readme",
3847
"devDependencies": {
3948
"ava": "^0.18.2",

test/getConfig.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ import getConfig from '../lib/getConfig';
88
const cwd = process.cwd();
99
const homedir = os.homedir();
1010
const fixtures = path.join(cwd, 'test', 'fixtures');
11+
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
12+
13+
let globalExist = false;
14+
15+
16+
// rename global .sgcrc
17+
test.before(() => {
18+
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
19+
globalExist = true;
20+
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}.back`));
21+
}
22+
});
23+
24+
test.after(() => {
25+
if (globalExist) {
26+
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}.back`), path.join(homedir, '.sgcrc'));
27+
}
28+
});
1129

1230
test('read config from a specific path', (t) => {
1331
t.deepEqual(getConfig(path.join(fixtures, '.sgcrc')), json.readToObjSync(path.join(fixtures, '.sgcrc')));
@@ -20,31 +38,24 @@ test('read config from a .sgcrc_default', (t) => {
2038
test('read config from package.json', (t) => {
2139
const sgcrc = json.readToObjSync(path.join(fixtures, '.sgcrc'));
2240
const packageJson = json.readToObjSync(path.join(cwd, 'package.json'));
23-
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
41+
2442
packageJson.sgc = sgcrc;
2543

44+
// manipulate local package
2645
fs.renameSync(path.join(cwd, 'package.json'), path.join(cwd, `package.json.${randomString}.back`));
2746
fs.writeFileSync(path.join(cwd, 'package.json'), JSON.stringify(packageJson));
47+
2848
t.deepEqual(getConfig(), sgcrc);
49+
50+
// revert local package
2951
fs.removeSync(path.join(cwd, 'package.json'));
3052
fs.renameSync(path.join(cwd, `package.json.${randomString}.back`), path.join(cwd, 'package.json'));
3153
});
3254

3355
test('read global config', (t) => {
34-
let globalExist = false;
3556
const sgcrc = json.readToObjSync(path.join(fixtures, '.sgcrc'));
36-
const randomString = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
37-
38-
if (fs.existsSync(path.join(homedir, '.sgcrc'))) {
39-
globalExist = true;
40-
fs.renameSync(path.join(homedir, '.sgcrc'), path.join(homedir, `.sgcrc.${randomString}.back`));
41-
}
4257

4358
fs.writeFileSync(path.join(homedir, '.sgcrc'), JSON.stringify(sgcrc));
4459
t.deepEqual(getConfig(), sgcrc);
4560
fs.removeSync(path.join(homedir, '.sgcrc'));
46-
47-
if (globalExist) {
48-
fs.renameSync(path.join(homedir, `.sgcrc.${randomString}.back`), path.join(homedir, '.sgcrc'));
49-
}
5061
});

0 commit comments

Comments
 (0)