@@ -6,10 +6,10 @@ module.exports = function(grunt) {
6
6
// Metadata.
7
7
pkg : grunt . file . readJSON ( 'package.json' ) ,
8
8
banner : '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
9
- '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
10
- '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
11
- '* Copyright (c) <%= grunt.template.today("yyyy") %> Nicole Sullivan and Nicholas C. Zakas;\n' +
12
- '* Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> <%= _.pluck(pkg.licenses, "url").join(", ") %> */\n' ,
9
+ '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
10
+ '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
11
+ '* Copyright (c) <%= grunt.template.today("yyyy") %> Nicole Sullivan and Nicholas C. Zakas;\n' +
12
+ '* Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> <%= _.pluck(pkg.licenses, "url").join(", ") %> */\n' ,
13
13
//Parser lib copy for verions that can't user requirejs
14
14
parserlib : 'node_modules/parserlib/lib/node-parserlib.js' ,
15
15
//Core CSSLint files used by most versions
@@ -91,20 +91,6 @@ module.exports = function(grunt) {
91
91
'src/cli/{common, whs}.js'
92
92
] ,
93
93
dest : 'build/<%= pkg.name %>-whs.js'
94
- } , //Build tests
95
- tests : {
96
- src : [
97
- '!tests/all-rules.js' ,
98
- 'tests/**/*.js'
99
- ] ,
100
- dest : 'build/<%= pkg.name %>-tests.js'
101
- } ,
102
- tests_node : {
103
- src : [
104
- '<%= concat.core.dest %>' ,
105
- 'tests/**/*.js'
106
- ] ,
107
- dest : 'build/<%= pkg.name %>-node-tests.js'
108
94
}
109
95
} ,
110
96
uglify : {
@@ -163,6 +149,13 @@ module.exports = function(grunt) {
163
149
files : '<%= jshint.tests.src %>' ,
164
150
tasks : [ 'jshint:tests' ]
165
151
}
152
+ } ,
153
+ yuitest : {
154
+ tests : {
155
+ src : [
156
+ 'tests/**/*.js'
157
+ ]
158
+ }
166
159
}
167
160
} ) ;
168
161
@@ -173,6 +166,63 @@ module.exports = function(grunt) {
173
166
grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
174
167
175
168
// Default task.
176
- grunt . registerTask ( 'default' , [ 'jshint' , 'concat' , 'uglify' ] ) ;
169
+ grunt . registerTask ( 'default' , [ 'test' ] ) ;
170
+
171
+ grunt . registerTask ( 'test' , [ 'jshint' , 'concat' , 'yuitest' ] ) ;
172
+
173
+ //Run the YUITest suite
174
+ grunt . registerMultiTask ( 'yuitest' , 'Run the YUITests for the project' , function ( ) {
175
+ /*jshint evil:true, node: true */
176
+
177
+ var start = Date . now ( ) ;
178
+ var YUITest = require ( "yuitest" ) ;
179
+ var CSSLint = require ( './build/csslint-node' ) . CSSLint ;
180
+ var files = this . filesSrc ;
181
+ var TestRunner = YUITest . TestRunner ;
182
+ var done = this . async ( ) ;
183
+
184
+ //Eval each file so the tests are brought into this scope were CSSLint and YUITest are loaded already
185
+ files . forEach ( function ( filepath ) {
186
+ eval ( grunt . file . read ( filepath ) ) ;
187
+ } ) ;
188
+
189
+ //Generic test event handler for individual test
190
+ function handleTestResult ( data ) {
191
+ switch ( data . type ) {
192
+ case TestRunner . TEST_FAIL_EVENT :
193
+ grunt . verbose . fail ( "Test named '" + data . testName + "' failed with message: '" + data . error . message + "'." ) . or . write ( "." . red ) ;
194
+ break ;
195
+ case TestRunner . TEST_PASS_EVENT :
196
+ grunt . verbose . ok ( "Test named '" + data . testName + "' passed." ) . or . write ( "." . green ) ;
197
+ break ;
198
+ case TestRunner . TEST_IGNORE_EVENT :
199
+ grunt . verbose . warn ( "Test named '" + data . testName + "' was ignored." ) . or . write ( "." . yellow ) ;
200
+ break ;
201
+ }
202
+ }
177
203
204
+ //Event to execute after all tests suites are finished
205
+ function reportResults ( allsuites ) {
206
+ var end = Date . now ( ) ;
207
+ var elapsed = end - start ;
208
+ grunt . log . writeln ( ) . write ( "Finished in " + ( elapsed / 1000 ) + " seconds" ) . writeln ( ) ;
209
+
210
+ if ( allsuites . results . failed > 0 ) {
211
+ grunt . fail . warn ( allsuites . results . failed + "/" + allsuites . results . total + "tests failed" ) ;
212
+ } else {
213
+ grunt . log . ok ( allsuites . results . passed + "/" + allsuites . results . total + "tests passed" ) ;
214
+ if ( allsuites . results . ignored > 0 ) {
215
+ grunt . log . warn ( "Ignored: " + allsuites . results . ignored ) ;
216
+ }
217
+ }
218
+ //Tell grunt we're done the async testing
219
+ done ( ) ;
220
+ }
221
+ //Add event listeners
222
+ TestRunner . subscribe ( TestRunner . TEST_FAIL_EVENT , handleTestResult ) ;
223
+ TestRunner . subscribe ( TestRunner . TEST_IGNORE_EVENT , handleTestResult ) ;
224
+ TestRunner . subscribe ( TestRunner . TEST_PASS_EVENT , handleTestResult ) ;
225
+ TestRunner . subscribe ( TestRunner . COMPLETE_EVENT , reportResults ) ;
226
+ TestRunner . run ( ) ;
227
+ } ) ;
178
228
} ;
0 commit comments