-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gruntfile.js
195 lines (174 loc) · 4.25 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
/*
* grunt-execute
* https://github.com/Bartvds/grunt-execute
*
* Copyright (c) 2013 Bart van der Schoor
* Licensed under the MIT license.
*/
'use strict';
/*jshint -W098 */
module.exports = function (grunt) {
// Project configuration.
var help = require('./test/helper.js');
var assert = require('assert');
function getShellFail(name) {
return {
options: {
callback: function (err, stdout, stderr, cb) {
if (!err) {
console.log('\nExpected error for test execute: '.red + 'execute:' + name + '\n');
cb(new Error('expected task to fail'));
return;
}
assert(/^Command failed: /.test(err.message), 'invalid error message: ' + err.message);
cb();
}
},
command: 'grunt execute:' + name
};
}
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/*.js',
'<%= nodeunit.tests %>'
],
options: {
jshintrc: '.jshintrc'
}
},
// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp', 'test/tmp']
},
// Configuration to be run (and then tested).
execute: {
error: {src: ['test/fixtures/error.js']},
error_module: {
options: {
module: true
},
src: ['test/fixtures/error.js']},
node_sync: {
src: ['test/fixtures/**/node.sync.*js']
},
node_async: {
src: ['test/fixtures/node.async.js']
},
node_args: {
options: {
args: ['foo', 'bar']
},
src: ['test/fixtures/**/node.args.*js']
},
node_exit: {
// will crash
src: ['test/fixtures/node.exit.one.js']
},
zero: {
src: ['test/fixtures/nonexisting.js']
},
module_sync: {
options: {
module: true
},
src: ['test/fixtures/module.sync.js']
},
module_async: {
options: {
module: true
},
src: ['test/fixtures/module.async.js']
},
harmony_on: {
options: {
nodeargs: ['--harmony']
},
src: ['test/fixtures/node.harmony.js']
},
call_sync: {
call: function (grunt, options, async) {
var ctx = help.getContext('call.sync.gruntfile.js');
grunt.file.write(ctx.dest, ctx.data);
}
},
call_async: {
call: function (grunt, options, async) {
var ctx = help.getContext('call.async.gruntfile.js');
// callback get, makes grunt-execute run async
var done = async();
var fs = require('fs');
setTimeout(function () {
fs.writeFile(ctx.dest, ctx.data, function (err) {
// call callback, passing error will fail the task
done(err);
});
}, 500);
}
},
beforeAfter: {
options: {
before: function (grunt, options, async) {
var ctx = help.getContext('before.options.sync.gruntfile.js');
grunt.file.write(ctx.dest, ctx.data);
},
after: function (grunt, options, async) {
var ctx = help.getContext('after.options.sync.gruntfile.js');
grunt.file.write(ctx.dest, ctx.data);
}
},
before: function (grunt, options, async) {
var ctx = help.getContext('before.sync.gruntfile.js');
grunt.file.write(ctx.dest, ctx.data);
},
after: function (grunt, options, async) {
var ctx = help.getContext('after.sync.gruntfile.js');
grunt.file.write(ctx.dest, ctx.data);
},
src: ['test/fixtures/node.async.js']
}
},
shell: {
options: {
stdout: false,
stderr: false,
execOptions: {
cwd: '.'
}
},
node_exit: getShellFail('node_exit:'),
error: getShellFail('error'),
error_module: getShellFail('error_module')
},
// Unit tests.
nodeunit: {
tests: ['test/*_test.js']
}
});
grunt.loadTasks('tasks');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('pass', [
'execute:node_args',
'execute:node_async',
'execute:node_sync',
'execute:harmony_on',
'execute:zero',
'execute:module_sync',
'execute:module_async',
'execute:call_sync',
'execute:call_async',
'execute:beforeAfter'
]);
grunt.registerTask('fail', [
'shell:node_exit',
'shell:error',
'shell:error_module'
]);
grunt.registerTask('test', ['jshint', 'clean', 'pass', 'fail', 'nodeunit']);
grunt.registerTask('default', ['test']);
grunt.registerTask('dev', ['error']);
};