|
| 1 | +/* |
| 2 | + * Qt+WebKit powered (mostly) headless test runner using Phantomjs |
| 3 | + * |
| 4 | + * Phantomjs installation: http://code.google.com/p/phantomjs/wiki/BuildInstructions |
| 5 | + * |
| 6 | + * Then run with: |
| 7 | + * phantomjs test.js |
| 8 | + */ |
| 9 | + |
| 10 | +function addLogging(suite, done) { |
| 11 | + var module; |
| 12 | + QUnit.moduleStart = function(context) { |
| 13 | + module = context.name; |
| 14 | + } |
| 15 | + var current_test_assertions = []; |
| 16 | + QUnit.testDone = function(result) { |
| 17 | + var name = module + ": " + result.name; |
| 18 | + if (result.failed) { |
| 19 | + console.log("\u001B[31m✖ " + name); |
| 20 | + for (var i = 0; i < current_test_assertions.length; i++) { |
| 21 | + console.log(" " + current_test_assertions[i]); |
| 22 | + } |
| 23 | + console.log("\u001B[39m"); |
| 24 | + } |
| 25 | + current_test_assertions = []; |
| 26 | + }; |
| 27 | + |
| 28 | + QUnit.log = function(details) { |
| 29 | + if (details.result) |
| 30 | + return; |
| 31 | + var response = details.message || ""; |
| 32 | + if (typeof details.expected !== "undefined") { |
| 33 | + if (response) { |
| 34 | + response += ", "; |
| 35 | + } |
| 36 | + response = "expected: " + details.expected + ", but was: " + details.actual; |
| 37 | + } |
| 38 | + current_test_assertions.push("Failed assertion: " + response); |
| 39 | + }; |
| 40 | + |
| 41 | + QUnit.done = function(result){ |
| 42 | + console.log(suite + ": Took " + result.runtime + "ms to run " + result.total + " tests. ✔ " + result.passed + " \u001B[31m✖ " + result.failed + "\u001B[39m "); |
| 43 | + done(result.failed > 0 ? 1 : 0); |
| 44 | + }; |
| 45 | +} |
| 46 | + |
| 47 | +// TODO add dialog, draggable, droppable, position, resizable, selectable, sortable and tabs once their suites are stable |
| 48 | +var phantom_tests = ["accordion", "autocomplete", "button", "core", "datepicker", "menu", "progressbar", "spinner", "tooltip", "widget"], |
| 49 | + //phantom_tests = ["accordion", "autocomplete", "button", "core", "datepicker", "dialog", "draggable", "droppable", "menu", "position", "progressbar", "resizable", "selectable", "slider", "sortable", "spinner", "tabs", "tooltip", "widget"], |
| 50 | + phantom_state; |
| 51 | + |
| 52 | +function run() { |
| 53 | + var test = phantom_tests[phantom_state]; |
| 54 | + phantom.state = phantom_state + 1; |
| 55 | + // TODO make base URL configurable via args? |
| 56 | + phantom.open("http://localhost/jquery-ui/tests/unit/" + test + "/" + test + ".html"); |
| 57 | +} |
| 58 | + |
| 59 | +if (phantom.state.length == 0) { |
| 60 | + phantom_state = phantom.state = 0; |
| 61 | + run(); |
| 62 | +} else { |
| 63 | + phantom_state = +phantom.state; |
| 64 | + addLogging(phantom_tests[phantom_state - 1], function(returnCode) { |
| 65 | + if (phantom_tests[phantom_state]) { |
| 66 | + run(); |
| 67 | + } else { |
| 68 | + // TODO sum all the return codes and pass them to .exit() |
| 69 | + phantom.exit(); |
| 70 | + } |
| 71 | + }); |
| 72 | +} |
0 commit comments