Skip to content

Commit

Permalink
Added unit testing to the pipeline, including the first test which ve…
Browse files Browse the repository at this point in the history
…rifies that initally, all except the first module are hidden.
  • Loading branch information
barnabycolby committed Aug 17, 2016
1 parent f3ed3f4 commit 6609240
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
3 changes: 2 additions & 1 deletion grunt/aliases.json
@@ -1,5 +1,6 @@
{
"default": [
"jslint"
"jslint",
"nodeunit"
]
}
3 changes: 2 additions & 1 deletion grunt/jslint.js
Expand Up @@ -4,7 +4,8 @@ module.exports = {
src: [
'Gruntfile.js',
'grunt/**/*.js',
'MMM-Carousel.js'
'MMM-Carousel.js',
'test.js'
]
}
};
4 changes: 4 additions & 0 deletions grunt/nodeunit.js
@@ -0,0 +1,4 @@
/*global module */
module.exports = {
main: ['test.js']
};
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -22,8 +22,9 @@
},
"homepage": "https://github.com/barnabycolby/MMM-Carousel#readme",
"dependencies": {
"grunt": "^1.0.1",
"grunt-jslint": "^1.1.14",
"load-grunt-config": "^0.19.2"
"grunt": "latest",
"grunt-jslint": "latest",
"load-grunt-config": "latest",
"grunt-contrib-nodeunit": "^1.0.0"
}
}
61 changes: 61 additions & 0 deletions test.js
@@ -0,0 +1,61 @@
/*global exports, require, console, global */
(function () {
'use strict';

var moduleObject, modulesList, i, hideFunction;

function initialiseModule() {
require('./MMM-Carousel.js');
moduleObject.notificationReceived('DOM_OBJECTS_CREATED');
}

global.Module = {
register: function (name, moduleObjectArgument) {
// To workaround a JSLint unused variable error for the first argument (name), we make JSLint think that the variable is used
// In newer versions of JSLint we can simply rename the variable to ignore to disable the warnings, but unfortunately, grunt-jslint
// is severely updated
var doNothing = function (nothing) {
return nothing;
};
doNothing(name);

moduleObject = moduleObjectArgument;
}
};

// We create a list of modules that can be hidden
modulesList = new Array(3);
hideFunction = function () {
this.hidden = true;
};
for (i = 0; i < 3; i += 1) {
modulesList[i] = {
hidden: false,
hide: hideFunction
};
}
modulesList.exceptModule = function () {
// As this is only used to exclude the current module, we can simply return the list without any modifications
return this;
};

global.MM = {
getModules: function () {
return modulesList;
}
};


exports.allModulesHiddenExceptFirst = function (test) {
var errorMessageForMostModules;

initialiseModule();

test.expect(3);
test.ok(!modulesList[0].hidden, "The first module in the config list should not initially be hidden.");
errorMessageForMostModules = "All modules except the first in the config list should be hidden initially.";
test.ok(modulesList[1].hidden, errorMessageForMostModules);
test.ok(modulesList[2].hidden, errorMessageForMostModules);
test.done();
};
}());

0 comments on commit 6609240

Please sign in to comment.