refactored Tester#skip
Showing
4 changed files
with
46 additions
and
74 deletions
... | @@ -1626,6 +1626,7 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) { | ... | @@ -1626,6 +1626,7 @@ Casper.prototype.thenOpen = function thenOpen(location, settings, then) { |
1626 | * @param Integer nb Number of steps to bypass | 1626 | * @param Integer nb Number of steps to bypass |
1627 | */ | 1627 | */ |
1628 | Casper.prototype.thenBypass = function thenBypass(nb) { | 1628 | Casper.prototype.thenBypass = function thenBypass(nb) { |
1629 | "use strict"; | ||
1629 | return this.then(function _thenBypass() { | 1630 | return this.then(function _thenBypass() { |
1630 | this.bypass(nb); | 1631 | this.bypass(nb); |
1631 | }); | 1632 | }); |
... | @@ -1638,6 +1639,7 @@ Casper.prototype.thenBypass = function thenBypass(nb) { | ... | @@ -1638,6 +1639,7 @@ Casper.prototype.thenBypass = function thenBypass(nb) { |
1638 | * @param Integer nb Number of steps to bypass | 1639 | * @param Integer nb Number of steps to bypass |
1639 | */ | 1640 | */ |
1640 | Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) { | 1641 | Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) { |
1642 | "use strict"; | ||
1641 | return this.then(function _thenBypassIf() { | 1643 | return this.then(function _thenBypassIf() { |
1642 | if (utils.isFunction(condition)) { | 1644 | if (utils.isFunction(condition)) { |
1643 | condition = condition.call(this); | 1645 | condition = condition.call(this); |
... | @@ -1655,6 +1657,7 @@ Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) { | ... | @@ -1655,6 +1657,7 @@ Casper.prototype.thenBypassIf = function thenBypassIf(condition, nb) { |
1655 | * @param Integer nb Number of tests to bypass | 1657 | * @param Integer nb Number of tests to bypass |
1656 | */ | 1658 | */ |
1657 | Casper.prototype.thenBypassUnless = function thenBypassUnless(condition, nb) { | 1659 | Casper.prototype.thenBypassUnless = function thenBypassUnless(condition, nb) { |
1660 | "use strict"; | ||
1658 | return this.then(function _thenBypassUnless() { | 1661 | return this.then(function _thenBypassUnless() { |
1659 | if (utils.isFunction(condition)) { | 1662 | if (utils.isFunction(condition)) { |
1660 | condition = condition.call(this); | 1663 | condition = condition.call(this); | ... | ... |
... | @@ -130,7 +130,7 @@ var Tester = function Tester(casper, options) { | ... | @@ -130,7 +130,7 @@ var Tester = function Tester(casper, options) { |
130 | 130 | ||
131 | this.on('skipped', function onSkipped(skipped) { | 131 | this.on('skipped', function onSkipped(skipped) { |
132 | var timeElapsed = new Date() - this.currentTestStartTime; | 132 | var timeElapsed = new Date() - this.currentTestStartTime; |
133 | this.currentSuite.addSkipped(skipped, timeElapsed - this.lastAssertTime); | 133 | this.currentSuite.addSkip(skipped, timeElapsed - this.lastAssertTime); |
134 | this.lastAssertTime = timeElapsed; | 134 | this.lastAssertTime = timeElapsed; |
135 | }); | 135 | }); |
136 | 136 | ||
... | @@ -226,7 +226,7 @@ exports.Tester = Tester; | ... | @@ -226,7 +226,7 @@ exports.Tester = Tester; |
226 | /** | 226 | /** |
227 | * Aborts current test suite. | 227 | * Aborts current test suite. |
228 | * | 228 | * |
229 | * @param {String} message Warning message (optional) | 229 | * @param String message Warning message (optional) |
230 | */ | 230 | */ |
231 | Tester.prototype.abort = function abort(message) { | 231 | Tester.prototype.abort = function abort(message) { |
232 | "use strict"; | 232 | "use strict"; |
... | @@ -238,13 +238,13 @@ Tester.prototype.abort = function abort(message) { | ... | @@ -238,13 +238,13 @@ Tester.prototype.abort = function abort(message) { |
238 | * | 238 | * |
239 | * @param Integer nb Number of tests to skip | 239 | * @param Integer nb Number of tests to skip |
240 | * @param String message Message to display | 240 | * @param String message Message to display |
241 | * @return Object | ||
241 | */ | 242 | */ |
242 | Tester.prototype.skip = function skip(nb, message) { | 243 | Tester.prototype.skip = function skip(nb, message) { |
243 | "use strict"; | 244 | "use strict"; |
244 | this.casper.bypass(nb); | ||
245 | return this.processAssertionResult({ | 245 | return this.processAssertionResult({ |
246 | success: null, | 246 | success: null, |
247 | standard: f("Skipping %d tests", nb), | 247 | standard: f("%d test%s skipped", nb, nb > 1 ? "s" : ""), |
248 | message: message, | 248 | message: message, |
249 | type: "skip", | 249 | type: "skip", |
250 | number: nb, | 250 | number: nb, |
... | @@ -938,7 +938,11 @@ Tester.prototype.begin = function begin() { | ... | @@ -938,7 +938,11 @@ Tester.prototype.begin = function begin() { |
938 | 938 | ||
939 | /** | 939 | /** |
940 | * Render a colorized output. Basically a proxy method for | 940 | * Render a colorized output. Basically a proxy method for |
941 | * Casper.Colorizer#colorize() | 941 | * `Casper.Colorizer#colorize()`. |
942 | * | ||
943 | * @param String message | ||
944 | * @param String style The style name | ||
945 | * @return String | ||
942 | */ | 946 | */ |
943 | Tester.prototype.colorize = function colorize(message, style) { | 947 | Tester.prototype.colorize = function colorize(message, style) { |
944 | "use strict"; | 948 | "use strict"; |
... | @@ -974,7 +978,8 @@ Tester.prototype.done = function done() { | ... | @@ -974,7 +978,8 @@ Tester.prototype.done = function done() { |
974 | this.processError(error); | 978 | this.processError(error); |
975 | } | 979 | } |
976 | } | 980 | } |
977 | if (this.currentSuite && this.currentSuite.planned && this.currentSuite.planned !== this.executed) { | 981 | if (this.currentSuite && this.currentSuite.planned && |
982 | this.currentSuite.planned !== this.executed + this.currentSuite.skipped) { | ||
978 | this.dubious(this.currentSuite.planned, this.executed, this.currentSuite.name); | 983 | this.dubious(this.currentSuite.planned, this.executed, this.currentSuite.name); |
979 | } else if (planned && planned !== this.executed) { | 984 | } else if (planned && planned !== this.executed) { |
980 | // BC | 985 | // BC |
... | @@ -1193,7 +1198,7 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result | ... | @@ -1193,7 +1198,7 @@ Tester.prototype.processAssertionResult = function processAssertionResult(result |
1193 | /** | 1198 | /** |
1194 | * Processes an error. | 1199 | * Processes an error. |
1195 | * | 1200 | * |
1196 | * @param {Error} error | 1201 | * @param Error error |
1197 | */ | 1202 | */ |
1198 | Tester.prototype.processError = function processError(error) { | 1203 | Tester.prototype.processError = function processError(error) { |
1199 | "use strict"; | 1204 | "use strict"; |
... | @@ -1209,8 +1214,8 @@ Tester.prototype.processError = function processError(error) { | ... | @@ -1209,8 +1214,8 @@ Tester.prototype.processError = function processError(error) { |
1209 | /** | 1214 | /** |
1210 | * Processes a PhantomJS error, which is an error message and a backtrace. | 1215 | * Processes a PhantomJS error, which is an error message and a backtrace. |
1211 | * | 1216 | * |
1212 | * @param {String} message | 1217 | * @param String message |
1213 | * @param {Array} backtrace | 1218 | * @param Array backtrace |
1214 | */ | 1219 | */ |
1215 | Tester.prototype.processPhantomError = function processPhantomError(msg, backtrace) { | 1220 | Tester.prototype.processPhantomError = function processPhantomError(msg, backtrace) { |
1216 | "use strict"; | 1221 | "use strict"; |
... | @@ -1265,13 +1270,10 @@ Tester.prototype.renderFailureDetails = function renderFailureDetails() { | ... | @@ -1265,13 +1270,10 @@ Tester.prototype.renderFailureDetails = function renderFailureDetails() { |
1265 | */ | 1270 | */ |
1266 | Tester.prototype.renderResults = function renderResults(exit, status, save) { | 1271 | Tester.prototype.renderResults = function renderResults(exit, status, save) { |
1267 | "use strict"; | 1272 | "use strict"; |
1268 | /*jshint maxstatements:25*/ | 1273 | /*jshint maxstatements:20*/ |
1269 | save = save || this.options.save; | 1274 | save = save || this.options.save; |
1270 | var dubious = this.suiteResults.countDubious(), | 1275 | var failed = this.suiteResults.countFailed(), |
1271 | failed = this.suiteResults.countFailed(), | ||
1272 | passed = this.suiteResults.countPassed(), | ||
1273 | total = this.suiteResults.countExecuted(), | 1276 | total = this.suiteResults.countExecuted(), |
1274 | skipped = this.suiteResults.countSkipped(), | ||
1275 | statusText, | 1277 | statusText, |
1276 | style, | 1278 | style, |
1277 | result, | 1279 | result, |
... | @@ -1292,10 +1294,10 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { | ... | @@ -1292,10 +1294,10 @@ Tester.prototype.renderResults = function renderResults(exit, status, save) { |
1292 | statusText, | 1294 | statusText, |
1293 | total, | 1295 | total, |
1294 | utils.ms2seconds(this.suiteResults.calculateDuration()), | 1296 | utils.ms2seconds(this.suiteResults.calculateDuration()), |
1295 | passed, | 1297 | this.suiteResults.countPassed(), |
1296 | failed, | 1298 | failed, |
1297 | dubious, | 1299 | this.suiteResults.countDubious(), |
1298 | skipped); | 1300 | this.suiteResults.countSkipped()); |
1299 | } | 1301 | } |
1300 | this.casper.echo(result, style, this.options.pad); | 1302 | this.casper.echo(result, style, this.options.pad); |
1301 | if (failed > 0) { | 1303 | if (failed > 0) { |
... | @@ -1606,7 +1608,7 @@ TestSuiteResult.prototype.getAllPasses = function getAllPasses() { | ... | @@ -1606,7 +1608,7 @@ TestSuiteResult.prototype.getAllPasses = function getAllPasses() { |
1606 | * | 1608 | * |
1607 | * @return Array | 1609 | * @return Array |
1608 | */ | 1610 | */ |
1609 | TestSuiteResult.prototype.getAllSkipped = function getAllSkipped() { | 1611 | TestSuiteResult.prototype.getAllSkips = function getAllSkips() { |
1610 | "use strict"; | 1612 | "use strict"; |
1611 | var skipped = []; | 1613 | var skipped = []; |
1612 | this.forEach(function(result) { | 1614 | this.forEach(function(result) { |
... | @@ -1653,7 +1655,7 @@ function TestCaseResult(options) { | ... | @@ -1653,7 +1655,7 @@ function TestCaseResult(options) { |
1653 | this.errors = []; | 1655 | this.errors = []; |
1654 | this.failures = []; | 1656 | this.failures = []; |
1655 | this.passes = []; | 1657 | this.passes = []; |
1656 | this.skip = []; | 1658 | this.skips = []; |
1657 | this.warnings = []; | 1659 | this.warnings = []; |
1658 | this.config = options && options.config; | 1660 | this.config = options && options.config; |
1659 | this.__defineGetter__("assertions", function() { | 1661 | this.__defineGetter__("assertions", function() { |
... | @@ -1674,7 +1676,11 @@ function TestCaseResult(options) { | ... | @@ -1674,7 +1676,11 @@ function TestCaseResult(options) { |
1674 | return this.passes.length; | 1676 | return this.passes.length; |
1675 | }); | 1677 | }); |
1676 | this.__defineGetter__("skipped", function() { | 1678 | this.__defineGetter__("skipped", function() { |
1677 | return this.skip.length; | 1679 | return this.skips.map(function(skip) { |
1680 | return skip.number; | ||
1681 | }).reduce(function(a, b) { | ||
1682 | return a + b; | ||
1683 | }, 0); | ||
1678 | }); | 1684 | }); |
1679 | } | 1685 | } |
1680 | exports.TestCaseResult = TestCaseResult; | 1686 | exports.TestCaseResult = TestCaseResult; |
... | @@ -1722,11 +1728,11 @@ TestCaseResult.prototype.addSuccess = function addSuccess(success, time) { | ... | @@ -1722,11 +1728,11 @@ TestCaseResult.prototype.addSuccess = function addSuccess(success, time) { |
1722 | * @param Object success | 1728 | * @param Object success |
1723 | * @param Number time | 1729 | * @param Number time |
1724 | */ | 1730 | */ |
1725 | TestCaseResult.prototype.addSkipped = function addSkipped(skipped, time) { | 1731 | TestCaseResult.prototype.addSkip = function addSkip(skipped, time) { |
1726 | "use strict"; | 1732 | "use strict"; |
1727 | skipped.suite = this.name; | 1733 | skipped.suite = this.name; |
1728 | skipped.time = time; | 1734 | skipped.time = time; |
1729 | this.skip.push(skipped); | 1735 | this.skips.push(skipped); |
1730 | }; | 1736 | }; |
1731 | 1737 | ||
1732 | 1738 | ... | ... |
... | @@ -134,7 +134,7 @@ class CasperExecTest(unittest.TestCase): | ... | @@ -134,7 +134,7 @@ class CasperExecTest(unittest.TestCase): |
134 | '# subject: false', | 134 | '# subject: false', |
135 | 'FAIL 1 tests executed', | 135 | 'FAIL 1 tests executed', |
136 | '0 passed', | 136 | '0 passed', |
137 | '1 failed.', | 137 | '1 failed', |
138 | ], failing=True) | 138 | ], failing=True) |
139 | 139 | ||
140 | @timeout(60) | 140 | @timeout(60) | ... | ... |
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', 4, function(test) { |
4 | casper.start('tests/site/index.html'); | 4 | test.assert(true, 'First test executed'); |
5 | 5 | test.assert(true, 'Second test executed'); | |
6 | casper. | 6 | test.skip(2, 'Two tests skipped'); |
7 | then(function () { | 7 | test.done(); |
8 | test.skip(1); | ||
9 | }). | ||
10 | then(function () { | ||
11 | test.fail("This test should be skipped."); | ||
12 | }). | ||
13 | then(function () { | ||
14 | test.pass("This test should be executed."); | ||
15 | }); | ||
16 | |||
17 | casper.run(function() { | ||
18 | test.done(); | ||
19 | }); | ||
20 | }); | 8 | }); |
21 | 9 | ||
22 | casper.test.begin('Skip multiple', 1, function(test) { | 10 | casper.test.begin('Skip tests after', 4, function(test) { |
23 | casper. | 11 | test.skip(2, 'Two tests skipped'); |
24 | then(function () { | 12 | test.assert(true, 'Third test executed'); |
25 | test.skip(2); | 13 | test.assert(true, 'Fourth test executed'); |
26 | }). | 14 | test.done(); |
27 | then(function () { | ||
28 | test.fail("This test should be skipped."); | ||
29 | }). | ||
30 | then(function () { | ||
31 | test.fail("This test should be skipped."); | ||
32 | }). | ||
33 | then(function () { | ||
34 | test.pass("This test should be executed."); | ||
35 | }); | ||
36 | |||
37 | casper.run(function() { | ||
38 | test.done(); | ||
39 | }); | ||
40 | }); | 15 | }); |
41 | 16 | ||
42 | casper.test.begin('Skip more than there is', 0, function(test) { | 17 | casper.test.begin('Skip tests (asynchronous)', 1, function(test) { |
43 | casper.then(function () { | 18 | casper.start('tests/site/index.html', function() { |
44 | test.skip(2); | 19 | test.skip(1); |
45 | }); | 20 | }).run(function() { |
46 | |||
47 | casper.run(function() { | ||
48 | test.done(); | ||
49 | }); | ||
50 | }); | ||
51 | |||
52 | casper.test.begin('Skip does not polluate next suite', 1, function(test) { | ||
53 | casper.then(function () { | ||
54 | test.pass("This test should be executed."); | ||
55 | }); | ||
56 | |||
57 | casper.run(function() { | ||
58 | test.done(); | 21 | test.done(); |
59 | }); | 22 | }); |
60 | }); | 23 | }); | ... | ... |
-
Please register or sign in to post a comment