-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
159 lines (133 loc) · 4.53 KB
/
Gruntfile.js
File metadata and controls
159 lines (133 loc) · 4.53 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
module.exports = function (grunt) {
// project's configuration
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
src: 'src',
tests: 'tests',
build: 'build',
coverage: '<%= build %>/coverage',
coverage_tmp: '<%= coverage %>/tmp',
clean: {
build: {
src: ['<%= build %>']
},
coverage: {
src: ['<%= coverage %>']
},
coverage_tmp: {
src: ['<%= coverage_tmp %>']
}
},
// JSHint's configuration (see http://jshint.com/docs/options/ for the list of available options)
jshint: {
productionCode: {
options: {jshintrc: '.jshintrc'},
src: ['<%= src %>/**/*.js']
},
testCode: {
options: {jshintrc: '.jshintrc'},
src: ['<%= tests %>/**/*.js']
}
},
runTests: {
unit: {
delegate: 'jasmine_nodejs:unit'
},
unitWithCoverage: {
delegate: 'jasmine_nodejs:unitWithCoverage'
}
},
jasmine_nodejs: {
unit: {
specs: ['<%= tests %>/**']
},
unitWithCoverage: {
specs: ['<%= coverage_tmp %>/<%= tests %>/**']
}
},
instrument: {
files: ['<%= src %>/**/*.js'],
options: {
lazy: true,
basePath: '<%= coverage_tmp %>'
}
},
storeCoverage: {
options: {
dir: '<%= coverage_tmp %>'
}
},
makeReport: {
src: '<%= coverage_tmp %>/coverage.json',
options: {
type: 'lcov',
dir: '<%= coverage %>',
print: 'detail'
}
},
copy: {
toCoverageTmp: {
files: [
{
expand: true,
src: '<%= tests %>/**',
dest: '<%= coverage_tmp %>'
}
]
}
},
coveralls: {
istanbul: {
src: '<%= coverage %>/lcov.info'
}
}
});
// plugin for deleting files (see https://github.com/gruntjs/grunt-contrib-clean)
grunt.loadNpmTasks('grunt-contrib-clean');
// plugin for validating files (see https://github.com/gruntjs/grunt-contrib-jshint)
grunt.loadNpmTasks('grunt-contrib-jshint');
// plugin for testing files (see https://github.com/onury/grunt-jasmine-nodejs)
grunt.loadNpmTasks('grunt-jasmine-nodejs');
// plugin for computing test coverage (see https://github.com/taichi/grunt-istanbul)
grunt.loadNpmTasks('grunt-istanbul');
// plugin for reporting test coverage to coveralls.io (see https://github.com/pimterry/grunt-coveralls)
grunt.loadNpmTasks('grunt-coveralls');
// plugin for copying files (see https://github.com/gruntjs/grunt-contrib-copy)
grunt.loadNpmTasks('grunt-contrib-copy');
// If a file is not required, then it won't be included in the coverage report. Actually, that report does not show
// the coverage of the code but the coverage of the specs, which can be misleading. The workaround is to require the
// instrumented files before running the tests.
grunt.task.registerTask('requireInstrumentedFiles', function () {
var _ = require('lodash');
var glob = require('glob');
_.forEach(glob.sync(grunt.config.get('coverage_tmp') + '/**/!(di.js|*.di.js|*.spec.js).js'), function (file) {
require('./' + file);
});
});
grunt.task.registerMultiTask('runTests', function runTests() {
var data = this.data;
// improve the logging of the errors
require('pretty-error').start();
return grunt.task.run(data.delegate);
});
grunt.task.registerTask('default', ['build']);
grunt.task.registerTask('build', [
'clean:build',
'jshint',
'build-coverage']);
grunt.task.registerTask('ci', [
'build',
'coveralls']);
grunt.task.registerTask('build-coverage', [
'clean:coverage',
'instrument',
'requireInstrumentedFiles',
'copy:toCoverageTmp',
'runTests:unitWithCoverage',
'storeCoverage',
'makeReport',
'clean:coverage_tmp'
]);
grunt.task.registerTask('test', ['runTests:unit']);
};