Skip to content

Commit

Permalink
Build: Cleanup for code coverage (fixes #4983)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyandeeps committed Jan 18, 2016
1 parent 4bfa496 commit d3f4bdd
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 56 deletions.
20 changes: 19 additions & 1 deletion Makefile.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var NODE = "node ", // intentional extra space
JS_FILES = find("lib/").filter(fileType("js")).join(" "), JS_FILES = find("lib/").filter(fileType("js")).join(" "),
JSON_FILES = find("conf/").filter(fileType("json")).join(" ") + " .eslintrc", JSON_FILES = find("conf/").filter(fileType("json")).join(" ") + " .eslintrc",
MARKDOWN_FILES_ARRAY = find("docs/").concat(ls(".")).filter(fileType("md")), 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 */ /* eslint-enable no-use-before-define */


// Regex // Regex
Expand All @@ -75,6 +75,24 @@ var NODE = "node ", // intentional extra space
// Helpers // 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. * Generates a function that matches files with a particular extension.
* @param {string} extension The file extension (i.e. "js") * @param {string} extension The file extension (i.e. "js")
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/eol-last.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ module.exports = function(context) {
location = {column: 1}, location = {column: 1},
linebreakStyle = context.options[0] || "unix", linebreakStyle = context.options[0] || "unix",
linebreak = linebreakStyle === "unix" ? "\n" : "\r\n"; linebreak = linebreakStyle === "unix" ? "\n" : "\r\n";
if (src.length === 0) {
return;
}


if (src[src.length - 1] !== "\n") { if (src[src.length - 1] !== "\n") {
// file is not newline-terminated // file is not newline-terminated
Expand Down
3 changes: 0 additions & 3 deletions lib/rules/no-shadow-restricted-names.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ module.exports = function(context) {
checkForViolation(node.id); checkForViolation(node.id);
}, },
"ArrowFunctionExpression": function(node) { "ArrowFunctionExpression": function(node) {
if (node.id) {
checkForViolation(node.id);
}
[].map.call(node.params, checkForViolation); [].map.call(node.params, checkForViolation);
}, },
"FunctionExpression": function(node) { "FunctionExpression": function(node) {
Expand Down
4 changes: 2 additions & 2 deletions lib/testers/event-generator-tester.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
* @param {function} method - A test logic. * @param {function} method - A test logic.
* @returns {any} The returned value with the 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); return method.apply(this);
}, },


Expand All @@ -35,7 +35,7 @@ module.exports = {
* @param {function} method - A test logic. * @param {function} method - A test logic.
* @returns {any} The returned value with the 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); return method.apply(this);
}, },


Expand Down
4 changes: 2 additions & 2 deletions lib/testers/rule-tester.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ RuleTester.resetDefaultConfig = function() {
}; };


// default separators for testing // 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); 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); return method.apply(this);
}; };


Expand Down
1 change: 1 addition & 0 deletions lib/util/estraverse.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var experimentalKeys = {
*/ */
function installKeys(keys) { function installKeys(keys) {
for (var key in keys) { for (var key in keys) {
/* istanbul ignore else */
if (keys.hasOwnProperty(key)) { if (keys.hasOwnProperty(key)) {
estraverse.Syntax[key] = key; estraverse.Syntax[key] = key;
if (keys[key]) { if (keys[key]) {
Expand Down
14 changes: 6 additions & 8 deletions lib/util/glob-util.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,20 +33,18 @@ debug = debug("eslint:glob-util");
* *
* Also makes sure all path separators are POSIX style for `glob` compatibility. * 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 * @returns {Function} A function that takes a pathname and returns a glob that
* matches all files with the provided extensions if * matches all files with the provided extensions if
* pathname is a directory. * pathname is a directory.
*/ */
function processPath(extensions) { function processPath(extensions) {
var suffix = "/**"; var suffix = "/**";


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


/** /**
Expand Down Expand Up @@ -129,7 +127,7 @@ function listFilesToProcess(globPatterns, options) {
ignoredPaths = new IgnoredPaths(options); ignoredPaths = new IgnoredPaths(options);
ignoredPathsList = ignoredPaths.ig.custom[rulesKey].map(function(rule) { ignoredPathsList = ignoredPaths.ig.custom[rulesKey].map(function(rule) {
return rule.pattern; return rule.pattern;
}) || []; });
globOptions = { globOptions = {
nodir: true, nodir: true,
ignore: ignoredPathsList ignore: ignoredPathsList
Expand Down
4 changes: 2 additions & 2 deletions lib/util/source-code.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ SourceCode.prototype = {
*/ */
getText: function(node, beforeCount, afterCount) { getText: function(node, beforeCount, afterCount) {
if (node) { if (node) {
return (this.text !== null) ? this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0), return this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0),
node.range[1] + (afterCount || 0)) : null; node.range[1] + (afterCount || 0));
} else { } else {
return this.text; return this.text;
} }
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@
"phantomjs": "1.9.18", "phantomjs": "1.9.18",
"phantomjs-polyfill": "0.0.1", "phantomjs-polyfill": "0.0.1",
"proxyquire": "^1.0.0", "proxyquire": "^1.0.0",
"rewire": "^2.3.4",
"semver": "^5.0.3", "semver": "^5.0.3",
"shelljs-nodecli": "~0.1.0", "shelljs-nodecli": "~0.1.0",
"sinon": "1.17.2", "sinon": "^1.17.2",
"through": "^2.3.6", "through": "^2.3.6",
"tmp": "0.0.28" "tmp": "0.0.28"
}, },
Expand Down
31 changes: 0 additions & 31 deletions scripts/bundle.sh

This file was deleted.

16 changes: 16 additions & 0 deletions tests/lib/config/config-file.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ describe("ConfigFile", function() {


describe("load", 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() { it("should load information from a legacy file", function() {
var config = ConfigFile.load(getFixturePath("legacy/.eslintrc")); var config = ConfigFile.load(getFixturePath("legacy/.eslintrc"));
assert.deepEqual(config, { assert.deepEqual(config, {
Expand Down Expand Up @@ -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"));
});
});
}); });


}); });
38 changes: 37 additions & 1 deletion tests/lib/config/config-ops.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
var assert = require("chai").assert, var assert = require("chai").assert,
assign = require("object-assign"), assign = require("object-assign"),
environments = require("../../../conf/environments"), environments = require("../../../conf/environments"),
ConfigOps = require("../../../lib/config/config-ops"); ConfigOps = require("../../../lib/config/config-ops"),
proxyquire = require("proxyquire");

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


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


describe("createEnvironmentConfig()", 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() { it("should create the correct config for Node.js environment", function() {
var config = ConfigOps.createEnvironmentConfig({ node: true }); var config = ConfigOps.createEnvironmentConfig({ node: true });
assert.deepEqual(config, { assert.deepEqual(config, {
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/no-empty-pattern.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ ruleTester.run("no-empty-pattern", rule, {
{ code: "var {a, b = {}} = foo;", parserOptions: { ecmaVersion: 6 }}, { code: "var {a, b = {}} = foo;", parserOptions: { ecmaVersion: 6 }},
{ code: "var {a = []} = 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: "function foo({a = []}) {}", parserOptions: { ecmaVersion: 6 }},
{ code: "var [a] = foo", parserOptions: { ecmaVersion: 6 }}
], ],


// Examples of code that should trigger the rule // Examples of code that should trigger the rule
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-useless-constructor.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ ruleTester.run("no-useless-constructor", rule, {
{ {
code: "class A extends B { constructor(...args){ super(...args); doSomething(); } }", code: "class A extends B { constructor(...args){ super(...args); doSomething(); } }",
parserOptions: { ecmaVersion: 6 } parserOptions: { ecmaVersion: 6 }
},
{
code: "class A { dummyMethod(){ doSomething(); } }",
parserOptions: { ecmaVersion: 6 }
} }
], ],
invalid: [ invalid: [
Expand Down
25 changes: 25 additions & 0 deletions tests/lib/rules/require-jsdoc.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ ruleTester.run("require-jsdoc", rule, {
} }
}] }]
}, },
{
code: "var myFunction = function() {}",
options: [{
"require": {
"FunctionDeclaration": false,
"MethodDefinition": true,
"ClassDeclaration": true
}
}]
},
{ {
code: code:
"/**\n" + "/**\n" +
Expand Down Expand Up @@ -140,6 +150,21 @@ ruleTester.run("require-jsdoc", rule, {
"ClassDeclaration": true "ClassDeclaration": true
} }
}] }]
},
{
code:
"class A {\n" +
" constructor(xs) {\n" +
" this.a = xs;" +
" }\n" +
"}",
parserOptions: { ecmaVersion: 6 },
options: [{
"require": {
"MethodDefinition": false,
"ClassDeclaration": false
}
}]
} }
], ],


Expand Down
15 changes: 15 additions & 0 deletions tests/lib/util/glob-util.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -214,5 +214,20 @@ describe("globUtil", function() {
assert.equal(result.length, 0); 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]);
});

}); });
}); });
Loading

0 comments on commit d3f4bdd

Please sign in to comment.