diff --git a/Gruntfile.js b/Gruntfile.js index f51c59d..883e953 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -52,6 +52,9 @@ module.exports = function(grunt) { custom_cmd: { src: 'test/custom_cmd_test.js' }, + custom_harmony: { + src: 'test/custom_harmony.js' + }, custom_args: { src: 'test/custom_args_test.js' }, @@ -90,6 +93,12 @@ module.exports = function(grunt) { script: './test/server_malformed.js' } }, + custom_harmony: { + options: { + harmony: true, + output: "Express server listening on port .+" + } + }, custom_args: { options: { args: [1, 2], @@ -153,37 +162,40 @@ module.exports = function(grunt) { grunt.registerTask('test', [ 'clean', 'nodeunit:defaults', - 'express:defaults', + 'express:defaults', 'express:defaults:stop', 'express:malformed', - 'express:custom_cmd', - 'nodeunit:custom_cmd', + 'express:custom_cmd', + 'nodeunit:custom_cmd', 'express:custom_cmd:stop', - 'express:custom_args', - 'nodeunit:custom_args', + 'express:custom_args', + 'nodeunit:custom_args', 'express:custom_args:stop', - 'express:custom_port', - 'nodeunit:custom_port', + 'express:custom_harmony', + 'nodeunit:custom_harmony', + 'express:custom_harmony:stop', + 'express:custom_port', + 'nodeunit:custom_port', 'express:custom_port:stop', - 'express:custom_node_env', - 'nodeunit:custom_node_env', + 'express:custom_node_env', + 'nodeunit:custom_node_env', 'express:custom_node_env:stop', - 'express:custom_delay', - 'nodeunit:custom_delay', + 'express:custom_delay', + 'nodeunit:custom_delay', 'express:custom_delay:stop', - 'express:custom_output', - 'nodeunit:custom_output', + 'express:custom_output', + 'nodeunit:custom_output', 'express:custom_output:stop', - 'express:stoppable', - 'express:stoppable:stop', + 'express:stoppable', + 'express:stoppable:stop', 'nodeunit:stoppable', // Multiple servers - 'express:custom_port', - 'nodeunit:defaults', - 'express:defaults', + 'express:custom_port', + 'nodeunit:defaults', + 'express:defaults', 'nodeunit:custom_port', - 'express:custom_port:stop', + 'express:custom_port:stop', 'express:defaults:stop', ]); diff --git a/tasks/express.js b/tasks/express.js index 4b601b7..41aca90 100644 --- a/tasks/express.js +++ b/tasks/express.js @@ -26,6 +26,7 @@ module.exports = function(grunt) { opts: [ ], args: [ ], node_env: undefined, + harmony: false, background: true, fallback: function() { /* Prevent EADDRINUSE from breaking Grunt */ }, port: process.env.PORT || 3000, @@ -40,6 +41,10 @@ module.exports = function(grunt) { options.args.unshift(options.script); + if (options.harmony) { + options.args.unshift('--harmony'); + } + if (!grunt.file.exists(options.script)) { grunt.log.error('Could not find server script: ' + options.script); diff --git a/test/app.js b/test/app.js index fea7271..de1e392 100644 --- a/test/app.js +++ b/test/app.js @@ -13,6 +13,10 @@ app.get('/env', function(req, res) { res.send('Howdy from ' + app.get('env') + '!'); }); +app.get('/harmony', function(req, res) { + res.send('Harmony flag idx is ' + process.execArgv.indexOf('--harmony')); +}); + // Setup simple echo for each additional argument passed for testing args.slice(2).forEach(function(arg) { app.get('/' + arg, function(req, res) { diff --git a/test/custom_harmony.js b/test/custom_harmony.js new file mode 100644 index 0000000..48bec62 --- /dev/null +++ b/test/custom_harmony.js @@ -0,0 +1,24 @@ +/* + * grunt-express-server + * https://github.com/ericclemmons/grunt-express-server + * + * Copyright (c) 2013 Eric Clemmons + * Licensed under the MIT license. + */ + +'use strict'; + +var get = require('./lib/get'); + +module.exports.custom_args = { + test_runs_in_harmony: function(test) { + test.expect(2); + get('http://localhost:3000/harmony', function(res, body) { + test.equal(res.statusCode, 200, 'should return 200'); + test.equal(body, 'Harmony flag idx is 0'); + test.done(); + }, function(err) { + test.done(); + }); + } +}; diff --git a/test/custom_node_env_test.js b/test/custom_node_env_test.js index e3d2688..9f74646 100644 --- a/test/custom_node_env_test.js +++ b/test/custom_node_env_test.js @@ -13,7 +13,6 @@ var get = require('./lib/get'); module.exports.custom_node_env = { test_site_configured_for_production: function(test) { test.expect(2); - get('http://localhost:3000/env', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy from production!', 'should return dynamic page');