| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2017 Eyeo GmbH |
|
Felix Dahlke
2017/01/30 14:37:58
It's 2017 :)
Wladimir Palant
2017/02/24 09:18:55
Yes, but the copyright header hasn't been updated
Felix Dahlke
2017/02/24 10:43:38
:)
| |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 (function() | 20 (function() |
| 21 { | 21 { |
| 22 // TODO: This should use promises once PhantomJS supports them, this will make | 22 // We are currently limited to ECMAScript 5 in this file, because it is being |
|
Felix Dahlke
2017/01/30 14:37:58
Could you reference issue 4796 here? In the other
Wladimir Palant
2017/02/24 09:18:55
Done.
| |
| 23 // wrapping all async calls in order to catch errors unnecessary. | 23 // used in the browser tests. See https://issues.adblockplus.org/ticket/4796 |
| 24 // Once this is resolved we should use promises here. | |
| 24 function safeCall(callback) | 25 function safeCall(callback) |
|
Felix Dahlke
2017/01/30 14:37:58
Have you considered using phantom.onError instead?
Wladimir Palant
2017/02/24 09:18:55
I was using that originally, it wasn't catching al
Felix Dahlke
2017/02/24 10:43:38
Acknowledged.
| |
| 25 { | 26 { |
| 26 return function() | 27 return function() |
| 27 { | 28 { |
| 28 try | 29 try |
| 29 { | 30 { |
| 30 callback.apply(this, arguments); | 31 callback.apply(this, arguments); |
| 31 } | 32 } |
| 32 catch (e) | 33 catch (e) |
| 33 { | 34 { |
| 34 var message = String(e); | 35 var message = String(e); |
| 35 if (e.stack) | 36 if (e.stack) |
| 36 message += "\n" + e.stack; | 37 message += "\n" + e.stack; |
| 37 console.log(message); | 38 console.log(message); |
|
Felix Dahlke
2017/01/30 14:37:58
Since it's an error message, how about console.err
Wladimir Palant
2017/02/24 09:18:55
nodeunit prints all output via console.log(), incl
Felix Dahlke
2017/02/24 10:43:39
Acknowledged.
| |
| 38 phantom.exit(); | 39 phantom.exit(1); |
|
Felix Dahlke
2017/01/30 14:37:58
phantom.exit(1) in this case?
Wladimir Palant
2017/02/24 09:18:55
Done.
| |
| 39 } | 40 } |
| 40 } | 41 }; |
|
Felix Dahlke
2017/01/30 14:37:58
Missing semicolon?
Wladimir Palant
2017/02/24 09:18:55
Done.
| |
| 41 } | 42 } |
| 42 | 43 |
| 43 function loadScript(doc, url, callback) | 44 function loadScript(doc, url, callback) |
| 44 { | 45 { |
| 45 var script = doc.createElement("script"); | 46 var script = doc.createElement("script"); |
| 46 script.src = url; | 47 script.src = url; |
| 47 script.async = false; | 48 script.async = false; |
| 48 doc.head.appendChild(script); | 49 doc.head.appendChild(script); |
| 49 if (callback) | 50 if (callback) |
| 50 window.setTimeout(callback, 0); | 51 window.setTimeout(callback, 0); |
| 51 } | |
| 52 | |
| 53 function run() | |
|
Felix Dahlke
2017/01/30 14:37:58
Nit: Move this below runTests() to have the functi
Wladimir Palant
2017/02/24 09:18:55
Done.
| |
| 54 { | |
| 55 var system = require("system"); | |
| 56 var nodeunitUrl = system.args[1]; | |
| 57 var urls = system.args.slice(2); | |
| 58 | |
| 59 loadScript(document, nodeunitUrl, safeCall(function() | |
| 60 { | |
| 61 loadModules(urls, safeCall(function(modules) | |
| 62 { | |
| 63 runTests(modules, function() | |
| 64 { | |
| 65 phantom.exit(); | |
| 66 }); | |
| 67 })); | |
| 68 })); | |
| 69 } | 52 } |
| 70 | 53 |
| 71 function loadModules(urls, callback) | 54 function loadModules(urls, callback) |
| 72 { | 55 { |
| 73 var modules = {}; | 56 var modules = {}; |
| 74 | 57 |
| 75 var loadNext = safeCall(function() | 58 var loadNext = safeCall(function() |
| 76 { | 59 { |
| 77 if (urls.length) | 60 if (urls.length) |
| 78 { | 61 { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 console.log("\u2714 " + name); | 121 console.log("\u2714 " + name); |
| 139 else | 122 else |
| 140 { | 123 { |
| 141 console.log(error("\u2716 " + name) + "\n"); | 124 console.log(error("\u2716 " + name) + "\n"); |
| 142 errors.forEach(function(error) | 125 errors.forEach(function(error) |
| 143 { | 126 { |
| 144 console.log(String(error)); | 127 console.log(String(error)); |
| 145 if (error.stack) | 128 if (error.stack) |
| 146 console.log(error.stack); | 129 console.log(error.stack); |
| 147 console.log(""); | 130 console.log(""); |
| 148 }) | 131 }); |
| 149 } | 132 } |
| 150 }, | 133 }, |
| 151 done: function(assertions) | 134 done: function(assertions) |
| 152 { | 135 { |
| 153 var failures = assertions.filter(function(assertion) | 136 var failures = assertions.filter(function(assertion) |
| 154 { | 137 { |
| 155 return assertion.failed(); | 138 return assertion.failed(); |
| 156 }); | 139 }); |
| 157 if (failures.length) | 140 if (failures.length) |
| 158 { | 141 { |
| 159 console.log( | 142 console.log( |
| 160 "\n" + | 143 "\n" + |
| 161 bold(error("FAILURES: ")) + | 144 bold(error("FAILURES: ")) + |
| 162 failures.length + "/" + assertions.length + " assertions failed" | 145 failures.length + "/" + assertions.length + " assertions failed" |
| 163 ); | 146 ); |
| 164 } | 147 } |
| 165 else | 148 else |
| 166 { | 149 { |
| 167 console.log( | 150 console.log( |
| 168 "\n" + bold(ok("OK: ")) + | 151 "\n" + bold(ok("OK: ")) + |
| 169 assertions.length + " assertions" | 152 assertions.length + " assertions" |
| 170 ); | 153 ); |
| 171 } | 154 } |
| 172 | 155 |
| 173 callback(); | 156 callback(!failures.length); |
| 174 } | 157 } |
| 175 }); | 158 }); |
| 176 } | 159 } |
| 177 | 160 |
| 161 function run() | |
| 162 { | |
| 163 var system = require("system"); | |
| 164 var nodeunitUrl = system.args[1]; | |
| 165 var urls = system.args.slice(2); | |
| 166 | |
| 167 loadScript(document, nodeunitUrl, safeCall(function() | |
| 168 { | |
| 169 loadModules(urls, safeCall(function(modules) | |
| 170 { | |
| 171 runTests(modules, function(success) | |
| 172 { | |
| 173 phantom.exit(success ? 0 : 1); | |
| 174 }); | |
| 175 })); | |
| 176 })); | |
| 177 } | |
| 178 | |
| 178 safeCall(run)(); | 179 safeCall(run)(); |
| 179 })(); | 180 })(); |
| LEFT | RIGHT |