Skip to content

Commit

Permalink
added test failure count to phantomjs exit status
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelduran committed Oct 9, 2013
1 parent 0871768 commit 1d23a45
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
23 changes: 18 additions & 5 deletions src/common/util.js
Expand Up @@ -1418,10 +1418,13 @@ YSLOW.util = {
* Format test results as TAP for CI
* @see: http://testanything.org/wiki/index.php/TAP_specification
* @param {Array} tests the arrays containing the test results from testResults.
* @return {String} the results as TAP plain text
* @return {Object}:
* failures: {Number} total test failed,
* content: {String} the results as TAP plain text
*/
formatAsTAP: function (results) {
var i, res, line, offenders, j, lenJ,
failures = 0,
len = results.length,
tap = [],
util = YSLOW.util,
Expand All @@ -1436,6 +1439,7 @@ YSLOW.util = {
for (i = 0; i < len; i += 1) {
res = results[i];
line = res.ok || res.score < 0 ? 'ok' : 'not ok';
failures += (res.ok || res.score < 0) ? 0 : 1;
line += ' ' + (i + 1) + ' ' + res.grade +
' (' + res.score + ') ' + res.name;
if (res.description) {
Expand Down Expand Up @@ -1473,14 +1477,19 @@ YSLOW.util = {
}
}

return tap.join('\n');
return {
failures: failures,
content: tap.join('\n')
};
},

/**
* Format test results as JUnit XML for CI
* @see: http://www.junit.org/
* @param {Array} tests the arrays containing the test results from testResults.
* @return {String} the results as JUnit XML text
* @return {Object}:
* failures: {Number} total test failed,
* content: {String} the results as JUnit XML text
*/
formatAsJUnit: function (results) {
var i, res, line, offenders, j, lenJ,
Expand Down Expand Up @@ -1510,13 +1519,14 @@ YSLOW.util = {
if (res.ok) {
cases.push(line + '"/>');
} else {
failures += 1;
cases.push(line + '">');

// skipped
if (res.score < 0) {
skipped += 1;
cases.push(' <skipped>score N/A</skipped>');
} else {
failures += 1;
}

line = ' <failure';
Expand Down Expand Up @@ -1567,7 +1577,10 @@ YSLOW.util = {
// close test suites wrapper
junit.push('</testsuites>');

return junit.join('\n');
return {
failures: failures,
content: junit.join('\n')
};
},

/**
Expand Down
31 changes: 19 additions & 12 deletions src/phantomjs/controller.js
Expand Up @@ -226,7 +226,9 @@ urls.forEach(function (url) {
// open page
page.startTime = new Date();
page.open(url, function (status) {
var yslow, ysphantomjs, controller, evalFunc, loadTime, url, resp,
var yslow, ysphantomjs, controller, evalFunc,
loadTime, url, resp, output,
exitStatus = 0,
startTime = page.startTime,
resources = page.resources;

Expand Down Expand Up @@ -278,7 +280,8 @@ urls.forEach(function (url) {

// format out with appropriate content type
formatOutput = function (content) {
var format = (args.format || '').toLowerCase(),
var testResults,
format = (args.format || '').toLowerCase(),
harness = {
'tap': {
func: ysutil.formatAsTAP,
Expand Down Expand Up @@ -311,14 +314,16 @@ urls.forEach(function (url) {
} catch (err) {
threshold = args.threshold;
}
testResults = harness[format].func(
ysutil.testResults(
content,
threshold
)
);
return {
content: harness[format].func(
ysutil.testResults(
content,
threshold
)
),
contentType: harness[format].contentType
content: testResults.content,
contentType: harness[format].contentType,
failures: testResults.failures
};
default:
return {
Expand Down Expand Up @@ -475,7 +480,7 @@ urls.forEach(function (url) {
}
}

return output.content;
return output;
} catch (err) {
return err;
}
Expand Down Expand Up @@ -520,13 +525,15 @@ urls.forEach(function (url) {
evalFunc = new Function(yslow + ysphantomjs + controller);

// evaluate script and log results
console.log(page.evaluate(evalFunc));
output = page.evaluate(evalFunc);
exitStatus += output.failures || 0;
console.log(output.content);
}

// finish phantomjs
urlCount -= 1;
if (urlCount === 0) {
phantom.exit();
phantom.exit(exitStatus);
}
});
});

0 comments on commit 1d23a45

Please sign in to comment.