Skip to content

Commit 0ddfa20

Browse files
authored
fix(tests): fix tests when a global config is present (#405)
Closes #211
1 parent efc58cd commit 0ddfa20

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build:watch": "babel --watch src --out-dir dist",
1111
"prepublish": "not-in-install && npm run build || true",
1212
"report-coverage": "nyc report --reporter=lcov | codecov",
13+
"write-coverage": "nyc report --reporter=lcov",
1314
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
1415
"start": "npm run test:watch",
1516
"test": "nyc --require babel-core/register _mocha -- test/tests/index.js",

src/common/util.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export {
77
getParsedPackageJsonFromPath,
88
isArray,
99
isFunction,
10-
isString
10+
isString,
11+
isInTest
1112
}
1213

1314
/**
@@ -80,3 +81,7 @@ function isString(str) {
8081
return Object.prototype.toString.call(str) == '[object String]';
8182
}
8283
}
84+
85+
function isInTest() {
86+
return typeof global.it === 'function';
87+
}

src/configLoader/loader.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import path from 'path';
22

33
import {findup, getContent} from '../configLoader';
4+
import {isInTest} from '../common/util.js';
45

56
export default loader;
67

78
/**
89
* Command line config helpers
9-
* Shamelessly ripped from with slight modifications:
10+
* Shamelessly ripped from with slight modifications:
1011
* https://github.com/jscs-dev/node-jscs/blob/master/lib/cli-config.js
1112
*/
1213

@@ -27,7 +28,7 @@ function loader(configs, config, cwd) {
2728

2829
content = getContent(
2930
findup(configs, { nocase: true, cwd: directory }, function(configPath) {
30-
if (path.basename(configPath) === 'package.json') {
31+
if (path.basename(configPath) === 'package.json') {
3132
// return !!this.getContent(configPath);
3233
}
3334

@@ -38,20 +39,22 @@ function loader(configs, config, cwd) {
3839
if (content) {
3940
return content;
4041
}
41-
42-
// Try to load standard configs from home dir
43-
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
44-
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
45-
if (!directoryArr[i]) {
46-
continue;
47-
}
48-
49-
for (var j = 0, len = configs.length; j < len; j++) {
50-
content = getContent(configs[j], directoryArr[i]);
51-
52-
if (content) {
53-
return content;
54-
}
55-
}
42+
/* istanbul ignore if */
43+
if(!isInTest()) {
44+
// Try to load standard configs from home dir
45+
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
46+
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
47+
if (!directoryArr[i]) {
48+
continue;
49+
}
50+
51+
for (var j = 0, len = configs.length; j < len; j++) {
52+
content = getContent(configs[j], directoryArr[i]);
53+
54+
if (content) {
55+
return content;
56+
}
57+
}
58+
}
5659
}
57-
}
60+
}

0 commit comments

Comments
 (0)