-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Gruntfile.js
99 lines (80 loc) · 2.83 KB
/
Gruntfile.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
'use strict';
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-coveralls');
function Runner() {
var done = this.async(),
force = this.options().force || false;
if (this.filesSrc.length === 0) {
grunt.log.error('No src files could be found for grunt-coveralls');
done(false);
}
var successful = true;
var remainingSubmissions = this.filesSrc.length;
function receiveResult(result) {
successful = successful && result;
remainingSubmissions--;
if (remainingSubmissions === 0) {
if (successful) {
grunt.log.ok("Successfully submitted coverage results to coveralls");
done(true);
} else if (force) {
grunt.log.warn("WARNING: Failed to submit coverage results to coveralls");
done(true);
} else {
grunt.log.error("Failed to submit coverage results to coveralls");
done(false);
}
}
}
for (var ii = 0; ii < this.filesSrc.length; ii++) {
submitToCoveralls(this.filesSrc[ii], receiveResult);
}
}
function submitToCoveralls(fileName, callback) {
grunt.verbose.writeln("Submitting file to coveralls.io: " + fileName);
var coveralls = require('coveralls');
// Override coveralls option processing until it handles use as a library better (TODO)
coveralls.getOptions = coveralls.getBaseOptions;
var fs = require('fs');
fs.readFile(fileName, 'utf8', function(err, fileContent) {
if (err) {
grunt.log.error("Failed to read file '" + fileName + "', with error: " + err);
return callback(false);
}
coveralls.handleInput(fileContent, function(err) {
if (err) {
grunt.log.error("Failed to submit '" + fileName + "' to coveralls: " + err);
return callback(false);
}
grunt.verbose.ok("Successfully submitted " + fileName + " to coveralls");
callback(true);
});
});
}
grunt.registerMultiTask('coveralls', 'Grunt task to load coverage results and submit them to Coveralls.io', Runner);
grunt.registerTask('test', [ 'qunit' ]);
grunt.event.on('qunit.report', function(data) {
grunt.file.write('.coverage-results/core.lcov', data);
});
grunt.initConfig({
qunit : {
all : {
options : {
urls : [ 'http://localhost:8080/tests?coverage=true&lcovReport' ],
noGlobals : true,
stack : true,
timeout: 990000
}
}
},
coveralls : {
options : {
force : true
},
all : {
src : '.coverage-results/core.lcov',
}
}
});
}