forked from schorfES/node-junitwriter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriter.js
More file actions
54 lines (40 loc) · 977 Bytes
/
Writer.js
File metadata and controls
54 lines (40 loc) · 977 Bytes
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
var
mkdirp = require('mkdirp'),
fs = require('fs'),
path = require('path'),
merge = require('merge'),
builder = require('xmlbuilder'),
Testsuites = require('./Testsuites')
;
// Format documentation @ http://llg.cubic.org/docs/junit/
function Writer() {
this._root = new Testsuites();
}
merge(Writer.prototype, {
getTestsuites: function() {
return this._root;
},
addTestsuite: function(name) {
return this._root.addTestsuite(name);
},
toString: function() {
return '<?xml version="1.0" encoding="UTF-8"?>\n' + this._root.toString();
},
save: function(destination, callback) {
var self = this;
mkdirp(path.dirname(destination), function (error) {
if (error) {
if (typeof callback === 'function') {
callback(error, self);
}
return;
}
fs.writeFile(destination, self.toString(), function(error) {
if (typeof callback === 'function') {
callback(error, self);
}
});
});
}
});
module.exports = Writer;