-
Notifications
You must be signed in to change notification settings - Fork 105
/
Gruntfile.js
268 lines (247 loc) · 7.28 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
* grunt-contrib-qunit
* https://gruntjs.com/
*
* Copyright (c) 2016 "Cowboy" Ben Alman, contributors
* Licensed under the MIT license.
*/
'use strict';
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
},
// Create a local web server for testing http:// URIs.
connect: {
rootServer: {
options: {
port: 9000,
base: '.'
}
}
},
// Unit tests.
qunit: {
allTests: ['test/*{1,2}.html'],
individualTests: {
files: [{
src: 'test/*basic{1,2}.html'
}]
},
urls: {
options: {
urls: [
'http://localhost:9000/test/qunit_basic1.html'
]
}
},
urlsAndFiles: {
options: {
urls: '<%= qunit.urls.options.urls %>'
},
src: 'test/*basic{1,2}.html'
},
noglobals: {
options: {
noGlobals: true,
urls: [
'http://localhost:9000/test/qunit_noglobals.html?foo=bar'
]
}
},
modules: {
options: {
urls: [
'http://localhost:9000/test/qunit_modules.html'
]
}
},
seed: {
options: {
urls: [
'http://localhost:9000/test/qunit_seed.html'
]
}
},
circularObject: {
options: {
urls: [
'http://localhost:9000/test/qunit_circular_object.html'
]
}
}
},
shell: {
options: {
callback: function(err, stdout, stderr, cb) {
// qunit:modules, qunit:seed, qunit:circularObject
if (/test\/(qunit_modules|qunit_seed|qunit_circular_object)\.html/.test(stdout) &&
/[12] tests completed.*, with 0 failed/.test(stdout)) {
cb(err === null);
// qunit:failAssert
} else if (/test\/qunit_fail_assert\.html/.test(stdout) &&
stdout.includes(`>> example
>> Message: some message
>> Actual: false
>> Expected: true`)) {
cb(err !== null);
// qunit:failNoTests
} else if (/test\/qunit_fail_notests\.html/.test(stdout) &&
stdout.includes(`>> global failure
>> Message: No tests were run.`)) {
cb(err !== null);
// qunit:failPageTimeout
} else if (/test\/qunit_page_timeout\.html/.test(stdout) &&
/Chrome timed out/.test(stdout)) {
cb(err !== null);
// qunit:failOnError
} else if (/test\/qunit_on_error\.html/.test(stdout) &&
stdout.includes('>> Error: boom') &&
/at .*qunit_on_error.html:15/.test(stdout)) {
cb(err !== null);
// qunit:failPageError
} else if (/test\/qunit_page_error\.html/.test(stdout) &&
/ReferenceError: boom is not defined/.test(stdout) &&
/at .*qunit_page_error.html:16/.test(stdout)) {
cb(err !== null);
// qunit:failCircularObject
} else if (/test\/qunit_circular_object_fail\.html/.test(stdout) &&
/Message: fail with circular actual\.\n>> Actual: \[object Object\]\n>> Expected: \{\}/.test(stdout) &&
/Message: fail with circular expected\.\n>> Actual: \{\}\n>> Expected: \[object Object\]/.test(stdout)) {
cb(err !== null);
} else {
cb(false);
}
},
preferLocal: true
},
modules: {
command: 'grunt qunit:modules --modules="module1"'
},
seed: {
command: 'grunt qunit:seed --seed="7x9"'
},
circularObject: {
command: 'grunt qunit:circularObject'
},
failAssert: {
command: 'grunt qunit:failAssert --with-failing'
},
failNoTests: {
command: 'grunt qunit:failNoTests --with-failing'
},
failCircularObject: {
command: 'grunt qunit:failCircularObject --with-failing'
},
failOnError: {
command: 'grunt qunit:failOnError --with-failing'
},
failPageError: {
command: 'grunt qunit:failPageError --with-failing'
},
failPageTimeout: {
command: 'grunt qunit:failPageTimeout --with-failing'
}
}
});
// Only register these tasks for the shell task that expects the failure
if (grunt.option('with-failing')) {
grunt.config.set('qunit.failAssert', {
options: {
urls: [
'http://localhost:9000/test/qunit_fail_assert.html'
]
}
});
grunt.config.set('qunit.failNoTests', {
options: {
urls: [
'http://localhost:9000/test/qunit_fail_notests.html'
]
}
});
grunt.config.set('qunit.failCircularObject', {
options: {
urls: [
'http://localhost:9000/test/qunit_circular_object_fail.html'
]
}
});
grunt.config.set('qunit.failOnError', {
options: {
urls: [
'http://localhost:9000/test/qunit_on_error.html'
]
}
});
grunt.config.set('qunit.failPageError', {
options: {
urls: [
'http://localhost:9000/test/qunit_page_error.html'
]
}
});
grunt.config.set('qunit.failPageTimeout', {
options: {
urls: [
'http://localhost:9000/test/qunit_page_timeout.html'
]
}
});
}
// Build a mapping of url success counters.
var successes = {};
var currentUrl;
grunt.event.on('qunit.spawn', function(url) {
currentUrl = url;
if (!successes[currentUrl]) {
successes[currentUrl] = 0;
}
});
grunt.event.on('qunit.on.runEnd', function(runEnd) {
if (runEnd.status === 'passed') {
successes[currentUrl]++;
} else {
successes[currentUrl] -= 100;
}
});
grunt.registerTask('really-test', 'Test to see if qunit task actually worked.', function() {
var assert = require('assert');
var difflet = require('difflet')({indent: 2, comment: true});
var actual = successes;
var expected = {
'test/qunit_basic1.html': 3,
'test/qunit_basic2.html': 3,
'http://localhost:9000/test/qunit_basic1.html': 2,
'http://localhost:9000/test/qunit_noglobals.html?foo=bar&noglobals=true': 1,
'http://localhost:9000/test/qunit_modules.html': 1,
'http://localhost:9000/test/qunit_seed.html': 1,
'http://localhost:9000/test/qunit_circular_object.html': 1
};
try {
assert.deepEqual(actual, expected, 'Actual should match expected.');
} catch (err) {
grunt.log.subhead('Actual should match expected.');
console.log(difflet.compare(expected, actual));
throw new Error(err.message);
}
});
// Actually load this plugin's task(s).
grunt.loadTasks('tasks');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-internal');
grunt.loadNpmTasks('grunt-shell');
// Whenever the "test" task is run, run some basic tests.
grunt.registerTask('test', ['jshint', 'connect', 'qunit', 'shell', 'really-test']);
// By default, lint and run all tests.
grunt.registerTask('default', ['test', 'contrib-core', 'contrib-ci:skipIfExists']);
};