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

Unified Diff: test/_common.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Patch Set: Stop using commonjs, fix other problems Created Feb. 21, 2017, 5:12 a.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
« no previous file with comments | « test/.eslintrc.json ('k') | test/domainRestrictions.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/_common.js
diff --git a/test/_common.js b/test/_common.js
index 2d9cf1ebf66eed7f92f5fb7bf499270ee1042bad..987a37c6d1d6ef4a7baaace71065ec0adec2617e 100644
--- a/test/_common.js
+++ b/test/_common.js
@@ -15,6 +15,8 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
+/* globals __dirname, console, Buffer */
+
"use strict";
let fs = require("fs");
@@ -32,34 +34,35 @@ const MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND;
const MILLIS_IN_HOUR = exports.MILLIS_IN_HOUR = 60 * MILLIS_IN_MINUTE;
const MILLIS_IN_DAY = exports.MILLIS_IN_DAY = 24 * MILLIS_IN_HOUR;
+function URL(urlString)
+{
+ return require("url").parse(urlString);
+}
+
let globals = {
atob: data => new Buffer(data, "base64").toString("binary"),
btoa: data => new Buffer(data, "binary").toString("base64"),
Ci: {
},
Cu: {
- import: () => {},
- reportError: e => undefined
+ import() {},
+ reportError(e) {}
},
console: {
- log: () => undefined,
- error: () => undefined,
+ log() {},
+ error() {}
},
navigator: {
},
onShutdown: {
- add: () =>
- {
- }
+ add() {}
},
Services: {
obs: {
- addObserver: () =>
- {
- }
+ addObserver() {}
},
vc: {
- compare: (v1, v2) =>
+ compare(v1, v2)
{
function comparePart(p1, p2)
{
@@ -69,8 +72,7 @@ let globals = {
return 1;
else if (p1 == p2)
return 0;
- else
- return parseInt(p1, 10) - parseInt(p2, 10);
+ return parseInt(p1, 10) - parseInt(p2, 10);
}
let parts1 = v1.split(".");
@@ -86,22 +88,21 @@ let globals = {
}
},
XPCOMUtils: {
- generateQI: () =>
- {
- }
+ generateQI() {}
},
- URL: function(urlString)
- {
- return require("url").parse(urlString);
- }
+ URL
};
let knownModules = new Map();
for (let dir of [path.join(__dirname, "stub-modules"),
path.join(__dirname, "..", "lib")])
+{
for (let file of fs.readdirSync(path.resolve(dir)))
+ {
if (path.extname(file) == ".js")
knownModules[path.basename(file, ".js")] = path.resolve(dir, file);
+ }
+}
function addExports(exports)
{
@@ -109,9 +110,13 @@ function addExports(exports)
{
let extraExports = exports[path.basename(this.filename, ".js")];
if (extraExports)
+ {
for (let name of extraExports)
+ {
source += `
Object.defineProperty(exports, "${name}", {get: () => ${name}});`;
+ }
+ }
return source;
};
}
@@ -144,7 +149,7 @@ exports.createSandbox = function(options)
// function which can be used to load further modules into the sandbox.
return SandboxedModule.require("./_common", {
globals: Object.assign({}, globals, options.globals),
- sourceTransformers: sourceTransformers
+ sourceTransformers
}).require;
};
@@ -160,7 +165,7 @@ exports.setupTimerAndXMLHttp = function()
delay: -1,
nextExecution: 0,
- initWithCallback: function(callback, delay, type)
+ initWithCallback(callback, delay, type)
{
if (this.callback)
throw new Error("Only one timer instance supported");
@@ -172,7 +177,7 @@ exports.setupTimerAndXMLHttp = function()
this.nextExecution = currentTime + delay;
},
- trigger: function()
+ trigger()
{
if (currentTime < this.nextExecution)
currentTime = this.nextExecution;
@@ -186,7 +191,7 @@ exports.setupTimerAndXMLHttp = function()
}
},
- cancel: function()
+ cancel()
{
this.nextExecution = -1;
}
@@ -198,9 +203,8 @@ exports.setupTimerAndXMLHttp = function()
this._host = "http://example.com";
this._loadHandlers = [];
this._errorHandlers = [];
- };
- XMLHttpRequest.prototype =
- {
+ }
+ XMLHttpRequest.prototype = {
_path: null,
_data: null,
_queryString: null,
@@ -210,7 +214,7 @@ exports.setupTimerAndXMLHttp = function()
readyState: 0,
responseText: null,
- addEventListener: function(eventName, handler, capture)
+ addEventListener(eventName, handler, capture)
{
let list;
if (eventName == "load")
@@ -224,7 +228,7 @@ exports.setupTimerAndXMLHttp = function()
list.push(handler);
},
- removeEventListener: function(eventName, handler, capture)
+ removeEventListener(eventName, handler, capture)
{
let list;
if (eventName == "load")
@@ -239,7 +243,7 @@ exports.setupTimerAndXMLHttp = function()
list.splice(index, 1);
},
- open: function(method, url, async, user, password)
+ open(method, url, async, user, password)
{
if (method != "GET")
throw new Error("Only GET requests are supported");
@@ -269,7 +273,7 @@ exports.setupTimerAndXMLHttp = function()
}
},
- send: function(data)
+ send(data)
{
if (!this._data && !this._path)
throw new Error("No request path set");
@@ -300,7 +304,7 @@ exports.setupTimerAndXMLHttp = function()
}));
},
- overrideMimeType: function(mime)
+ overrideMimeType(mime)
{
},
@@ -316,9 +320,9 @@ exports.setupTimerAndXMLHttp = function()
};
XMLHttpRequest.requestHandlers = {};
- this.registerHandler = (path, handler) =>
+ this.registerHandler = (requestPath, handler) =>
{
- XMLHttpRequest.requestHandlers[path] = handler;
+ XMLHttpRequest.requestHandlers[requestPath] = handler;
};
function waitForRequests()
@@ -332,8 +336,7 @@ exports.setupTimerAndXMLHttp = function()
console.error(e);
}).then(() => waitForRequests());
}
- else
- return Promise.resolve();
+ return Promise.resolve();
}
function runScheduledTasks(maxMillis)
@@ -344,13 +347,8 @@ exports.setupTimerAndXMLHttp = function()
currentTime = endTime;
return Promise.resolve();
}
- else
- {
- fakeTimer.trigger();
- return waitForRequests().then(() => runScheduledTasks(endTime - currentTime));
- }
-
- currentTime = endTime;
+ fakeTimer.trigger();
+ return waitForRequests().then(() => runScheduledTasks(endTime - currentTime));
}
this.runScheduledTasks = (maxHours, initial, skip) =>
@@ -399,7 +397,7 @@ exports.setupTimerAndXMLHttp = function()
TYPE_REPEATING_SLACK: 1,
TYPE_REPEATING_PRECISE: 2
},
- nsIHttpChannel: () => null,
+ nsIHttpChannel: () => null
},
Cr,
XMLHttpRequest,
@@ -409,6 +407,10 @@ exports.setupTimerAndXMLHttp = function()
};
};
+/* eslint-disable no-console */
+console.warn = console.log;
+/* eslint-enable no-console */
+
exports.setupRandomResult = function()
{
let randomResult = 0.5;
« no previous file with comments | « test/.eslintrc.json ('k') | test/domainRestrictions.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld