This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Gruntfile.js
211 lines (183 loc) · 5.17 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
/**
* Example Gruntfile for Mocha setup
*/
'use strict';
module.exports = function(grunt) {
var port = 8981;
grunt.initConfig({
jshint: {
all: [
'Gruntfile.js',
'tasks/**/*.js', ],
options: {
jshintrc: '.jshintrc'
}
},
watch: {
// If you want to watch files and run tests automatically on change
test: {
files: [
'example/js/**/*.js',
'example/test/spec/**/*.js',
'phantomjs/*',
'tasks/*',
'Gruntfile.js'
],
tasks: 'test'
}
},
mocha: {
// runs all html files (except test2.html) in the test dir
// In this example, there's only one, but you can add as many as
// you want. You can split them up into different groups here
// ex: admin: [ 'test/admin.html' ]
all: ['example/test/**/!(test2|testBail|testPage).html'],
// Runs 'test/test2.html' with specified mocha options.
// This variant auto-includes 'bridge.js' so you do not have
// to include it in your HTML spec file. Instead, you must add an
// environment check before you run `mocha.run` in your HTML.
test2: {
// Test files
src: ['example/test/test2.html'],
options: {
// mocha options
mocha: {
ignoreLeaks: false,
grep: 'food'
},
reporter: 'Spec',
timeout: 10000
}
},
// Runs the same as test2 but with URL's
testUrls: {
options: {
// mocha options
mocha: {
ignoreLeaks: false,
grep: 'food'
},
reporter: 'Nyan',
// URLs passed through as options
urls: ['http://localhost:' + port + '/example/test/test2.html'],
}
},
// Test using a custom reporter
testReporter: {
src: ['example/test/test.html', 'example/test/test2.html'],
options: {
mocha: {
ignoreLeaks: false,
grep: 'food'
},
reporter: './example/test/reporter/simple',
}
},
// Test log option
testLog: {
src: ['example/test/test.html'],
options: {
mocha: {
ignoreLeaks: false,
grep: 'food'
},
log: true
}
},
testDest1: {
// Test files
src: ['example/test/test2.html'],
dest: 'example/test/results/spec.out',
options: {
reporter: 'Spec',
}
},
// Same as above, but with URLS + Xunit
testDest2: {
options: {
reporter: 'XUnit',
// URLs passed through as options
urls: ['http://localhost:' + (port + 1) + '/example/test/test2.html'],
},
dest: 'example/test/results/xunit.out'
},
// Test a failing test with bail: true
testBail: {
src: ['example/test/testBail.html'],
// Bail option
options: {
bail: true
}
},
// This test should never run
neverTest: {
src: ['example/test/test.html'],
},
// Test page options
testPage: {
src: ['example/test/testPage.html'],
options: {
page: {
settings: {
userAgent: 'grunt-mocha-agent'
}
}
}
}
},
connect: {
testUrls: {
options: {
port: port,
base: '.'
}
},
testDest: {
options: {
port: port + 1,
base: '.'
}
}
}
});
grunt.registerTask('verifyDestResults', function () {
var expected = ['spec', 'xunit'];
expected.forEach(function (reporter) {
var output = 'example/test/results/' + reporter + '.out';
// simply check if the file is non-empty since verifying if the output is
// correct based on the spec is kind of hard due to changing test running
// times and different ways to report this time in reporters.
if (!grunt.file.read(output, 'utf8'))
grunt.fatal('Empty reporter output: ' + reporter);
// Clean-up
grunt.file.delete(output);
grunt.log.ok('Reporter output non-empty for %s', reporter);
});
});
grunt.loadTasks('tasks');
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.task.registerTask('testUrls', ['connect:testUrls', 'mocha:testUrls']);
grunt.task.registerTask('testLog', ['mocha:testLog']);
grunt.task.registerTask('testReporter', ['mocha:testReporter']);
grunt.task.registerTask('testDest', [
'mocha:testDest1',
'connect:testDest',
'mocha:testDest2',
'verifyDestResults'
]);
grunt.task.registerTask('testPage', ['mocha:testPage']);
// WARNING: Running this test will cause grunt to fail after mocha:testBail
grunt.task.registerTask('testBail', ['mocha:testBail', 'mocha:neverTest']);
grunt.task.registerTask('test', [
'mocha:all',
'testUrls',
'testLog',
'testReporter',
'testDest',
'testPage',
]);
// By default, lint and run all tests.
grunt.task.registerTask('default', ['jshint', 'test']);
};