Skip to content

Commit

Permalink
Merge pull request #11 from udjamaflip/master
Browse files Browse the repository at this point in the history
Adding support for jsxhint
  • Loading branch information
udjamaflip committed May 20, 2015
2 parents 3916a5e + ff23243 commit 49b7fea
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
3 changes: 2 additions & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jshint-junit-reporter",
"version": "0.2.0",
"version": "0.2.1",
"description": "A JSHint reporter for jUnit.",
"license": "MIT",
"main": "index.js",
Expand All @@ -14,6 +14,7 @@
},
"keywords": [
"jshint",
"jsxhint",
"junit",
"jslint"
]
Expand Down
55 changes: 44 additions & 11 deletions reporter.js
Expand Up @@ -44,6 +44,26 @@ function failure_details(failures) {
return msg.join("\n");
}

//jsxhint stores the files in a tmp dir
//this means the data list and the results array don't match
//to remedy we can loop through list and remove the non-matching string
function getMatchingResultFileName(file, failureList) {

for (var failureFile in failureList) {

//if the end of the file provided identically matches that in the failures list
//the files will be the same just 1 has a bunch of tmpdir rubbish at the front.
//return the failureFile link

if (file.indexOf(failureFile) === (file.length-failureFile.length)) {
return failureFile;
}

return file;
}

}

exports.reporter = function (results, data, opts) {

var out = [];
Expand All @@ -57,6 +77,7 @@ exports.reporter = function (results, data, opts) {

results.forEach(function (result) {
result.file = result.file.replace(/^\.\//, '');

if (!files[result.file]) {
files[result.file] = [];
}
Expand All @@ -72,16 +93,28 @@ exports.reporter = function (results, data, opts) {
}

for (var i = 0; i < data.length; i++) {
var file = data[i].file;
//has an error
if (files[file]) {
out.push("\t<testcase name=\"" + file + "\">");
out.push("\t\t<failure message=\"" + failure_message(files[file]) + "\">");
out.push(failure_details(files[file]));
out.push("\t\t</failure>");
out.push("\t</testcase>");
} else {
out.push("\t<testcase name=\"" + file + "\" />");
var fileName = data[i].file;

//so this works with jsxhint as well
//jsxhint puts the files into a cache dir
//but doesn't change the location of the results to match
//so we have to work around it
if (fileName.indexOf('/jsxhint/') > -1) {
fileName = getMatchingResultFileName(fileName, files);
}

//jshint seems to shove itself at the start in some versions
if (fileName !== 'jshint') {
//has an error
if (files[fileName]) {
out.push("\t<testcase name=\"" + fileName + "\">");
out.push("\t\t<failure message=\"" + failure_message(files[fileName]) + "\">");
out.push(failure_details(files[fileName]));
out.push("\t\t</failure>");
out.push("\t</testcase>");
} else {
out.push("\t<testcase name=\"" + fileName + "\" />");
}
}
}

Expand All @@ -96,4 +129,4 @@ exports.reporter = function (results, data, opts) {

return out;

};
};

0 comments on commit 49b7fea

Please sign in to comment.