Commit 6dd97c9c 6dd97c9cc865464bab4e705fe6824bd8b111312b by Julien Muetton

Add test results for skipped

1 parent a228e553
...@@ -102,8 +102,9 @@ var Tester = function Tester(casper, options) { ...@@ -102,8 +102,9 @@ var Tester = function Tester(casper, options) {
102 this.options = utils.mergeObjects({ 102 this.options = utils.mergeObjects({
103 concise: false, // concise output? 103 concise: false, // concise output?
104 failFast: false, // terminates a suite as soon as a test fails? 104 failFast: false, // terminates a suite as soon as a test fails?
105 failText: "FAIL", // text to use for a succesful test 105 failText: "FAIL", // text to use for a failed test
106 passText: "PASS", // text to use for a failed test 106 passText: "PASS", // text to use for a succesful test
107 skipText: "SKIP", // text to use for a skipped test
107 pad: 80 , // maximum number of chars for a result line 108 pad: 80 , // maximum number of chars for a result line
108 warnText: "WARN" // text to use for a dubious test 109 warnText: "WARN" // text to use for a dubious test
109 }, options); 110 }, options);
...@@ -118,6 +119,12 @@ var Tester = function Tester(casper, options) { ...@@ -118,6 +119,12 @@ var Tester = function Tester(casper, options) {
118 this.lastAssertTime = timeElapsed; 119 this.lastAssertTime = timeElapsed;
119 }); 120 });
120 121
122 this.on('skipped', function onSkipped(skipped) {
123 var timeElapsed = new Date() - this.currentTestStartTime;
124 this.currentSuite.addSkipped(skipped, timeElapsed - this.lastAssertTime);
125 this.lastAssertTime = timeElapsed;
126 });
127
121 this.on('fail', function onFail(failure) { 128 this.on('fail', function onFail(failure) {
122 // export 129 // export
123 var valueKeys = Object.keys(failure.values), 130 var valueKeys = Object.keys(failure.values),
...@@ -222,25 +229,28 @@ Tester.prototype.abort = function abort(message) { ...@@ -222,25 +229,28 @@ Tester.prototype.abort = function abort(message) {
222 }; 229 };
223 230
224 /** 231 /**
225 * Aborts current test suite. 232 * Skip `nb` tests.
226 * 233 *
227 * @param {String} message Warning message (optional) 234 * @param Integer nb number of tests to skip
235 * @param String message message to display
228 */ 236 */
229 Tester.prototype.skip = function skip(number, message) { 237 Tester.prototype.skip = function skip(nb, message) {
230 "use strict"; 238 "use strict";
231 var step = this.casper.step, 239 var step = this.casper.step,
232 steps = this.casper.steps, 240 steps = this.casper.steps,
233 last = steps.length; 241 last = steps.length;
234 242
235 if (message) { 243 this.casper.step = Math.min(step + nb, last);
236 this.casper.echo([ 244 this.executed += this.casper.step - step;
237 this.casper.colorize('SKIP', 'SKIP'),
238 'test suite aborted: ' + message
239 ].join(' '));
240 }
241 this.casper.step = Math.min(step + number, last);
242 245
243 return this; 246 return this.processAssertionResult({
247 success: null,
248 standard: f("Skipping %d tests", nb),
249 message: message,
250 type: "skip",
251 number: nb,
252 skipped: true
253 });
244 }; 254 };
245 255
246 /** 256 /**
...@@ -1164,7 +1174,11 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result ...@@ -1164,7 +1174,11 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result
1164 message = result.message || result.standard, 1174 message = result.message || result.standard,
1165 style = 'INFO', 1175 style = 'INFO',
1166 status = this.options.passText; 1176 status = this.options.passText;
1167 if (!result.success) { 1177 if (null === result.success) {
1178 eventName = 'skipped';
1179 style = 'SKIP';
1180 status = this.options.skipText;
1181 }else if (!result.success) {
1168 eventName = 'fail'; 1182 eventName = 'fail';
1169 style = 'RED_BAR'; 1183 style = 'RED_BAR';
1170 status = this.options.failText; 1184 status = this.options.failText;
...@@ -1254,6 +1268,7 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { ...@@ -1254,6 +1268,7 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
1254 save = save || this.options.save; 1268 save = save || this.options.save;
1255 var failed = this.suiteResults.countFailed(), 1269 var failed = this.suiteResults.countFailed(),
1256 passed = this.suiteResults.countPassed(), 1270 passed = this.suiteResults.countPassed(),
1271 skipped = this.suiteResults.countSkipped(),
1257 total = this.suiteResults.countTotal(), 1272 total = this.suiteResults.countTotal(),
1258 statusText, 1273 statusText,
1259 style, 1274 style,
...@@ -1267,16 +1282,20 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { ...@@ -1267,16 +1282,20 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) {
1267 if (failed > 0) { 1282 if (failed > 0) {
1268 statusText = this.options.failText; 1283 statusText = this.options.failText;
1269 style = 'RED_BAR'; 1284 style = 'RED_BAR';
1285 } else if (skipped > 0) {
1286 statusText = this.options.skipText;
1287 style = 'SKIP_BAR';
1270 } else { 1288 } else {
1271 statusText = this.options.passText; 1289 statusText = this.options.passText;
1272 style = 'GREEN_BAR'; 1290 style = 'GREEN_BAR';
1273 } 1291 }
1274 result = f('%s %s tests executed in %ss, %d passed, %d failed.', 1292 result = f('%s %s tests executed in %ss, %d passed, %d failed, %d skipped.',
1275 statusText, 1293 statusText,
1276 total, 1294 total,
1277 utils.ms2seconds(this.suiteResults.calculateDuration()), 1295 utils.ms2seconds(this.suiteResults.calculateDuration()),
1278 passed, 1296 passed,
1279 failed); 1297 failed,
1298 skipped);
1280 } 1299 }
1281 this.casper.echo(result, style, this.options.pad); 1300 this.casper.echo(result, style, this.options.pad);
1282 if (failed > 0) { 1301 if (failed > 0) {
...@@ -1483,6 +1502,20 @@ TestSuiteResult.prototype.countPassed = function countPassed() { ...@@ -1483,6 +1502,20 @@ TestSuiteResult.prototype.countPassed = function countPassed() {
1483 }; 1502 };
1484 1503
1485 /** 1504 /**
1505 * Returns the number of skipped tests.
1506 *
1507 * @return Number
1508 */
1509 TestSuiteResult.prototype.countSkipped = function countSkipped() {
1510 "use strict";
1511 return this.map(function(result) {
1512 return result.skipped;
1513 }).reduce(function(a, b) {
1514 return a + b;
1515 }, 0);
1516 };
1517
1518 /**
1486 * Returns the number of warnings. 1519 * Returns the number of warnings.
1487 * 1520 *
1488 * @return Number 1521 * @return Number
...@@ -1507,6 +1540,16 @@ TestSuiteResult.prototype.isFailed = function isFailed() { ...@@ -1507,6 +1540,16 @@ TestSuiteResult.prototype.isFailed = function isFailed() {
1507 }; 1540 };
1508 1541
1509 /** 1542 /**
1543 * Checks if the suite has skipped tests.
1544 *
1545 * @return Number
1546 */
1547 TestSuiteResult.prototype.isSkipped = function isFailed() {
1548 "use strict";
1549 return this.countSkipped() > 0;
1550 };
1551
1552 /**
1510 * Returns all failures from this suite. 1553 * Returns all failures from this suite.
1511 * 1554 *
1512 * @return Array 1555 * @return Array
...@@ -1535,6 +1578,20 @@ TestSuiteResult.prototype.getAllPasses = function getAllPasses() { ...@@ -1535,6 +1578,20 @@ TestSuiteResult.prototype.getAllPasses = function getAllPasses() {
1535 }; 1578 };
1536 1579
1537 /** 1580 /**
1581 * Returns all skipped tests from this suite.
1582 *
1583 * @return Array
1584 */
1585 TestSuiteResult.prototype.getAllSkipped = function getAllSkipped() {
1586 "use strict";
1587 var skipped = [];
1588 this.forEach(function(result) {
1589 skipped = skipped.concat(result.skipped);
1590 });
1591 return skipped;
1592 };
1593
1594 /**
1538 * Returns all results from this suite. 1595 * Returns all results from this suite.
1539 * 1596 *
1540 * @return Array 1597 * @return Array
...@@ -1572,6 +1629,7 @@ function TestCaseResult(options) { ...@@ -1572,6 +1629,7 @@ function TestCaseResult(options) {
1572 this.errors = []; 1629 this.errors = [];
1573 this.failures = []; 1630 this.failures = [];
1574 this.passes = []; 1631 this.passes = [];
1632 this.skip = [];
1575 this.warnings = []; 1633 this.warnings = [];
1576 this.config = options && options.config; 1634 this.config = options && options.config;
1577 this.__defineGetter__("assertions", function() { 1635 this.__defineGetter__("assertions", function() {
...@@ -1586,6 +1644,9 @@ function TestCaseResult(options) { ...@@ -1586,6 +1644,9 @@ function TestCaseResult(options) {
1586 this.__defineGetter__("passed", function() { 1644 this.__defineGetter__("passed", function() {
1587 return this.passes.length; 1645 return this.passes.length;
1588 }); 1646 });
1647 this.__defineGetter__("skipped", function() {
1648 return this.skip.length;
1649 });
1589 } 1650 }
1590 exports.TestCaseResult = TestCaseResult; 1651 exports.TestCaseResult = TestCaseResult;
1591 1652
...@@ -1627,6 +1688,20 @@ TestCaseResult.prototype.addSuccess = function addSuccess(success, time) { ...@@ -1627,6 +1688,20 @@ TestCaseResult.prototype.addSuccess = function addSuccess(success, time) {
1627 }; 1688 };
1628 1689
1629 /** 1690 /**
1691 * Adds a success record and its execution time.
1692 *
1693 * @param Object success
1694 * @param Number time
1695 */
1696 TestCaseResult.prototype.addSkipped = function addSkipped(skipped, time) {
1697 "use strict";
1698 skipped.suite = this.name;
1699 skipped.time = time;
1700 this.skip.push(skipped);
1701 };
1702
1703
1704 /**
1630 * Adds a warning record. 1705 * Adds a warning record.
1631 * 1706 *
1632 * @param Object warning 1707 * @param Object warning
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 casper.test.begin('Skip tests', 1, function(test) { 3 casper.test.begin('Skip tests', 2, function(test) {
4 casper.start('tests/site/index.html'); 4 casper.start('tests/site/index.html');
5 5
6 casper. 6 casper.
...@@ -19,7 +19,7 @@ casper.test.begin('Skip tests', 1, function(test) { ...@@ -19,7 +19,7 @@ casper.test.begin('Skip tests', 1, function(test) {
19 }); 19 });
20 }); 20 });
21 21
22 casper.test.begin('Skip multiple', 1, function(test) { 22 casper.test.begin('Skip multiple', 3, function(test) {
23 casper. 23 casper.
24 then(function () { 24 then(function () {
25 test.skip(2); 25 test.skip(2);
...@@ -50,7 +50,7 @@ casper.test.begin('Skip more than there is', 0, function(test) { ...@@ -50,7 +50,7 @@ casper.test.begin('Skip more than there is', 0, function(test) {
50 }); 50 });
51 }); 51 });
52 52
53 casper.test.begin('Next suite should be executed', 1, function(test) { 53 casper.test.begin('Skip does not polluate next suite', 1, function(test) {
54 casper. 54 casper.
55 then(function () { 55 then(function () {
56 test.pass("This test should be executed."); 56 test.pass("This test should be executed.");
......