f1701c26 by Adam Heath

Add support for jasmine.

1 parent 7c0a2e88
...@@ -391,6 +391,92 @@ module.exports = function (grunt) { ...@@ -391,6 +391,92 @@ module.exports = function (grunt) {
391 } 391 }
392 }; 392 };
393 } 393 }
394 if (mpConfig.jasmine) {
395 var src = [
396 mpConfig.base + '/scripts/{,**/}*.js',
397 '!' + mpConfig.base + '/scripts/main.js',
398 ];
399 var specs = [
400 mpConfig.base + '/scripts/**/*.spec.js',
401 ];
402 var template = require('grunt-template-jasmine-requirejs');
403 var templateOptions = {
404 requireConfigFile: mpConfig.base + '/scripts/config.js',
405 requireConfig: {
406 baseUrl: mpConfig.base + '/scripts',
407 },
408 };
409 if (mpConfig.jasmine.withCoverage) {
410 templateOptions.requireConfig.callback = function() {
411 /* global requirejs:false */
412 var oldLoad = requirejs.load;
413 requirejs.load = function (context, moduleName, url) {
414 //console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url);
415 var parts = url.split('/');
416 for (var i = 0; i < parts.length; ) {
417 var part = parts[i];
418 if (part === '.') {
419 parts.splice(i, 1);
420 } else if (part === '') {
421 parts.splice(i, 1);
422 } else if (part === '..') {
423 if (i > 0) {
424 i--;
425 parts.splice(i, 2);
426 } else {
427 parts.splice(i, 1);
428 }
429 } else {
430 i++;
431 }
432 }
433 url = parts.join('/');
434 if (url.indexOf(mpConfig.base + '/scripts/') === 0) {
435 url = './.grunt/grunt-contrib-jasmine/' + url;
436 }
437 return oldLoad.apply(this, [context, moduleName, url]);
438 };
439 };
440
441 templateOptions = {
442 coverage: 'dist/coverage/coverage.json',
443 report: 'dist/coverage',
444 replace: false,
445 template: _.extend({}, template, {
446 process: (function(origProcess) {
447 return function process(grunt, task, context) {
448 var src = [];
449 context.scripts.src.forEach(function(file) {
450 if (!grunt.file.isMatch(specs, file)) {
451 src.push(file);
452 }
453 });
454 context.scripts.src = src;
455 return origProcess.apply(this, arguments);
456 };
457 })(template.process),
458 }),
459 templateOptions: templateOptions,
460 files: _.concat([], src, specs),
461 };
462 template = require('grunt-template-jasmine-istanbul');
463 }
464 initConfig.jasmine = {
465 options: {
466 template: template,
467 templateOptions: templateOptions,
468 },
469 all: {
470 src: _.concat([],
471 src,
472 specs
473 ),
474 options: {
475 specs: specs,
476 },
477 },
478 };
479 }
394 480
395 if (mpConfig.css) { 481 if (mpConfig.css) {
396 initConfig.copy.css = { 482 initConfig.copy.css = {
......
...@@ -24,11 +24,14 @@ ...@@ -24,11 +24,14 @@
24 "grunt-contrib-jshint": "~0", 24 "grunt-contrib-jshint": "~0",
25 "grunt-contrib-htmlmin": "~0", 25 "grunt-contrib-htmlmin": "~0",
26 "grunt-contrib-imagemin": "~0", 26 "grunt-contrib-imagemin": "~0",
27 "grunt-contrib-jasmine": "",
27 "grunt-contrib-requirejs": "~0", 28 "grunt-contrib-requirejs": "~0",
28 "grunt-contrib-uglify": "~0", 29 "grunt-contrib-uglify": "~0",
29 "grunt-jscs": "", 30 "grunt-jscs": "",
30 "grunt-rev": "~0", 31 "grunt-rev": "~0",
31 "grunt-svgmin": "~0", 32 "grunt-svgmin": "~0",
33 "grunt-template-jasmine-istanbul": "",
34 "grunt-template-jasmine-requirejs": "",
32 "grunt-usemin": "~2", 35 "grunt-usemin": "~2",
33 "jshint-stylish": "~0", 36 "jshint-stylish": "~0",
34 "load-grunt-tasks": "~0", 37 "load-grunt-tasks": "~0",
......