| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 script.src = url; | 29 script.src = url; |
| 30 script.onload = resolve; | 30 script.onload = resolve; |
| 31 doc.head.appendChild(script); | 31 doc.head.appendChild(script); |
| 32 }); | 32 }); |
| 33 } | 33 } |
| 34 | 34 |
| 35 function loadModules(urls) | 35 function loadModules(urls) |
| 36 { | 36 { |
| 37 let modules = {}; | 37 let modules = {}; |
| 38 | 38 |
| 39 let loadNext = () => | 39 return (function loadNext() |
| 40 { | 40 { |
| 41 if (urls.length) | 41 if (urls.length) |
| 42 { | 42 { |
| 43 // Load each module into a new frame so that their scopes don't clash | 43 // Load each module into a new frame so that their scopes don't clash |
| 44 let frame = document.createElement("iframe"); | 44 let frame = document.createElement("iframe"); |
| 45 document.body.appendChild(frame); | 45 document.body.appendChild(frame); |
| 46 | 46 |
| 47 let wnd = frame.contentWindow; | 47 let wnd = frame.contentWindow; |
| 48 wnd.loadScript = url => loadScript(wnd.document, url); | 48 wnd.loadScript = url => loadScript(wnd.document, url); |
| 49 wnd.exports = {}; | 49 wnd.exports = {}; |
| 50 wnd.module = {exports: wnd.exports}; | 50 wnd.module = {exports: wnd.exports}; |
| 51 | 51 |
| 52 let url = urls.shift(); | 52 let url = urls.shift(); |
| 53 let name = url.split("/").pop(); | 53 let name = url.split("/").pop(); |
| 54 return wnd.loadScript(url).then(() => | 54 return wnd.loadScript(url).then(() => |
| 55 { | 55 { |
| 56 modules[name] = nodeunit.testCase(wnd.module.exports); | 56 modules[name] = nodeunit.testCase(wnd.module.exports); |
| 57 return loadNext(); | 57 return loadNext(); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 | 60 |
| 61 return Promise.resolve(modules); | 61 return Promise.resolve(modules); |
| 62 }; | 62 })(); |
| 63 | |
| 64 return loadNext(); | |
| 65 } | 63 } |
| 66 | 64 |
| 67 function runTests(modules) | 65 function runTests(modules) |
| 68 { | 66 { |
| 69 function bold(str) | 67 function bold(str) |
| 70 { | 68 { |
| 71 return "\u001B[1m" + str + "\u001B[22m"; | 69 return "\u001B[1m" + str + "\u001B[22m"; |
| 72 } | 70 } |
| 73 | 71 |
| 74 function ok(str) | 72 function ok(str) |
| 75 { | 73 { |
| 76 return "\u001B[32m" + str + "\u001B[39m"; | 74 return "\u001B[32m" + str + "\u001B[39m"; |
| 77 } | 75 } |
| 78 | 76 |
| 79 function error(str) | 77 function error(str) |
| 80 { | 78 { |
| 81 return "\u001B[31m" + str + "\u001B[39m"; | 79 return "\u001B[31m" + str + "\u001B[39m"; |
| 82 } | 80 } |
| 83 | 81 |
| 84 return new Promise((resolve, reject) => | 82 return new Promise((resolve, reject) => |
| 85 { | 83 { |
| 86 nodeunit.runModules(modules, { | 84 nodeunit.runModules(modules, { |
| 87 moduleStart(name) | 85 moduleStart(name) |
| 88 { | 86 { |
| 89 console.log(bold(name)); | 87 console.log(bold(name)); |
| 90 }, | 88 }, |
| 91 testDone(name, assertions) | 89 testDone(name, assertions) |
| 92 { | 90 { |
| 93 let errors = assertions.filter(assertion => | 91 let errors = assertions.filter(assertion => assertion.failed()) |
| 94 { | 92 .map(assertion => assertion.error); |
| 95 return assertion.failed(); | |
| 96 }).map(assertion => | |
| 97 { | |
| 98 return assertion.error; | |
| 99 }); | |
| 100 | 93 |
| 101 if (errors.length == 0) | 94 if (errors.length == 0) |
| 102 console.log("\u2714 " + name); | 95 console.log("\u2714 " + name); |
| 103 else | 96 else |
| 104 { | 97 { |
| 105 console.log(error("\u2716 " + name) + "\n"); | 98 console.log(error("\u2716 " + name) + "\n"); |
| 106 errors.forEach(e => | 99 errors.forEach(e => |
| 107 { | 100 { |
| 108 if (e.stack) | 101 if (e.stack) |
| 109 console.log(e.stack); | 102 console.log(e.stack); |
| 110 else | 103 else |
| 111 console.log(String(e)); | 104 console.log(String(e)); |
| 112 console.log(""); | 105 console.log(""); |
| 113 }); | 106 }); |
| 114 } | 107 } |
| 115 }, | 108 }, |
| 116 done(assertions) | 109 done(assertions) |
| 117 { | 110 { |
| 118 let failures = assertions.filter(assertion => | 111 let failures = assertions.filter(assertion => assertion.failed()); |
| 119 { | |
| 120 return assertion.failed(); | |
| 121 }); | |
| 122 if (failures.length) | 112 if (failures.length) |
| 123 { | 113 { |
| 124 console.log( | 114 console.log( |
| 125 "\n" + | 115 "\n" + |
| 126 bold(error("FAILURES: ")) + | 116 bold(error("FAILURES: ")) + |
| 127 failures.length + "/" + assertions.length + " assertions failed" | 117 failures.length + "/" + assertions.length + " assertions failed" |
| 128 ); | 118 ); |
| 129 } | 119 } |
| 130 else | 120 else |
| 131 { | 121 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 } | 132 } |
| 143 | 133 |
| 144 return loadScript(document, nodeunitUrl).then(() => | 134 return loadScript(document, nodeunitUrl).then(() => |
| 145 { | 135 { |
| 146 return loadModules(moduleUrls); | 136 return loadModules(moduleUrls); |
| 147 }).then(modules => | 137 }).then(modules => |
| 148 { | 138 { |
| 149 return runTests(modules); | 139 return runTests(modules); |
| 150 }); | 140 }); |
| 151 }); | 141 }); |
| LEFT | RIGHT |