f1701c26 by Adam Heath

Add support for jasmine.

1 parent 7c0a2e88
......@@ -391,6 +391,92 @@ module.exports = function (grunt) {
}
};
}
if (mpConfig.jasmine) {
var src = [
mpConfig.base + '/scripts/{,**/}*.js',
'!' + mpConfig.base + '/scripts/main.js',
];
var specs = [
mpConfig.base + '/scripts/**/*.spec.js',
];
var template = require('grunt-template-jasmine-requirejs');
var templateOptions = {
requireConfigFile: mpConfig.base + '/scripts/config.js',
requireConfig: {
baseUrl: mpConfig.base + '/scripts',
},
};
if (mpConfig.jasmine.withCoverage) {
templateOptions.requireConfig.callback = function() {
/* global requirejs:false */
var oldLoad = requirejs.load;
requirejs.load = function (context, moduleName, url) {
//console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url);
var parts = url.split('/');
for (var i = 0; i < parts.length; ) {
var part = parts[i];
if (part === '.') {
parts.splice(i, 1);
} else if (part === '') {
parts.splice(i, 1);
} else if (part === '..') {
if (i > 0) {
i--;
parts.splice(i, 2);
} else {
parts.splice(i, 1);
}
} else {
i++;
}
}
url = parts.join('/');
if (url.indexOf(mpConfig.base + '/scripts/') === 0) {
url = './.grunt/grunt-contrib-jasmine/' + url;
}
return oldLoad.apply(this, [context, moduleName, url]);
};
};
templateOptions = {
coverage: 'dist/coverage/coverage.json',
report: 'dist/coverage',
replace: false,
template: _.extend({}, template, {
process: (function(origProcess) {
return function process(grunt, task, context) {
var src = [];
context.scripts.src.forEach(function(file) {
if (!grunt.file.isMatch(specs, file)) {
src.push(file);
}
});
context.scripts.src = src;
return origProcess.apply(this, arguments);
};
})(template.process),
}),
templateOptions: templateOptions,
files: _.concat([], src, specs),
};
template = require('grunt-template-jasmine-istanbul');
}
initConfig.jasmine = {
options: {
template: template,
templateOptions: templateOptions,
},
all: {
src: _.concat([],
src,
specs
),
options: {
specs: specs,
},
},
};
}
if (mpConfig.css) {
initConfig.copy.css = {
......
......@@ -24,11 +24,14 @@
"grunt-contrib-jshint": "~0",
"grunt-contrib-htmlmin": "~0",
"grunt-contrib-imagemin": "~0",
"grunt-contrib-jasmine": "",
"grunt-contrib-requirejs": "~0",
"grunt-contrib-uglify": "~0",
"grunt-jscs": "",
"grunt-rev": "~0",
"grunt-svgmin": "~0",
"grunt-template-jasmine-istanbul": "",
"grunt-template-jasmine-requirejs": "",
"grunt-usemin": "~2",
"jshint-stylish": "~0",
"load-grunt-tasks": "~0",
......