Skip to content
Permalink
Browse files

Build: Cleanup for code coverage (fixes #4983)

  • Loading branch information...
gyandeeps committed Jan 17, 2016
1 parent 4bfa496 commit d3f4bdd8ee52531c0b1404ad7e6c8bb9e00566ee
@@ -61,7 +61,7 @@ var NODE = "node ", // intentional extra space
JS_FILES = find("lib/").filter(fileType("js")).join(" "),
JSON_FILES = find("conf/").filter(fileType("json")).join(" ") + " .eslintrc",
MARKDOWN_FILES_ARRAY = find("docs/").concat(ls(".")).filter(fileType("md")),
TEST_FILES = find("tests/lib/").filter(fileType("js")).join(" "),
TEST_FILES = getTestFilePatterns(),
/* eslint-enable no-use-before-define */

// Regex
@@ -75,6 +75,24 @@ var NODE = "node ", // intentional extra space
// Helpers
//------------------------------------------------------------------------------

/**
* Generates file patterns for test files
* @returns {string} test file patterns
* @private
*/
function getTestFilePatterns() {
var testLibPath = "tests/lib/";

return ls(testLibPath).filter(function(pathToCheck) {
return test("-d", testLibPath + pathToCheck);
}).reduce(function(initialValue, currentValues) {
if (currentValues !== "rules") {
initialValue.push(testLibPath + currentValues + "/**/*.js");
}
return initialValue;
}, [testLibPath + "rules/**/*.js", testLibPath + "*.js"]).join(" ");
}

/**
* Generates a function that matches files with a particular extension.
* @param {string} extension The file extension (i.e. "js")
@@ -22,9 +22,6 @@ module.exports = function(context) {
location = {column: 1},
linebreakStyle = context.options[0] || "unix",
linebreak = linebreakStyle === "unix" ? "\n" : "\r\n";
if (src.length === 0) {
return;
}

if (src[src.length - 1] !== "\n") {
// file is not newline-terminated
@@ -30,9 +30,6 @@ module.exports = function(context) {
checkForViolation(node.id);
},
"ArrowFunctionExpression": function(node) {
if (node.id) {
checkForViolation(node.id);
}
[].map.call(node.params, checkForViolation);
},
"FunctionExpression": function(node) {
@@ -25,7 +25,7 @@ module.exports = {
* @param {function} method - A test logic.
* @returns {any} The returned value with the test logic.
*/
describe: (typeof describe === "function") ? describe : function(text, method) {
describe: (typeof describe === "function") ? describe : /* istanbul ignore next */ function(text, method) {
return method.apply(this);
},

@@ -35,7 +35,7 @@ module.exports = {
* @param {function} method - A test logic.
* @returns {any} The returned value with the test logic.
*/
it: (typeof it === "function") ? it : function(text, method) {
it: (typeof it === "function") ? it : /* istanbul ignore next */ function(text, method) {
return method.apply(this);
},

@@ -181,11 +181,11 @@ RuleTester.resetDefaultConfig = function() {
};

// default separators for testing
RuleTester.describe = (typeof describe === "function") ? describe : function(text, method) {
RuleTester.describe = (typeof describe === "function") ? describe : /* istanbul ignore next */ function(text, method) {
return method.apply(this);
};

RuleTester.it = (typeof it === "function") ? it : function(text, method) {
RuleTester.it = (typeof it === "function") ? it : /* istanbul ignore next */ function(text, method) {
return method.apply(this);
};

@@ -33,6 +33,7 @@ var experimentalKeys = {
*/
function installKeys(keys) {
for (var key in keys) {
/* istanbul ignore else */
if (keys.hasOwnProperty(key)) {
estraverse.Syntax[key] = key;
if (keys[key]) {
@@ -33,20 +33,18 @@ debug = debug("eslint:glob-util");
*
* Also makes sure all path separators are POSIX style for `glob` compatibility.
*
* @param {string[]} [extensions] An array of accepted extensions
* @param {string[]} extensions An array of accepted extensions
* @returns {Function} A function that takes a pathname and returns a glob that
* matches all files with the provided extensions if
* pathname is a directory.
*/
function processPath(extensions) {
var suffix = "/**";

if (extensions) {
if (extensions.length === 1) {
suffix += "/*." + extensions[0];
} else {
suffix += "/*.{" + extensions.join(",") + "}";
}
if (extensions.length === 1) {
suffix += "/*." + extensions[0];
} else {
suffix += "/*.{" + extensions.join(",") + "}";
}

/**
@@ -129,7 +127,7 @@ function listFilesToProcess(globPatterns, options) {
ignoredPaths = new IgnoredPaths(options);
ignoredPathsList = ignoredPaths.ig.custom[rulesKey].map(function(rule) {
return rule.pattern;
}) || [];
});
globOptions = {
nodir: true,
ignore: ignoredPathsList
@@ -161,8 +161,8 @@ SourceCode.prototype = {
*/
getText: function(node, beforeCount, afterCount) {
if (node) {
return (this.text !== null) ? this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0),
node.range[1] + (afterCount || 0)) : null;
return this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0),
node.range[1] + (afterCount || 0));
} else {
return this.text;
}
@@ -95,10 +95,9 @@
"phantomjs": "1.9.18",
"phantomjs-polyfill": "0.0.1",
"proxyquire": "^1.0.0",
"rewire": "^2.3.4",
"semver": "^5.0.3",
"shelljs-nodecli": "~0.1.0",
"sinon": "1.17.2",
"sinon": "^1.17.2",
"through": "^2.3.6",
"tmp": "0.0.28"
},

This file was deleted.

Oops, something went wrong.
@@ -215,6 +215,16 @@ describe("ConfigFile", function() {

describe("load", function() {

it("should throw error if file doesnt exist", function() {
assert.throws(function() {
ConfigFile.load(getFixturePath("legacy/nofile.js"));
});

assert.throws(function() {
ConfigFile.load(getFixturePath("legacy/package.json"));
});
});

it("should load information from a legacy file", function() {
var config = ConfigFile.load(getFixturePath("legacy/.eslintrc"));
assert.deepEqual(config, {
@@ -464,6 +474,12 @@ describe("ConfigFile", function() {
});

});

it("should throw error if file extension is not valid", function() {
assert.throws(function() {
ConfigFile.write({}, getFixturePath("yaml/.eslintrc.class"));
});
});
});

});
@@ -13,7 +13,10 @@
var assert = require("chai").assert,
assign = require("object-assign"),
environments = require("../../../conf/environments"),
ConfigOps = require("../../../lib/config/config-ops");
ConfigOps = require("../../../lib/config/config-ops"),
proxyquire = require("proxyquire");

proxyquire = proxyquire.noCallThru().noPreserveCache();

//------------------------------------------------------------------------------
// Tests
@@ -83,6 +86,39 @@ describe("ConfigOps", function() {

describe("createEnvironmentConfig()", function() {

it("should return empty config if called without any config", function() {
var config = ConfigOps.createEnvironmentConfig(null);
assert.deepEqual(config, {
globals: {},
env: {},
rules: {},
parserOptions: {}
});
});

it("should return correct config for env with no globals", function() {
var stubbedConfigOps = proxyquire("../../../lib/config/config-ops", {
"../../conf/environments": {
test: {
parserOptions: {
modules: true
}
}
}
});
var config = stubbedConfigOps.createEnvironmentConfig({ test: true });
assert.deepEqual(config, {
globals: {},
env: {
test: true
},
rules: {},
parserOptions: {
modules: true
}
});
});

it("should create the correct config for Node.js environment", function() {
var config = ConfigOps.createEnvironmentConfig({ node: true });
assert.deepEqual(config, {
@@ -26,7 +26,8 @@ ruleTester.run("no-empty-pattern", rule, {
{ code: "var {a, b = {}} = foo;", parserOptions: { ecmaVersion: 6 }},
{ code: "var {a = []} = foo;", parserOptions: { ecmaVersion: 6 }},
{ code: "function foo({a = {}}) {}", parserOptions: { ecmaVersion: 6 }},
{ code: "function foo({a = []}) {}", parserOptions: { ecmaVersion: 6 }}
{ code: "function foo({a = []}) {}", parserOptions: { ecmaVersion: 6 }},
{ code: "var [a] = foo", parserOptions: { ecmaVersion: 6 }}
],

// Examples of code that should trigger the rule
@@ -52,6 +52,10 @@ ruleTester.run("no-useless-constructor", rule, {
{
code: "class A extends B { constructor(...args){ super(...args); doSomething(); } }",
parserOptions: { ecmaVersion: 6 }
},
{
code: "class A { dummyMethod(){ doSomething(); } }",
parserOptions: { ecmaVersion: 6 }
}
],
invalid: [
@@ -53,6 +53,16 @@ ruleTester.run("require-jsdoc", rule, {
}
}]
},
{
code: "var myFunction = function() {}",
options: [{
"require": {
"FunctionDeclaration": false,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
},
{
code:
"/**\n" +
@@ -140,6 +150,21 @@ ruleTester.run("require-jsdoc", rule, {
"ClassDeclaration": true
}
}]
},
{
code:
"class A {\n" +
" constructor(xs) {\n" +
" this.a = xs;" +
" }\n" +
"}",
parserOptions: { ecmaVersion: 6 },
options: [{
"require": {
"MethodDefinition": false,
"ClassDeclaration": false
}
}]
}
],

@@ -214,5 +214,20 @@ describe("globUtil", function() {
assert.equal(result.length, 0);
});

it("should return a file only once if listed in more than 1 pattern", function() {
var patterns = [
getFixturePath("glob-util", "one-js-file", "**/*.js"),
getFixturePath("glob-util", "one-js-file", "baz.js")
];
var result = globUtil.listFilesToProcess(patterns, {
cwd: path.join(fixtureDir, "..")
});

var file1 = getFixturePath("glob-util", "one-js-file", "baz.js");

assert.isArray(result);
assert.deepEqual(result, [file1]);
});

});
});
Oops, something went wrong.

0 comments on commit d3f4bdd

Please sign in to comment.
You can’t perform that action at this time.