grunt.initConfig({// jasmine task is to run specs using phantom, before running it, you must// make sure you have installed phantom following instruction on// https://github.com/cowboy/grunt/blob/master/docs/faq.md#why-does-grunt-complain-that-phantomjs-isnt-installedjasmine:{all:{src:['http://localhost:8000/tests/SpecRunner.html'],timeout:300000//in milliseconds}}});
启动http服务:
123
$ ./node_modules/bbb/bin/bbb server
Running "server" task
Listening on http://127.0.0.1:8000
然后在另一个终端运行jasmine任务:
1234567
$ ./node_modules/bbb/bin/bbb jasmine
Running "jasmine:all"(jasmine) task
Running specs for SpecRunner.html
.............
>> 31 assertions passed in 13 specs (1451ms)Done, without errors.
/* * grunt * https://github.com/cowboy/grunt * * Copyright (c) 2012 "Cowboy" Ben Alman * Licensed under the MIT license. * http://benalman.com/about/license/ */module.exports=function(grunt){// Nodejs libs.varpath=require('path');// External libs.varconnect=require('connect');// ==========================================================================// TASKS// ==========================================================================grunt.registerTask('staticserver','Start a static web server.',function(){// Get values from config, or use defaults.varport=grunt.config('server.port')||8000;varbase=path.resolve(grunt.config('server.base')||'.');varmiddleware=[// Serve static files.connect.static(base),// Make empty directories browsable. (overkill?)connect.directory(base)];// If --debug was specified, enable logging.if(grunt.option('debug')){connect.logger.format('grunt',('[D] server :method :url :status '+':res[content-length] - :response-time ms').magenta);middleware.unshift(connect.logger('grunt'));}// Start server.grunt.log.writeln('Starting static web server on port '+port+'.');connect.apply(null,middleware).listen(port);});};
// Register test task, which will compile app and run the server and then do test.// Here we use 'staticserver' task (pure grunt static server) for testing.grunt.registerTask('test','default staticserver jasmine');