/
gruntfile.js
136 lines (121 loc) · 3.9 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
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
module.exports = function (grunt) {
// Unified Watch Object
var watchFiles = {
serverJS: ['lib/*.js', 'lib/**/*.js', 'index.js'],
serverTests: ['test/*_spec.js'],
ignores: ['node_modules/**', '.git/**', '.idea/', '.cache/', '.tmp/']
};
var allFiles = watchFiles.serverTests
.concat(watchFiles.serverJS);
// Project Configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
/*
* JSLint
* ===========================================
*/
// region JSLint, jscs, jsbeautifier, nodemon, watch definition
jshint: {
options: {
reporter: require('jshint-stylish')
},
all: {
src: allFiles,
options: {
jshintrc: true
}
},
test: {
src: watchFiles.serverTests,
options: {
jshintrc: true
}
}
},
jsbeautifier: {
options: {
js: {
braceStyle: 'collapse',
breakChainedMethods: false,
e4x: false,
evalCode: false,
indentChar: ' ',
indentLevel: 0,
indentSize: 4,
indentWithTabs: false,
jslintHappy: true,
keepArrayIndentation: false,
keepFunctionIndentation: false,
maxPreserveNewlines: 10,
preserveNewlines: true,
spaceBeforeConditional: true,
spaceInParen: false,
unescapeStrings: false,
wrapLineLength: 0
}
},
all: {
src: allFiles
}
},
jscs: {
options: {
config: '.jscsrc'
},
all: {
src: allFiles
}
},
watch: {
test: {
files: allFiles,
tasks: ['newer:jshint:test', 'mocha_istanbul:test']
}
},
// endregion
mocha_istanbul: {
test: {
src: ['test'], // a folder works nicely
options: {
reporter: 'spec',
coverage: false
//root: './lib'
}
},
coverage: {
src: ['test'], // a folder works nicely
options: {
reporter: 'mocha-teamcity-reporter',
coverage: false,
check: {
lines: 25,
statements: 25,
branches: 25,
functions: 25
},
//root: './lib', // define where the cover task should consider the root of libraries that are covered by tests
reportFormats: ['teamcity', 'html']
}
}
}
});
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Making grunt default to force in order not to break the project.
grunt.option('force', true);
grunt.event.on('coverage', function(lcov, done){
require('coveralls').handleInput(lcov, function(err){
if (err) {
return done(err);
}
done();
});
});
// Default task(s).
grunt.registerTask('default', ['mocha_istanbul:test', 'watch:test']);
// Lint task(s).
grunt.registerTask('lint', ['jshint', 'jscs', 'jsbeautifier']);
// We don't need setup a test server here because we use injection to the server instance directly
grunt.registerTask('coverage', ['mocha_istanbul:coverage']);
};