UNPKG

2.29 kBJavaScriptView Raw
1/*jshint -W083 */
2(function () {
3 'use strict';
4
5 var glob = require("glob"),
6 path = require('path');
7
8 module.exports = function (grunt) {
9 var PREFIX = '<?xml version="1.0"?><testsuites>',
10 SUFFIX = '</testsuites>',
11 jasmineJunit = require(__dirname + '/jasmineJunit')(grunt),
12 cucumberJunit = require(__dirname + '/cucumberJunit')(grunt);
13
14 /**
15 * Merge all junit results.
16 *
17 * #1 iterate over each location.
18 * #2 check what framework is used (defaults to jasmine)
19 * #3 merge the files
20 * #4 write merged results to file.
21 */
22 function merge(locations, outputFile, type) {
23 var testType = (type === 'itUnit' ? ' integration' : ''),
24 resultContent = PREFIX;
25
26 // #1
27 locations.forEach(function (l) {
28 var report = l.reports[type],
29 framework = ((report !== undefined && typeof report === 'object') && report.framework ? report.framework : 'jasmine'),
30 source = ((report !== undefined && typeof report === 'object') ? report.src : report),
31 cwd = (l.cwd || '.') + path.sep,
32 testDir = cwd + l.test,
33 testDirExists = grunt.file.exists(testDir);
34
35 if (source) {
36 if (l.test && testDirExists) {
37 // #2
38 if(framework === 'jasmine' || framework === 'jasmine2') {
39 // #3
40 resultContent = resultContent.concat(jasmineJunit.mergeLocation(source, cwd, testDir, type));
41 } else if(framework === 'cucumber') {
42 // #3
43 resultContent = resultContent.concat(cucumberJunit.mergeLocation(source, cwd, testDir, type));
44 }
45 }
46 } else {
47 grunt.log.warn('No' + testType + ' jUnit report has been specified');
48 }
49 });
50 // #4
51 grunt.file.write(outputFile, resultContent.concat(SUFFIX), {encoding: 'utf8'});
52 }
53
54 return {
55 merge: merge
56 };
57 };
58})();