This repository has been archived by the owner on Dec 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathGruntfile.js
120 lines (100 loc) · 3.63 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"use strict";
/*global module:false*/
module.exports = function (grunt) {
// Automatic module definition loading. Significantly speeds up build cycles
require('jit-grunt')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Project configuration.
var DEFAULT_COVERAGE_ARGS = ["cover", "-x", "Gruntfile.js", "--report", "none", "--print", "none", "--include-pid", "grunt", "--", "it"],
path = require("path");
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
comb: {
paths: {
root: './',
lib: './lib',
test: './test'
}
},
jshint: {
src: [
"./index.js",
"<%= comb.paths.lib %>/**/*.js",
"<%= comb.paths.test %>/**/*.js",
"Gruntfile.js"
],
options: {
jshintrc: '.jshintrc'
}
},
exec: {
sendToCoveralls: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
removeCoverage: "rm -rf ./coverage",
removeDocs: "rm -rf docs/*",
createDocs: 'coddoc -f multi-html -d ./lib --dir ./docs'
},
it: {
all: {
src: 'test/**/*.test.js',
options: {
timeout: 3000, // not fully supported yet
reporter: 'tap'
}
}
}
});
grunt.registerTask("benchmarks", "runs benchmarks", function () {
var done = this.async();
require("./benchmark/benchmark")()
.then(function () {
done(true);
})
.catch(function (err) {
console.log(err.stack || err);
done(false);
});
});
grunt.registerTask("spawn-test-coverage", "spawn tests with coverage", function () {
var done = this.async();
var env = process.env;
grunt.util.spawn({
cmd: "./node_modules/istanbul/lib/cli.js",
args: DEFAULT_COVERAGE_ARGS,
opts: {stdio: 'inherit', env: env}
}, function (err) {
if (err) {
console.log(err);
done(false);
} else {
done();
}
});
});
grunt.registerTask("process-coverage", "process coverage obects", function () {
var files = grunt.file.expand("./coverage/coverage*.json"),
istanbul = require('istanbul'),
collector = new istanbul.Collector(),
reporter = new istanbul.Reporter(),
sync = false,
done = this.async();
files.forEach(function (file) {
collector.add(grunt.file.readJSON(file));
});
reporter.add('text');
reporter.addAll(['lcovonly']);
reporter.write(collector, sync, function (err) {
if (err) {
console.error(err.stack);
return done(false);
}
console.log('All reports generated');
done();
});
});
grunt.registerTask('default', ['jshint', "test", "test-coverage", "docs"]);
grunt.registerTask('test', ['it']);
grunt.registerTask('coveralls', ['exec:removeCoverage', 'spawn-test-coverage', 'process-coverage', 'exec:sendToCoveralls', 'exec:removeCoverage']);
grunt.registerTask('test-coverage', ['exec:removeCoverage', 'spawn-test-coverage', 'process-coverage', 'exec:removeCoverage']);
grunt.registerTask("docs", ["exec:removeDocs", "exec:createDocs"]);
};