Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test_wrapper.js

Issue 29354864: Issue 4223 - Migrate some more of adblockplustests (Closed)
Patch Set: Created Sept. 25, 2016, 1:38 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« test/filterListener.js ('K') | « test/stub-modules/io.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test_wrapper.js
diff --git a/test_wrapper.js b/test_wrapper.js
index 75e034d995dbb8acd18ebbcac271a2f5f712c83d..c676b2788be101c7c2bd6765d8518ef45a217fc4 100644
--- a/test_wrapper.js
+++ b/test_wrapper.js
@@ -1,9 +1,42 @@
"use strict";
+let nodeBabel = require("node-babel");
+let nodeunit = require("nodeunit");
+let path = require("path");
+
+// The Adblock Plus code assumes some things are present in the global scope.
+// We need to stub them out here to get the tests running.
GLOBAL.atob = data => new Buffer(data, "base64").toString("binary");
GLOBAL.btoa = data => new Buffer(data, "binary").toString("base64");
+GLOBAL.Ci = {};
+GLOBAL.Cu = {
+ import: () => { }
+};
GLOBAL.navigator = {};
+GLOBAL.onShutdown = {
+ add: () => { }
+};
+GLOBAL.Services = {
+ obs: {
+ addObserver: () => { }
+ }
+};
+GLOBAL.XPCOMUtils = {
+ generateQI: () => { }
+};
-require("node-babel")();
+// Force the use of our modules over the Node.js builtin modules when the names
+// clash by messing with the module cache. (It's important we load any Node.js
+// 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.
+function forceModule(name, relativePath)
+{
+ let filename = name + ".js";
+ let absolutePath = path.join(__dirname, relativePath, filename);
+ require(absolutePath);
+ require.cache[name] = require.cache[absolutePath];
+}
+forceModule("events", "lib");
+forceModule("io", "test/stub-modules");
-require("./node_modules/.bin/nodeunit");
+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.
+nodeunit.reporters.default.run(["test"]);
« test/filterListener.js ('K') | « test/stub-modules/io.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld