Skip to content

Commit

Permalink
fixed detail reporting for jshint if there are no failures
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Quach authored and Chris Quach committed Jan 23, 2015
1 parent a62f8a3 commit 8a474d3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

node_modules
npm-debug.log
tmp
.tmp
result.json
test/override/results
test/missing/results
Expand Down
24 changes: 20 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ module.exports = function (grunt) {
dir: 'test/fixtures/e2e/coverage/**/missing*.json'
}
},
jshint: 'test/fixtures/missing.xml'
jshint: {
file: 'test/fixtures/missing.xml'
}
}
},
missingFiles: {
options: {
dir: '.tmp/does/not/exist',
file: 'non-existing-file.json'
dir: '.tmp/missing-files/',
file: 'missing-files.json'
},
results: {
junit: {
Expand All @@ -201,7 +203,9 @@ module.exports = function (grunt) {
dir: 'non/existing/directory/*.json'
}
},
jshint: 'non/existing/results.xml'
jshint: {
file: 'non/existing/results.xml'
}
}
},
undefined: {
Expand All @@ -211,6 +215,18 @@ module.exports = function (grunt) {
},
results: {
}
},
jshintNoFailures: {
options: {
dir: '.tmp/jshintNoFailures',
file: 'results.json'
},
results: {
jshint: {
file: 'test/fixtures/jshint/jshint-nofailures.xml',
details: true
}
}
}
},

Expand Down
22 changes: 11 additions & 11 deletions tasks/code_quality_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ module.exports = function (grunt) {
}
}
}

}

/**
Expand All @@ -81,11 +80,7 @@ module.exports = function (grunt) {
* @param name The name that is used when writing to disk.
*/
function mergeTestResults(src, name) {
//if(typeof name === 'undefined') {
// return undefined;
//}

var result = '<?xml version="1.0"?><testsuites>';
var result = '<?xml version="1.0"?><testsuites>';
grunt.file.expand({filter: 'isFile'}, src).forEach(function (file) {
var content = grunt.file.read(file);
var matches = /<testsuite [\s\S]*>[\s\S]*<\/testsuite>/g.exec(content);
Expand Down Expand Up @@ -140,8 +135,10 @@ module.exports = function (grunt) {
}
results.push(result);
});

});
}

return results;
}

Expand All @@ -159,6 +156,7 @@ module.exports = function (grunt) {
var browser = path.dirname(file).substring(path.dirname(file).lastIndexOf("/")+1)
collector.add(JSON.parse(grunt.file.read(file)));
var summary = utils.summarizeCoverage(collector.getFinalCoverage());
grunt.log.writeflags(summary);
results.push({
browser: browser,
lines: Number(summary.lines.pct),
Expand Down Expand Up @@ -191,11 +189,13 @@ module.exports = function (grunt) {
if (showDetails) {
var details = {};
res.testsuite.testcase.forEach(function (key) {
var filename = key.$.name.substring(key.$.name.search(/[^\/]+$/g));
var failures = key.failure[0]._.replace(/\n/g, "###").split("###");
failures.shift();
failures.pop();
details[filename] = failures;
if(typeof key.failure !== 'undefined') {
var filename = key.$.name.substring(key.$.name.search(/[^\/]+$/g));
var failures = key.failure[0]._.replace(/\n/g, "###").split("###");
failures.shift();
failures.pop();
details[filename] = failures;
}
});
result.failureDetails = details;
}
Expand Down
12 changes: 10 additions & 2 deletions test/code_quality_report_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ exports.code_quality_report = {
},
missingFiles: function(test) {
test.expect(1);
//test.ok(!grunt.file.exists('.tmp/does/not/exist/non-existing-file.json'), 'Should not have created a file');
var actual = grunt.file.read('.tmp/does/not/exist/non-existing-file.json');
var actual = grunt.file.read('.tmp/missing-files/missing-files.json');
var expected = grunt.file.read('test/expected/missing.json');
test.equal(actual, expected, 'should write the result in the missing result dir.');

Expand All @@ -76,6 +75,15 @@ exports.code_quality_report = {
var expected = grunt.file.read('test/expected/undefined.json');
test.equal(actual, expected, 'should write the result in the missing result dir.');

test.done();
},
jshintNoFailures: function(test) {
test.expect(1);

var actual = grunt.file.read('.tmp/jshintNoFailures/results.json');
var expected = grunt.file.read('test/expected/jshintNoFailures.json');
test.equals(actual, expected, 'should write the result in the jshintNoFailures result dir');

test.done();
}
};
1 change: 1 addition & 0 deletions test/expected/jshintNoFailures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"jshint":{"tests":1,"failures":0,"errors":0,"consoleStatements":0,"failureDetails":{}}}
2 changes: 1 addition & 1 deletion test/expected/missing.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"junit":{"tests":[],"coverage":[]},"e2e":{"tests":[],"coverage":[]}}
{"junit":{"tests":[],"coverage":[]},"e2e":{"tests":[],"coverage":[]},"jshint":{}}
4 changes: 4 additions & 0 deletions test/fixtures/jshint/jshint-nofailures.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<testsuite name="jshint" tests="1" failures="0" errors="0">
<testcase name="jshint" />
</testsuite>

0 comments on commit 8a474d3

Please sign in to comment.