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

Unified Diff: test/filterNotifier.js

Issue 30025555: Issue 6820 - Move tests to mocha (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased Created April 10, 2019, 6:33 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
« no previous file with comments | « test/filterListener.js ('k') | test/filterStorage.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/filterNotifier.js
===================================================================
--- a/test/filterNotifier.js
+++ b/test/filterNotifier.js
@@ -12,112 +12,110 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
+const assert = require("assert");
const {createSandbox} = require("./_common");
let filterNotifier = null;
-exports.setUp = function(callback)
-{
- let sandboxedRequire = createSandbox();
- (
- {filterNotifier} = sandboxedRequire("../lib/filterNotifier")
- );
-
- callback();
-};
-
-let triggeredListeners = [];
-let listeners = [
- (...args) => triggeredListeners.push(["listener1", ...args]),
- (...args) => triggeredListeners.push(["listener2", ...args]),
- (...args) => triggeredListeners.push(["listener3", ...args])
-];
-
-function addListener(listener)
-{
- filterNotifier.on("foo", listener);
-}
-
-function removeListener(listener)
+describe("Filter Notifier", () =>
{
- filterNotifier.off("foo", listener);
-}
+ beforeEach(() =>
+ {
+ let sandboxedRequire = createSandbox();
+ (
+ {filterNotifier} = sandboxedRequire("../lib/filterNotifier")
+ );
+ });
-function compareListeners(test, testDescription, list)
-{
- test.equal(filterNotifier.hasListeners(), list.length > 0, testDescription);
- test.equal(filterNotifier.hasListeners("foo"), list.length > 0,
- testDescription);
+ let triggeredListeners = [];
+ let listeners = [
+ (...args) => triggeredListeners.push(["listener1", ...args]),
+ (...args) => triggeredListeners.push(["listener2", ...args]),
+ (...args) => triggeredListeners.push(["listener3", ...args])
+ ];
- test.equal(filterNotifier.hasListeners("bar"), false, testDescription);
+ function addListener(listener)
+ {
+ filterNotifier.on("foo", listener);
+ }
- let result1 = triggeredListeners = [];
- filterNotifier.emit("foo", {bar: true});
+ function removeListener(listener)
+ {
+ filterNotifier.off("foo", listener);
+ }
- let result2 = triggeredListeners = [];
- for (let observer of list)
- observer({bar: true});
+ function compareListeners(testDescription, list)
+ {
+ assert.equal(filterNotifier.hasListeners(), list.length > 0, testDescription);
+ assert.equal(filterNotifier.hasListeners("foo"), list.length > 0,
+ testDescription);
+
+ assert.equal(filterNotifier.hasListeners("bar"), false, testDescription);
- test.deepEqual(result1, result2, testDescription);
-}
+ let result1 = triggeredListeners = [];
+ filterNotifier.emit("foo", {bar: true});
+
+ let result2 = triggeredListeners = [];
+ for (let observer of list)
+ observer({bar: true});
-exports.testAddingRemovingListeners = function(test)
-{
- let [listener1, listener2, listener3] = listeners;
+ assert.deepEqual(result1, result2, testDescription);
+ }
+
+ it("Add/Remove Listeners", () =>
+ {
+ let [listener1, listener2, listener3] = listeners;
- compareListeners(test, "No listeners", []);
+ compareListeners("No listeners", []);
- addListener(listener1);
- compareListeners(test, "addListener(listener1)", [listener1]);
+ addListener(listener1);
+ compareListeners("addListener(listener1)", [listener1]);
- addListener(listener1);
- compareListeners(test, "addListener(listener1) again", [listener1, listener1]);
+ addListener(listener1);
+ compareListeners("addListener(listener1) again", [listener1, listener1]);
- addListener(listener2);
- compareListeners(test, "addListener(listener2)", [listener1, listener1, listener2]);
+ addListener(listener2);
+ compareListeners("addListener(listener2)", [listener1, listener1, listener2]);
- removeListener(listener1);
- compareListeners(test, "removeListener(listener1)", [listener1, listener2]);
+ removeListener(listener1);
+ compareListeners("removeListener(listener1)", [listener1, listener2]);
- removeListener(listener1);
- compareListeners(test, "removeListener(listener1) again", [listener2]);
+ removeListener(listener1);
+ compareListeners("removeListener(listener1) again", [listener2]);
- addListener(listener3);
- compareListeners(test, "addListener(listener3)", [listener2, listener3]);
+ addListener(listener3);
+ compareListeners("addListener(listener3)", [listener2, listener3]);
- addListener(listener1);
- compareListeners(test, "addListener(listener1)", [listener2, listener3, listener1]);
-
- removeListener(listener3);
- compareListeners(test, "removeListener(listener3)", [listener2, listener1]);
+ addListener(listener1);
+ compareListeners("addListener(listener1)", [listener2, listener3, listener1]);
- removeListener(listener1);
- compareListeners(test, "removeListener(listener1)", [listener2]);
+ removeListener(listener3);
+ compareListeners("removeListener(listener3)", [listener2, listener1]);
- removeListener(listener2);
- compareListeners(test, "removeListener(listener2)", []);
+ removeListener(listener1);
+ compareListeners("removeListener(listener1)", [listener2]);
- test.done();
-};
+ removeListener(listener2);
+ compareListeners("removeListener(listener2)", []);
+ });
-exports.testRemovingListenersWhileBeingCalled = function(test)
-{
- let listener1 = function(...args)
+ it("Removing listeners while being called", () =>
{
- listeners[0](...args);
- removeListener(listener1);
- };
- let listener2 = listeners[1];
- addListener(listener1);
- addListener(listener2);
+ let listener1 = function(...args)
+ {
+ listeners[0](...args);
+ removeListener(listener1);
+ };
+ let listener2 = listeners[1];
+ addListener(listener1);
+ addListener(listener2);
- compareListeners(test, "Initial call", [listener1, listener2]);
- compareListeners(test, "Subsequent calls", [listener2]);
-
- test.done();
-};
+ compareListeners("Initial call", [listener1, listener2]);
+ compareListeners("Subsequent calls", [listener2]);
+ });
+});
« no previous file with comments | « test/filterListener.js ('k') | test/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld