From 33e577da250f6b45b27300297c5625226ad38d1d Mon Sep 17 00:00:00 2001 From: ThieryMichel Date: Sun, 27 Oct 2013 15:26:26 +0100 Subject: [PATCH] Renamed suite to gremlin --- demo/index.html | 10 ++-- src/{clickMonkey.js => clickerGremlin.js} | 22 ++++---- src/{monkeyTest.js => gremlins.js} | 56 ++++++++++----------- src/{scrollMonkey.js => scrollerGremlin.js} | 14 +++--- src/{typeMonkey.js => typerGremlin.js} | 18 +++---- test.js | 12 ++--- 6 files changed, 66 insertions(+), 66 deletions(-) rename src/{clickMonkey.js => clickerGremlin.js} (87%) rename src/{monkeyTest.js => gremlins.js} (58%) rename src/{scrollMonkey.js => scrollerGremlin.js} (89%) rename src/{typeMonkey.js => typerGremlin.js} (90%) diff --git a/demo/index.html b/demo/index.html index 4a959e5..1eaf6d4 100644 --- a/demo/index.html +++ b/demo/index.html @@ -7,10 +7,10 @@ - - - - + + + + - \ No newline at end of file + diff --git a/src/clickMonkey.js b/src/clickerGremlin.js similarity index 87% rename from src/clickMonkey.js rename to src/clickerGremlin.js index 714c459..5cc39da 100644 --- a/src/clickMonkey.js +++ b/src/clickerGremlin.js @@ -1,7 +1,7 @@ -var MonkeyTest = MonkeyTest || {}; -MonkeyTest.crew = MonkeyTest.crew || {}; +var Gremlins = Gremlins || {}; +Gremlins.crew = Gremlins.crew || {}; -MonkeyTest.crew.ClickMonkey = function() { +Gremlins.crew.ClickerGremlin = function() { var document = window.document, body = document.body; @@ -42,7 +42,7 @@ MonkeyTest.crew.ClickMonkey = function() { canClick: function() { return true; } }; - function monkey(callback) { + function gremlin(callback) { var posX = Math.floor(Math.random() * document.documentElement.clientWidth), posY = Math.floor(Math.random() * document.documentElement.clientHeight), targetElement = document.elementFromPoint(posX, posY); @@ -62,23 +62,23 @@ MonkeyTest.crew.ClickMonkey = function() { } } - monkey.clickTypes = function(clickTypes) { + gremlin.clickTypes = function(clickTypes) { if (!arguments.length) return config.clickTypes; config.clickTypes = clickTypes; - return monkey; + return gremlin; }; - monkey.showAction = function(showAction) { + gremlin.showAction = function(showAction) { if (!arguments.length) return config.showAction; config.showAction = showAction; - return monkey; + return gremlin; }; - monkey.canClick = function(canClick) { + gremlin.canClick = function(canClick) { if (!arguments.length) return config.canClick; config.canClick = canClick; - return monkey; + return gremlin; }; - return monkey; + return gremlin; }; diff --git a/src/monkeyTest.js b/src/gremlins.js similarity index 58% rename from src/monkeyTest.js rename to src/gremlins.js index d0461dc..5c49f96 100644 --- a/src/monkeyTest.js +++ b/src/gremlins.js @@ -1,14 +1,14 @@ -var MonkeyTest = (function() { +var Gremlins = (function() { - var MonkeyTest = { + var Gremlins = { crew: {} }; - var MonkeyTestSuite = function() { + var GremlinsHorde = function() { this._beforeCallbacks = []; this._afterCallbacks = []; - this._monkeys = []; - this._runners = []; + this._gremlins = []; + this._unleashers = []; this._loggers = []; }; @@ -34,43 +34,43 @@ var MonkeyTest = (function() { })(callbacks, args, done); }; - MonkeyTestSuite.prototype.before = function(beforeCallback) { + GremlinsHorde.prototype.before = function(beforeCallback) { this._beforeCallbacks.push(beforeCallback); return this; }; - MonkeyTestSuite.prototype.after = function(afterCallback) { + GremlinsHorde.prototype.after = function(afterCallback) { this._afterCallbacks.push(afterCallback); return this; }; - MonkeyTestSuite.prototype.monkey = function(monkeyCallback) { - this._monkeys.push(monkeyCallback); + GremlinsHorde.prototype.breed = function(gremlin) { + this._gremlins.push(gremlin); return this; }; - MonkeyTestSuite.prototype.allMonkeys = function() { - for (var monkeyName in MonkeyTest.crew) { - this.monkey(MonkeyTest.crew[monkeyName]()); + GremlinsHorde.prototype.breedAll = function() { + for (var gremlinName in Gremlins.crew) { + this.breed(Gremlins.crew[gremlinName]()); } return this; }; - MonkeyTestSuite.prototype.runner = function(runnerCallback) { - this._runners.push(runnerCallback); + GremlinsHorde.prototype.unleasher = function(unleasherCallback) { + this._unleashers.push(unleasherCallback); return this; }; - // run each monkey every 10 milliseconds for nb times - var defaultRunner = function(monkeys, nb, done) { + // run each gremlin every 10 milliseconds for nb times + var defaultUnleasher = function(gremlins, nb, done) { var i = 0, j, - count = monkeys.length; + count = gremlins.length; while (i < nb) { for (j = 0; j < count; j++) { (function(i, j) { setTimeout(function(){ - monkeys[j](); + gremlins[j](); if (i == nb -1 && j == count - 1){ done(); @@ -82,25 +82,25 @@ var MonkeyTest = (function() { } }; - var runRunners = function(runners, monkeys, nb, done) { - if (runners.length === 0) { - defaultRunner(monkeys, nb, done); + var runUnleashers = function(unleashers, gremlins, nb, done) { + if (unleashers.length === 0) { + defaultUnleasher(gremlins, nb, done); } else { - callCallbacks(runners, [monkeys, nb], done); + callCallbacks(unleashers, [gremlins, nb], done); } }; - MonkeyTestSuite.prototype.logger = function(loggerCallback) { + GremlinsHorde.prototype.logger = function(loggerCallback) { this._loggers.push(loggerCallback); return this; }; - MonkeyTestSuite.prototype.run = function(nb, done) { + GremlinsHorde.prototype.unleash = function(nb, done) { var i; var self = this; callCallbacks(this._beforeCallbacks, [], function () { - runRunners(self._runners, self._monkeys, nb, function() { + runUnleashers(self._unleashers, self._gremlins, nb, function() { callCallbacks(self._afterCallbacks, [], function () { if (typeof done === 'function') { done(); @@ -110,9 +110,9 @@ var MonkeyTest = (function() { }); }; - MonkeyTest.createSuite = function() { - return new MonkeyTestSuite(); + Gremlins.createHorde = function() { + return new GremlinsHorde(); }; - return MonkeyTest; + return Gremlins; })(); diff --git a/src/scrollMonkey.js b/src/scrollerGremlin.js similarity index 89% rename from src/scrollMonkey.js rename to src/scrollerGremlin.js index 7f3c2d5..8fa49c9 100644 --- a/src/scrollMonkey.js +++ b/src/scrollerGremlin.js @@ -1,7 +1,7 @@ -var MonkeyTest = MonkeyTest || {}; -MonkeyTest.crew = MonkeyTest.crew || {}; +var Gremlins = Gremlins || {}; +Gremlins.crew = Gremlins.crew || {}; -MonkeyTest.crew.ScrollMonkey = function() { +Gremlins.crew.ScrollerGremlin = function() { var document = window.document, documentElement = document.documentElement, @@ -31,7 +31,7 @@ MonkeyTest.crew.ScrollMonkey = function() { showAction: defaultShowAction }; - function monkey(callback) { + function gremlin(callback) { var documentWidth = Math.max(body.scrollWidth, body.offsetWidth, documentElement.scrollWidth, documentElement.offsetWidth, documentElement.clientWidth), documentHeight = Math.max(body.scrollHeight, body.offsetHeight, documentElement.scrollHeight, documentElement.offsetHeight, documentElement.clientHeight), scrollX = Math.floor(Math.random() * (documentWidth - documentElement.clientWidth )), @@ -47,11 +47,11 @@ MonkeyTest.crew.ScrollMonkey = function() { } } - monkey.showAction = function(showAction) { + gremlin.showAction = function(showAction) { if (!arguments.length) return config.showAction; config.showAction = showAction; - return monkey; + return gremlin; }; - return monkey; + return gremlin; }; diff --git a/src/typeMonkey.js b/src/typerGremlin.js similarity index 90% rename from src/typeMonkey.js rename to src/typerGremlin.js index 87940ce..74e594c 100644 --- a/src/typeMonkey.js +++ b/src/typerGremlin.js @@ -1,9 +1,9 @@ /*jslint browser: true*/ -var MonkeyTest = MonkeyTest || {}; -MonkeyTest.crew = MonkeyTest.crew || {}; +var Gremlins = Gremlins || {}; +Gremlins.crew = Gremlins.crew || {}; -MonkeyTest.crew.TypeMonkey = function() { +Gremlins.crew.TyperGremlin = function() { "use strict"; var document = window.document, @@ -51,7 +51,7 @@ MonkeyTest.crew.TypeMonkey = function() { showAction: defaultShowAction }; - function monkey(callback) { + function gremlin(callback) { var documentWidth = Math.max(body.scrollWidth, body.offsetWidth, documentElement.scrollWidth, documentElement.offsetWidth, documentElement.clientWidth), documentHeight = Math.max(body.scrollHeight, body.offsetHeight, documentElement.scrollHeight, documentElement.offsetHeight, documentElement.clientHeight), keyboardEvent = document.createEvent("KeyboardEvent"), @@ -73,17 +73,17 @@ MonkeyTest.crew.TypeMonkey = function() { } } - monkey.eventTypes = function(eventTypes) { + gremlin.eventTypes = function(eventTypes) { if (!arguments.length) return config.eventTypes; config.eventTypes = eventTypes; - return monkey; + return gremlin; }; - monkey.showAction = function(showAction) { + gremlin.showAction = function(showAction) { if (!arguments.length) return config.showAction; config.showAction = showAction; - return monkey; + return gremlin; }; - return monkey; + return gremlin; }; diff --git a/test.js b/test.js index 1f02bd2..4007499 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,4 @@ -MonkeyTest.createSuite() +Gremlins.createHorde() .before(function(done) { setTimeout(function(){ console.log('async'); @@ -8,12 +8,12 @@ MonkeyTest.createSuite() .before(function() { console.log('sync'); }) - .monkey(MonkeyTest.crew.ClickMonkey().clickTypes(['click'])) - .monkey(MonkeyTest.crew.ScrollMonkey()) - .monkey(function() { - console.log('I\'m a monkey!'); + .breed(Gremlins.crew.ClickerGremlin().clickTypes(['click'])) + .breed(Gremlins.crew.ScrollerGremlin()) + .breed(function() { + console.log('I\'m a gremlin!'); }) .after(function() { console.log('finished!'); }) - .run(10); + .unleash(10);