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 20
/
Gruntfile.js
124 lines (104 loc) · 3.96 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
121
122
123
124
/*global module:false*/
module.exports = function (grunt) {
// Project configuration.
// 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"];
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
patio: {
paths: {
root: './',
lib: './lib',
test: './test'
}
},
jshint: {
src: [
"./index.js",
"<%= patio.paths.lib %>/**/*.js",
"<%= patio.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("spawn-test", "spawn tests", function (db) {
var done = this.async();
var env = process.env;
env.PATIO_DB = db;
grunt.util.spawn({cmd: "grunt", args: ["it"], opts: {stdio: 'inherit', env: env}}, function (err) {
if (err) {
done(false);
} else {
done();
}
});
});
grunt.registerTask("spawn-test-coverage", "spawn tests with coverage", function (db) {
var done = this.async();
var env = process.env;
env.PATIO_DB = db;
grunt.util.spawn({cmd: "istanbul", args: DEFAULT_COVERAGE_ARGS, opts: {stdio: 'inherit', env: env}}, function (err) {
if (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();
});
});
// Default task.
grunt.registerTask('default', ['jshint', "test", "test-coverage", "docs"]);
grunt.registerTask('test', ['jshint', 'test-mysql', 'test-pg']);
grunt.registerTask('test-mysql', ['jshint', "spawn-test:mysql"]);
grunt.registerTask('test-pg', ['jshint', "spawn-test:pg"]);
grunt.registerTask('test-coverage', ['exec:removeCoverage', 'test-mysql-coverage', 'test-pg-coverage', 'process-coverage', 'exec:sendToCoveralls', 'exec:removeCoverage']);
grunt.registerTask('test-mysql-coverage', ["spawn-test-coverage:mysql"]);
grunt.registerTask('test-pg-coverage', ["spawn-test-coverage:pg"]);
grunt.registerTask("docs", ["exec:removeDocs", "exec:createDocs"]);
grunt.loadNpmTasks('grunt-it');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-coveralls');
};