-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
100 lines (83 loc) · 2.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var builder = require( 'xmlbuilder' ),
path = require( 'path' ),
fs = require( 'fs' ),
xml;
module.exports = {
name: 'bender-reporter-junit',
attach: function() {
var bender = this,
packageName = bender.conf.jUnitReporter && bender.conf.jUnitReporter.package || '';
xml = builder.create( 'testsuites' );
bender.on( 'client:afterRegister', function( client ) {
var browser = client.browser + client.version,
suite = xml.ele( 'testsuite', {
name: browser,
timestamp: ( new Date() ).toISOString().substr( 0, 19 ),
package: packageName,
id: 0
} ),
props = suite.ele( 'properties' );
props.ele( 'property', {
name: 'userAgent',
value: client.ua
} );
props.ele( 'property', {
name: 'address',
value: client.addr
} );
} );
bender.on( 'client:complete', function( data ) {
var className = ( packageName ? packageName + '.' : '' ) +
data.client.browser + data.client.version + '.' + data.id.replace( /\.|\?|=/g, '_' ),
suite = xml.ele( 'testsuite', {
name: className,
timestamp: ( new Date() ).toISOString().substr( 0, 19 ),
package: packageName
} ),
passed = 0,
failed = 0,
ignored = 0,
duration = 0,
total = 0,
errors = 0;
Object.keys( data.results ).forEach( function( name ) {
var result = data.results[ name ],
spec = suite.ele( 'testcase', {
name: result.fullName,
time: ( result.duration || 0 ) / 1000,
className: className
} );
total++;
if ( result.success ) {
if ( result.ignored ) {
ignored++;
spec.ele( 'skipped' );
} else {
passed++;
}
} else {
failed++;
spec.ele( 'failure', {}, result.error );
}
} );
suite.att( 'tests', total );
suite.att( 'errors', errors > 0 ? 1 : 0 );
suite.att( 'failures', failed );
suite.att( 'time', ( duration || 0 ) / 1000 );
} );
bender.reporters.add( 'junit', this );
},
detach: function( done ) {
var bender = this,
filePath = bender.conf.jUnitReporter && bender.conf.jUnitReporter.outputFile || path.join( process.cwd(),
'bender-result.xml' );
bender.utils.mkdirp( path.dirname( filePath ), function( err ) {
if ( err ) {
return done( err );
}
fs.writeFile( filePath, xml.end( {
pretty: true
} ), done );
} );
}
};