Skip to content

Commit

Permalink
Renamed suite to gremlin
Browse files Browse the repository at this point in the history
  • Loading branch information
ThieryMichel committed Oct 27, 2013
1 parent cec2e87 commit 33e577d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 66 deletions.
10 changes: 5 additions & 5 deletions demo/index.html
Expand Up @@ -7,10 +7,10 @@
</head>

<body>
<script src="../src/monkeyTest.js"></script>
<script src="../src/clickMonkey.js"></script>
<script src="../src/scrollMonkey.js"></script>
<script src="../src/typeMonkey.js"></script>
<script src="../src/gremlins.js"></script>
<script src="../src/clickerGremlin.js"></script>
<script src="../src/scrollerGremlin.js"></script>
<script src="../src/typerGremlin.js"></script>
<script src="../test.js"></script>
</body>
</html>
</html>
22 changes: 11 additions & 11 deletions src/clickMonkey.js → 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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
};
56 changes: 28 additions & 28 deletions src/monkeyTest.js → 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 = [];
};

Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -110,9 +110,9 @@ var MonkeyTest = (function() {
});
};

MonkeyTest.createSuite = function() {
return new MonkeyTestSuite();
Gremlins.createHorde = function() {
return new GremlinsHorde();
};

return MonkeyTest;
return Gremlins;
})();
14 changes: 7 additions & 7 deletions src/scrollMonkey.js → 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,
Expand Down Expand Up @@ -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 )),
Expand All @@ -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;
};
18 changes: 9 additions & 9 deletions src/typeMonkey.js → 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,
Expand Down Expand Up @@ -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"),
Expand All @@ -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;
};
12 changes: 6 additions & 6 deletions test.js
@@ -1,4 +1,4 @@
MonkeyTest.createSuite()
Gremlins.createHorde()
.before(function(done) {
setTimeout(function(){
console.log('async');
Expand All @@ -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);

0 comments on commit 33e577d

Please sign in to comment.