7721aa02 by Adam Heath

Update to support latest grunt-monty-python.

1 parent 56db38ec
...@@ -54,103 +54,10 @@ module.exports = function(grunt) { ...@@ -54,103 +54,10 @@ module.exports = function(grunt) {
54 beautify: false, 54 beautify: false,
55 compress: true, 55 compress: true,
56 }; 56 };
57 config.jasmine = {
58 withCoverage: true,
59 };
57 60
58 var montyPython = require('grunt-monty-python')(grunt); 61 var montyPython = require('grunt-monty-python')(grunt);
59 montyPython.createConfig(config); 62 montyPython.createConfig(config);
60
61 var _ = require('lodash');
62
63 function genJasmineConfig(withCoverage, options) {
64 var src = [
65 'src/scripts/{,**/}*.js',
66 '!src/scripts/main.js',
67 ];
68 var specs = [
69 'src/scripts/**/*.spec.js',
70 ];
71 var template = require('grunt-template-jasmine-requirejs');
72 var templateOptions = {
73 requireConfigFile: 'src/scripts/config.js',
74 requireConfig: {
75 baseUrl: 'src/scripts',
76 },
77 };
78
79 if (withCoverage) {
80 /* global requirejs */
81 templateOptions.requireConfig.callback = function() {
82 var oldLoad = requirejs.load;
83 requirejs.load = function (context, moduleName, url) {
84 var origUrl = url;
85 //console.log('context=' + JSON.stringify(arguments), 'moduleName=' + moduleName, 'url=' + url);
86 var parts = url.split('/');
87 for (var i = 0; i < parts.length; ) {
88 var part = parts[i];
89 if (part === '.') {
90 parts.splice(i, 1);
91 } else if (part === '') {
92 parts.splice(i, 1);
93 } else if (part === '..') {
94 if (i > 0) {
95 i--;
96 parts.splice(i, 2);
97 } else {
98 parts.splice(i, 1);
99 }
100 } else {
101 i++;
102 }
103 }
104 url = parts.join('/');
105 if (1) if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.spec\.js$/)) {
106 url = './.grunt/grunt-contrib-jasmine/' + url;
107 } else if (url.match(/^src\/scripts\/(.*?\/)?[^\/]+\.js$/)) {
108 url = './.grunt/grunt-contrib-jasmine/' + url;
109 }
110 if (url.indexOf('test/specs/') === 0) {
111 url = './.grunt/grunt-contrib-jasmine/' + url;
112 }
113 //console.log('url[' + origUrl + ']=' + url);
114 return oldLoad.apply(this, [context, moduleName, url]);
115 };
116 };
117
118 var foo = _.extend({}, template);
119 var bar = template.process;
120 foo.process = function process(grunt, task, context) {
121 var src = [];
122 context.scripts.src.forEach(function(file) {
123 if (!grunt.file.isMatch(specs, file)) {
124 src.push(file);
125 }
126 });
127 context.scripts.src = src;
128 return bar.apply(this, arguments);
129 };
130
131 templateOptions = {
132 coverage: 'dist/coverage/coverage.json',
133 report: 'dist/coverage',
134 replace: false,
135 template: foo,
136 templateOptions: templateOptions,
137 files: _.concat([], src, specs),
138 };
139 template = require('grunt-template-jasmine-istanbul');
140 }
141 var jasmineConfig = {
142 src: _.concat([],
143 src,
144 specs
145 ),
146 options: {
147 specs: specs,
148 template: template,
149 templateOptions: templateOptions,
150 },
151 };
152 return jasmineConfig;
153 }
154
155 grunt.config.set(['jasmine', 'all'], genJasmineConfig(true));
156 }; 63 };
......