-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathGruntfile.js
195 lines (182 loc) · 5.32 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*global module:false*/
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
src: [
'Gruntfile.js',
'lib/**/*.js',
'bin/fakeminder',
'test/**/*.js',
'sample_target/app.js',
'sample_target/routes/*.js',
'sample_target/test/**/*.js'
],
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
node: true,
globals: {
require: true,
define: true,
requirejs: true,
describe: true,
expect: true,
it: true,
beforeEach: true,
afterEach: true
}
}
},
simplemocha: {
unit_test: {
src: ['test/**/*.js'],
options: {
globals: ['expect'],
timeout: 2000,
ignoreLeaks: false,
reporter: 'dot'
}
},
integration_test: {
src: ['sample_target/test/**/*.js'],
options: {
globals: ['expect', 'require'],
timeout: 2000,
ignoreLeaks: false,
reporter: 'spec'
}
}
},
watch: {
files: ['<%= jshint.src %>'],
tasks: ['jshint', 'simplemocha']
},
casperjs: {
options: {},
files: {src: ['sample_target/integration_test/**/*.js']}
},
express: {
options: {
output: "Express server listening on port .+"
},
sample_target: {
options: {
script: 'sample_target/app.js'
}
}
},
gitpush: {
github: {
options: {
remote: 'github',
branch: 'master'
}
}
},
coverage: {
options: {
thresholds: {
statements: 90,
branches: 90,
lines: 90,
functions: 90
},
dir: 'coverage'
}
},
clean: ['coverage'],
open: {
cover: {
path: 'coverage/lcov-report/index.html',
app: 'Google Chrome'
}
}
});
// Load JSHint task
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.loadNpmTasks('grunt-casperjs');
grunt.loadNpmTasks('grunt-express-server');
grunt.loadNpmTasks('grunt-clear');
grunt.loadNpmTasks('grunt-git');
grunt.loadNpmTasks('grunt-istanbul-coverage');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-open');
// Default task.
grunt.registerTask('default', ['clear', 'jshint', 'simplemocha:unit_test']);
grunt.registerTask('test', ['clear', 'simplemocha:unit_test']);
grunt.registerTask('int-test', 'Execute integration tests against the sample app through the proxy', function() {
// Make sure failed automation tests don't break the entire task
// so we can shutdown both the FakeMinder and Express apps.
grunt.option('force', true);
grunt.task.run('clear');
grunt.task.run('fakeminder-start');
grunt.task.run('express:sample_target');
grunt.task.run('simplemocha:integration_test');
grunt.task.run('express:sample_target:stop');
grunt.task.run('fakeminder-stop');
});
grunt.registerTask('ui-test', 'Execute Casperjs integration tests against the sample app through the proxy', function() {
// Make sure failed automation tests don't break the entire task
// so we can shutdown both the FakeMinder and Express apps.
grunt.option('force', true);
grunt.task.run('clear');
grunt.task.run('fakeminder-start');
grunt.task.run('express:sample_target');
grunt.task.run('casperjs');
grunt.task.run('express:sample_target:stop');
grunt.task.run('fakeminder-stop');
});
grunt.registerTask('cover', ['clear', 'clean', 'istanbul', 'open:cover']);
grunt.registerTask('cover-check', ['clear', 'clean', 'istanbul', 'coverage']);
var server;
var regex = new RegExp(/Listening on port/);
// Run the FakeMinder server
grunt.registerTask('fakeminder-start', 'Start an instance of FakeMinder using the default config.', function() {
var done = this.async();
server = grunt.util.spawn({
cmd: './bin/fakeminder',
args: ['start', 'config.json']
}, done);
server.stderr.on('data', function(data) {
var message = '' + data;
if (message.match(regex)) {
done();
}
});
});
// End the FakeMinder server
grunt.registerTask('fakeminder-stop', 'Stop the running instance of FakeMinder.', function() {
if (server && server.kill) {
server.kill('SIGTERM');
server = null;
}
});
// Commit changes to Github.
grunt.registerTask('commit', 'Commit changes to Github', function(env) {
grunt.task.run('clear');
grunt.task.run('default');
grunt.task.run('int-test');
grunt.task.run('gitpush:github');
grunt.log.ok('Changes successfully committed to Github.');
});
// Run mocha tests while also generating code coverage using istanbul
grunt.registerTask('istanbul', 'Generate coverage using istanbul from mocha tests', function() {
var done = this.async();
server = grunt.util.spawn({
cmd: './node_modules/.bin/istanbul',
args: ['cover', '_mocha', '--']
}, done);
server.stdout.pipe(process.stdout);
server.stderr.pipe(process.stderr);
});
};