@@ -6,10 +6,10 @@ module.exports = function(grunt) {
66 // Metadata.
77 pkg : grunt . file . readJSON ( 'package.json' ) ,
88 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' ,
1313 //Parser lib copy for verions that can't user requirejs
1414 parserlib : 'node_modules/parserlib/lib/node-parserlib.js' ,
1515 //Core CSSLint files used by most versions
@@ -91,20 +91,6 @@ module.exports = function(grunt) {
9191 'src/cli/{common, whs}.js'
9292 ] ,
9393 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'
10894 }
10995 } ,
11096 uglify : {
@@ -163,6 +149,13 @@ module.exports = function(grunt) {
163149 files : '<%= jshint.tests.src %>' ,
164150 tasks : [ 'jshint:tests' ]
165151 }
152+ } ,
153+ yuitest : {
154+ tests : {
155+ src : [
156+ 'tests/**/*.js'
157+ ]
158+ }
166159 }
167160 } ) ;
168161
@@ -173,6 +166,63 @@ module.exports = function(grunt) {
173166 grunt . loadNpmTasks ( 'grunt-contrib-watch' ) ;
174167
175168 // 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+ }
177203
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+ } ) ;
178228} ;
0 commit comments