Skip to content

Commit

Permalink
fix(tests): fix tests when a global config is present (#405)
Browse files Browse the repository at this point in the history
Closes #211
  • Loading branch information
jimthedev authored Dec 19, 2016
1 parent efc58cd commit 0ddfa20
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build:watch": "babel --watch src --out-dir dist",
"prepublish": "not-in-install && npm run build || true",
"report-coverage": "nyc report --reporter=lcov | codecov",
"write-coverage": "nyc report --reporter=lcov",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"start": "npm run test:watch",
"test": "nyc --require babel-core/register _mocha -- test/tests/index.js",
Expand Down
7 changes: 6 additions & 1 deletion src/common/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export {
getParsedPackageJsonFromPath,
isArray,
isFunction,
isString
isString,
isInTest
}

/**
Expand Down Expand Up @@ -80,3 +81,7 @@ function isString(str) {
return Object.prototype.toString.call(str) == '[object String]';
}
}

function isInTest() {
return typeof global.it === 'function';
}
39 changes: 21 additions & 18 deletions src/configLoader/loader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import path from 'path';

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

export default loader;

/**
* Command line config helpers
* Shamelessly ripped from with slight modifications:
* Shamelessly ripped from with slight modifications:
* https://github.com/jscs-dev/node-jscs/blob/master/lib/cli-config.js
*/

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

content = getContent(
findup(configs, { nocase: true, cwd: directory }, function(configPath) {
if (path.basename(configPath) === 'package.json') {
if (path.basename(configPath) === 'package.json') {
// return !!this.getContent(configPath);
}

Expand All @@ -38,20 +39,22 @@ function loader(configs, config, cwd) {
if (content) {
return content;
}

// Try to load standard configs from home dir
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
if (!directoryArr[i]) {
continue;
}

for (var j = 0, len = configs.length; j < len; j++) {
content = getContent(configs[j], directoryArr[i]);

if (content) {
return content;
}
}
/* istanbul ignore if */
if(!isInTest()) {
// Try to load standard configs from home dir
var directoryArr = [process.env.USERPROFILE, process.env.HOMEPATH, process.env.HOME];
for (var i = 0, dirLen = directoryArr.length; i < dirLen; i++) {
if (!directoryArr[i]) {
continue;
}

for (var j = 0, len = configs.length; j < len; j++) {
content = getContent(configs[j], directoryArr[i]);

if (content) {
return content;
}
}
}
}
}
}

0 comments on commit 0ddfa20

Please sign in to comment.