1 |
|
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 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function merge(locations, outputFile, type) {
|
23 | var testType = (type === 'itUnit' ? ' integration' : ''),
|
24 | resultContent = PREFIX;
|
25 |
|
26 |
|
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 |
|
38 | if(framework === 'jasmine' || framework === 'jasmine2') {
|
39 |
|
40 | resultContent = resultContent.concat(jasmineJunit.mergeLocation(source, cwd, testDir, type));
|
41 | } else if(framework === 'cucumber') {
|
42 |
|
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 |
|
51 | grunt.file.write(outputFile, resultContent.concat(SUFFIX), {encoding: 'utf8'});
|
52 | }
|
53 |
|
54 | return {
|
55 | merge: merge
|
56 | };
|
57 | };
|
58 | })();
|