| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 "use strict"; | |
| 2 | |
| 3 let nodeBabel = require("node-babel"); | |
| 4 let nodeunit = require("nodeunit"); | |
| 5 let path = require("path"); | |
| 6 | |
| 7 // The Adblock Plus code assumes some things are present in the global scope. | |
| 8 // We need to stub them out here to get the tests running. | |
| 9 GLOBAL.atob = data => new Buffer(data, "base64").toString("binary"); | |
| 10 GLOBAL.btoa = data => new Buffer(data, "binary").toString("base64"); | |
| 11 GLOBAL.Ci = {}; | |
| 12 GLOBAL.Cu = { | |
| 13 import: () => { } | |
| 14 }; | |
| 15 GLOBAL.navigator = {}; | |
| 16 GLOBAL.onShutdown = { | |
| 17 add: () => { } | |
| 18 }; | |
| 19 GLOBAL.Services = { | |
| 20 obs: { | |
| 21 addObserver: () => { } | |
| 22 } | |
| 23 }; | |
| 24 GLOBAL.XPCOMUtils = { | |
| 25 generateQI: () => { } | |
| 26 }; | |
| 27 | |
| 28 // Force the use of our modules over the Node.js builtin modules when the names | |
| 29 // clash by messing with the module cache. (It's important we load any Node.js | |
| 30 // modules beforehand, otherwise they will might break when given our modules!) | |
|
Wladimir Palant
2016/09/26 09:40:58
Messing with the global require function is a bad
kzar
2016/09/29 15:53:10
Done.
| |
| 31 function forceModule(name, relativePath) | |
| 32 { | |
| 33 let filename = name + ".js"; | |
| 34 let absolutePath = path.join(__dirname, relativePath, filename); | |
| 35 require(absolutePath); | |
| 36 require.cache[name] = require.cache[absolutePath]; | |
| 37 } | |
| 38 forceModule("events", "lib"); | |
| 39 forceModule("io", "test/stub-modules"); | |
| 40 | |
| 41 nodeBabel(); | |
|
Wladimir Palant
2016/09/26 09:40:58
This should no longer be necessary if we require a
kzar
2016/09/29 15:53:10
Done.
| |
| 42 nodeunit.reporters.default.run(["test"]); | |
| LEFT | RIGHT |