UNPKG

1.71 kBJavaScriptView Raw
1(function () {
2 'use strict';
3
4 module.exports = function (grunt) {
5 var glob = require("glob"),
6 path = require('path');
7
8 /**
9 * Merge all coverage results.
10 * Because the sources will be copied we need to fix the paths for coverage
11 *
12 * #1 iterate over each location .
13 * #2 replace the suffix
14 * #3 append the tests to the result.
15 * #4 write merged results to file.
16 */
17 function merge(locations, outputFile, type) {
18 var CURRENT_PATH = '.',
19 resultContent = '';
20
21 // #1
22 locations.forEach(function (l) {
23 var cwd = (l.cwd || CURRENT_PATH) + path.sep;
24
25 if (l.reports[type]) {
26 glob.sync(l.reports[type], {cwd: cwd, root: '/'}).forEach(function (file) {
27 // #2
28 var content = grunt.file.read(cwd + file).
29 replace(new RegExp('(SF:)(.*?' + l.src + ')(.*)', 'g'), '$1.' + path.sep + l.src + '$3');
30
31 // #3
32 resultContent = resultContent.concat(content);
33 });
34 } else {
35 if (type === 'itCoverage') {
36 grunt.log.warn('No integration coverage report has been specified');
37 } else {
38 grunt.log.warn('No coverage report has been specified');
39 }
40 }
41 });
42 // #4
43 grunt.file.write(outputFile, resultContent, {encoding: 'utf8'});
44 }
45
46 return {
47 merge: merge
48 };
49
50 };
51})();
\No newline at end of file