.gitignore000066400000000000000000000000371516102243000130400ustar00rootroot00000000000000node_modules npm-debug.log tmp .jshintrc000066400000000000000000000002771516102243000127030ustar00rootroot00000000000000{ "curly": true, "eqeqeq": true, "immed": true, "latedef": true, "newcap": true, "noarg": true, "sub": true, "undef": true, "boss": true, "eqnull": true, "node": true } .travis.yml000066400000000000000000000000441516102243000131570ustar00rootroot00000000000000language: node_js node_js: - 0.10 Gruntfile.js000066400000000000000000000101701516102243000133440ustar00rootroot00000000000000/* * grunt-express-server * https://github.com/ericclemmons/grunt-express-server * * Copyright (c) 2013 Eric Clemmons * Licensed under the MIT license. */ 'use strict'; module.exports = function(grunt) { // Project configuration. grunt.initConfig({ jshint: { all: [ 'Gruntfile.js', 'tasks/**/*.js', 'test/*.js', ], options: { jshintrc: '.jshintrc', }, }, // Before generating any new files, remove any previously-created files. clean: { tests: ['tmp'], }, watch: { express: { options: { livereload: true, spawn: false }, files: [ 'Gruntfile.js', 'tasks/**/*.js', 'test/**/*.js' ], tasks: ['express:defaults'] } }, // Unit tests. nodeunit: { defaults: { src: 'test/defaults_test.js' }, custom_cmd: { src: 'test/custom_cmd_test.js' }, custom_args: { src: 'test/custom_args_test.js' }, custom_port: { src: 'test/custom_port_test.js' }, custom_node_env: { src: 'test/custom_node_env_test.js' }, custom_delay: { src: 'test/custom_delay_test.js' }, custom_output: { src: 'test/custom_output_test.js' }, stoppable: { src: 'test/stoppable_test.js' } }, express: { options: { script: './test/server.js', port: 3000 }, defaults: {}, custom_cmd: { options: { script: './test/server.coffee', cmd: "coffee", output: "Express server listening on port .+" } }, custom_args: { options: { args: [1, 2], output: "Express server listening on port .+" } }, custom_background: { options: { background: false } }, custom_port: { options: { port: 8080, output: "Express server listening on port .+" } }, custom_node_env: { options: { node_env: "production", output: "Express server listening on port .+" } }, custom_delay: { options: { delay: 1000, output: "This RegEx does not match anything lol" } }, custom_output: { options: { output: "timeout" } }, custom_delay_output: { options: { delay: 1000, output: "Express server listening on port .+" } }, quiet: { options: { script: './test/server-quiet.js' } }, stoppable: {} } }); // Actually load this plugin's task(s). grunt.loadTasks('tasks'); // These plugins provide necessary tasks. grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-watch'); // Whenever the "test" task is run, first clean the "tmp" dir, then run this // plugin's task(s), then test the result. grunt.registerTask('test', [ 'clean', 'express:defaults', 'nodeunit:defaults', 'express:defaults:stop', 'express:custom_cmd', 'nodeunit:custom_cmd', 'express:custom_cmd:stop', 'express:custom_args', 'nodeunit:custom_args', 'express:custom_args:stop', 'express:custom_port', 'nodeunit:custom_port', 'express:custom_port:stop', 'express:custom_node_env', 'nodeunit:custom_node_env', 'express:custom_node_env:stop', 'express:custom_delay', 'nodeunit:custom_delay', 'express:custom_delay:stop', 'express:custom_output', 'nodeunit:custom_output', 'express:custom_output:stop', 'express:stoppable', 'express:stoppable:stop', 'nodeunit:stoppable', // Multiple servers 'express:custom_port', 'express:defaults', 'nodeunit:defaults', 'nodeunit:custom_port', 'express:custom_port:stop', 'express:defaults:stop', ]); // By default, lint and run all tests. grunt.registerTask('default', ['jshint', 'test']); }; LICENSE-MIT000066400000000000000000000020411516102243000125010ustar00rootroot00000000000000Copyright (c) 2013 Eric Clemmons Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. README.md000066400000000000000000000165401516102243000123350ustar00rootroot00000000000000# grunt-express-server [![Build Status](https://travis-ci.org/ericclemmons/grunt-express-server.png?branch=master)](https://travis-ci.org/ericclemmons/grunt-express-server) [![Dependencies](https://david-dm.org/ericclemmons/grunt-express-server.png)](https://david-dm.org/ericclemmons/grunt-express-server) [![devDependencies](https://david-dm.org/ericclemmons/grunt-express-server/dev-status.png)](https://david-dm.org/ericclemmons/grunt-express-server#info=devDependencies&view=table) > Simple grunt task for running an Express server that works great with LiveReload + Watch/Regarde ## Getting Started This plugin requires Grunt `~0.4.0` If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command: ```shell npm install grunt-express-server --save-dev ``` One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript: ```js grunt.loadNpmTasks('grunt-express-server'); ``` ## The `express` task ### Setup In your project's Gruntfile, you can create one or multiple servers: ```js grunt.initConfig({ express: { options: { // Override defaults here }, dev: { options: { script: 'path/to/dev/server.js' } }, prod: { options: { script: 'path/to/prod/server.js', node_env: 'production' } }, test: { options: { script: 'path/to/test/server.js' } } } }); ``` You can override the default `options` either in the root of the `express` config or within each individual server task. ### Default `options` ```js express: { options: { // Override the command used to start the server. // (do not use 'coffee' here, the server will not be able to restart // see below at opts for coffee-script support) cmd: process.argv[0], // Will turn into: `node OPT1 OPT2 ... OPTN path/to/server.js ARG1 ARG2 ... ARGN` // (e.g. opts: ['node_modules/coffee-script/bin/coffee'] will correctly parse coffee-script) opts: [ ], args: [ ], // Setting to `false` will effectively just run `node path/to/server.js` background: true, // Called when the spawned server throws errors fallback: function() {}, // Override node env's PORT port: 3000, // Override node env's NODE_ENV node_env: undefined, // Consider the server to be "running" after an explicit delay (in milliseconds) // (e.g. when server has no initial output) delay: 0, // Regular expression that matches server output to indicate it is "running" output: ".+", // Set --debug debug: false } } ``` ### Usage By default, unless `delay` or `output` has been customized, **the server is considered "running" once any output is logged to the console**, upon which control is passed back to grunt. Typically, this is normally: > Express server listening on port 3000 If you log output *before* the server is running, either set `delay` or `output` to indicate when the server has officially started. #### Starting the server If you have a server defined named `dev`, you can start the server by running `express:dev`. The server only runs as long as grunt is running. Once grunt's tasks have completed, the web server stops. #### Stopping the server Similarly, if you start the `dev` server with `express:dev`, you can stop the server with `express:dev:stop`. #### With [grunt-contrib-watch](https://github.com/gruntjs/grunt-contrib-watch) ```js grunt.initConfig({ watch: { express: { files: [ '**/*.js' ], tasks: [ 'express:dev' ], options: { spawn: false // for grunt-contrib-watch v0.5.0+, "nospawn: true" for lower versions. Without this option specified express won't be reloaded } } } }); grunt.registerTask('server', [ 'express:dev', 'watch' ]) ``` ## Contributing In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). ## Release History - v0.4.19 – Use `process.env.PORT` before `3000` ([#59](https://github.com/ericclemmons/grunt-express-server/pull/59)) - v0.4.18 – Fix for when running the node debugger ([#57](https://github.com/ericclemmons/grunt-express-server/pull/57)) - v0.4.17 – Update `devDependencies`...again - v0.4.16 – Update `devDependencies` - v0.4.15 – Recommend using local `coffee` with additional arguments ([#50](https://github.com/ericclemmons/grunt-express-server/pull/50)) - v0.4.14 – Attempt to fix issues running Coffeescript ([#54](https://github.com/ericclemmons/grunt-express-server/pull/54)) - v0.4.13 – Add `--nodejs` for Coffeescript users ([#37](https://github.com/ericclemmons/grunt-express-server/issues/37)) - v0.4.12 – Only remove this task's listeners ([#39](https://github.com/ericclemmons/grunt-express-server/pull/39)) - v0.4.11 – Revert v0.4.10 until Travis can reproduce it - v0.4.10 – Another attempt to fix #28 & #30's server restarting issue ([#31](https://github.com/ericclemmons/grunt-express-server/pull/31)) - v0.4.9 – Revert v0.4.8 until [#30](https://github.com/ericclemmons/grunt-express-server/issues/30#issuecomment-29931192) is resolved - v0.4.8 – Fix issue with start/restarting multiple instances ([#29](https://github.com/ericclemmons/grunt-express-server/pull/29)) - v0.4.7 – Remove broken `error` option ([#27](https://github.com/ericclemmons/grunt-express-server/issues/27)) - v0.4.6 – Store running servers on `process._servers[target]` ([#22](https://github.com/ericclemmons/grunt-express-server/issues/22)) - v0.4.5 – Support multiple servers running at once ([#23](https://github.com/ericclemmons/grunt-express-server/pull/23)) - v0.4.4 - Fix for using `grunt-env` to change environments, thanks to @FredrikAppelros ([#20](https://github.com/ericclemmons/grunt-express-server/pull/20)) - v0.4.3 - Add `cmd` option that defaults to Node, but can be set to `coffee` for Coffeescript support, thanks to @JonET ([#15](https://github.com/ericclemmons/grunt-express-server/pull/15)) - v0.4.2 - Add `debug` option that gets enables Node's debugger, ideally for use with [node-inspector](https://github.com/node-inspector/node-inspector) - v0.4.1 - Add `node_env` option that sets `NODE_ENV` when running the server & restores original env upon closing, thanks to @jgable! - v0.4.0 - Add `delay` option that, when set, passes control back to grunt after timeout - Add `output` regular expression option that, when set, waits for matching message before passing control back to grunt - v0.3.1 - Try to force notification that `express` task has finished as much as possible - v0.3.0 - `express` is now a multitask with customizable options, better error handling and `:stop` task - v0.2.0 - Change `express-server` task to `express` - Config is set via `express: '...'` instead of `server: { script: '...' } ` - v0.1.0 - Initial import from [Genesis Skeleton](https://github.com/ericclemmons/genesis-skeleton) & release [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ericclemmons/grunt-express-server/trend.png)](https://bitdeli.com/free "Bitdeli Badge") package.json000066400000000000000000000022651516102243000133430ustar00rootroot00000000000000{ "name": "grunt-express-server", "description": "Grunt task for running an Express Server that works great with LiveReload + Watch/Regarde", "version": "0.4.19", "homepage": "https://github.com/ericclemmons/grunt-express-server", "author": { "name": "Eric Clemmons", "email": "eric@smarterspam.com" }, "repository": { "type": "git", "url": "git://github.com/ericclemmons/grunt-express-server.git" }, "bugs": { "url": "https://github.com/ericclemmons/grunt-express-server/issues" }, "licenses": [ { "type": "MIT", "url": "https://github.com/ericclemmons/grunt-express-server/blob/master/LICENSE-MIT" } ], "main": "Gruntfile.js", "engines": { "node": ">= 0.8.0" }, "scripts": { "test": "./node_modules/.bin/grunt" }, "devDependencies": { "coffee-script": "^1.7.1", "express": "^4.0.0", "grunt": "^0.4.4", "grunt-cli": "^0.1.13", "grunt-contrib-clean": "^0.5.0", "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-nodeunit": "^0.3.3", "grunt-contrib-watch": "^0.6.1" }, "peerDependencies": { "grunt": "~0.4.0" }, "keywords": [ "gruntplugin", "express", "server" ] } tasks/000077500000000000000000000000001516102243000121755ustar00rootroot00000000000000tasks/express.js000066400000000000000000000023111516102243000142210ustar00rootroot00000000000000/* * grunt-express-server * https://github.com/ericclemmons/grunt-express-server * * Copyright (c) 2013 Eric Clemmons * Licensed under the MIT license. */ 'use strict'; var path = require('path'); module.exports = function(grunt) { var servers = {}; grunt.registerMultiTask('express', 'Start an express web server', function() { if (!servers[this.target]) { servers[this.target] = require('./lib/server')(grunt, this.target); } var server = servers[this.target]; var action = this.args.shift() || 'start'; var options = this.options({ cmd: process.argv[0], opts: [ ], args: [ ], node_env: undefined, background: true, fallback: function() { /* Prevent EADDRINUSE from breaking Grunt */ }, port: process.env.PORT || 3000, delay: 0, output: ".+", debug: false }); options.script = path.resolve(options.script); options.args.unshift(options.script); if (!grunt.file.exists(options.script)) { grunt.log.error('Could not find server script: ' + options.script); return false; } server[action](options); }); }; tasks/lib/000077500000000000000000000000001516102243000127435ustar00rootroot00000000000000tasks/lib/server.js000066400000000000000000000073341516102243000146160ustar00rootroot00000000000000/* * grunt-express-server * https://github.com/ericclemmons/grunt-express-server * * Copyright (c) 2013 Eric Clemmons * Licensed under the MIT license. */ 'use strict'; module.exports = function(grunt, target) { if (!process._servers) { process._servers = {}; } var backup = null; var done = null; var server = process._servers[target]; // Store server between live reloads to close/restart express var finished = function() { if (done) { done(); done = null; } }; return { start: function start(options) { if (server) { this.stop(); if (grunt.task.current.flags.stop) { finished(); return; } } backup = JSON.parse(JSON.stringify(process.env)); // Clone process.env // For some weird reason, on Windows the process.env stringify produces a "Path" // member instead of a "PATH" member, and grunt chokes when it can't find PATH. if (!backup.PATH) { if (backup.Path) { backup.PATH = backup.Path; delete backup.Path; } } grunt.log.writeln('Starting '.cyan + (options.background ? 'background' : 'foreground') + ' Express server'); done = grunt.task.current.async(); // Set PORT for new processes process.env.PORT = options.port; // Set NODE_ENV for new processes if (options.node_env) { process.env.NODE_ENV = options.node_env; } if (options.cmd === 'coffee') { grunt.log.writeln('You are using cmd: coffee'.red); grunt.log.writeln('coffee does not allow a restart of the server'.red); grunt.log.writeln('use opts: ["path/to/your/coffee"] instead'.red); } // Set debug mode for node-inspector if (options.debug) { options.opts.unshift('--debug'); if (options.cmd === 'coffee') { options.opts.unshift('--nodejs'); } } if (options.background) { var donefunc = (options.delay || options.output) ? function() {} : finished; server = process._servers[target] = grunt.util.spawn({ cmd: options.cmd, args: options.opts.concat(options.args), env: process.env, fallback: options.fallback }, donefunc); if (options.delay) { setTimeout(finished, options.delay); } if (options.output) { server.stdout.on('data', function(data) { var message = "" + data; var regex = new RegExp(options.output, "gi"); if (message.match(regex)) { finished(); } }); } server.stderr.on('data', function(data) { if (!options.debug) { finished(); } else { var message = "" + data; var regex = new RegExp('debugger listening', "gi"); if (!message.match(regex)) { finished(); } } }); server.stdout.pipe(process.stdout); server.stderr.pipe(process.stderr); } else { // Server is ran in current process server = process._servers[target] = require(options.script); } process.on('exit', finished); process.on('exit', this.stop); }, stop: function stop() { if (server && server.kill) { grunt.log.writeln('Stopping'.red + ' Express server'); server.kill('SIGTERM'); process.removeListener('exit', finished); process.removeListener('exit', stop); server = process._servers[target] = null; } // Restore original process.env if (backup) { process.env = JSON.parse(JSON.stringify(backup)); } finished(); } }; }; test/000077500000000000000000000000001516102243000120275ustar00rootroot00000000000000test/app.coffee000066400000000000000000000003601516102243000137570ustar00rootroot00000000000000"use strict" express = require("express") app = module.exports = express() env = (process.env.NODE_ENV or 'development') app.set 'port', (process.env.PORT or 3000) app.get "/", (req, res) -> res.send "Howdy from CoffeeScript!" test/app.js000066400000000000000000000011171516102243000131450ustar00rootroot00000000000000"use strict"; var express = require('express'); var app = module.exports = express(); var args = process.argv; var env = process.env.NODE_ENV || 'development'; app.set('port', process.env.PORT || 3000); app.use(express.static(__dirname + '/../test/fixtures')); app.get('/env', function(req, res) { res.send('Howdy from ' + app.get('env') + '!'); }); // Setup simple echo for each additional argument passed for testing args.slice(2).forEach(function(arg) { app.get('/' + arg, function(req, res) { res.send('Howdy ' + arg + ' from ' + app.get('env') + '!'); }); }); test/custom_args_test.js000066400000000000000000000023031516102243000157500ustar00rootroot00000000000000/* * 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 = { 1: function(test) { test.expect(2); get('http://localhost:3000/1', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy 1 from development!', 'should return dynamic page'); test.done(); }, function(err) { test.done(); }); }, 2: function(test) { test.expect(2); get('http://localhost:3000/2', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy 2 from development!', 'should return dynamic page'); test.done(); }, function(err) { test.done(); }); }, test_runs_in_development: 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 development!', 'should return dynamic page'); test.done(); }, function(err) { test.done(); }); } }; test/custom_cmd_test.js000066400000000000000000000011451516102243000155620ustar00rootroot00000000000000/* * 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_output = { test_runs_from_coffeescript_server: function(test) { test.expect(2); get('http://localhost:3000/', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy from CoffeeScript!', 'should return message from CoffeeScript server'); test.done(); }, function(err) { test.done(); }); } }; test/custom_delay_test.js000066400000000000000000000016221516102243000161150ustar00rootroot00000000000000/* * 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_delay = { test_runs_after_timeout: function(test) { test.expect(2); get('http://localhost:3000/hello.txt', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy!\n', 'should return static page'); test.done(); }, function(err) { test.done(); }); }, test_runs_in_development: 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 development!', 'should return dynamic page'); test.done(); }, function(err) { test.done(); }); } }; test/custom_node_env_test.js000066400000000000000000000011251516102243000166120ustar00rootroot00000000000000/* * 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_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'); test.done(); }, function(err) { test.done(); }); } }; test/custom_output_test.js000066400000000000000000000016341516102243000163620ustar00rootroot00000000000000/* * 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_output = { test_runs_after_listening_output: function(test) { test.expect(2); get('http://localhost:3000/hello.txt', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy!\n', 'should return static page'); test.done(); }, function(err) { test.done(); }); }, test_runs_in_development: 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 development!', 'should return dynamic page'); test.done(); }, function(err) { test.done(); }); } }; test/custom_port_test.js000066400000000000000000000016211516102243000160020ustar00rootroot00000000000000/* * 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_port = { test_accessible_on_8080: function(test) { test.expect(2); get('http://localhost:8080/hello.txt', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy!\n', 'should return static page'); test.done(); }, function(err) { test.done(); }); }, test_runs_in_development: function(test) { test.expect(2); get('http://localhost:8080/env', function(res, body) { test.equal(res.statusCode, 200, 'should return 200'); test.equal(body, 'Howdy from development!', 'should return dynamic page'); test.done(); }, function(err) { test.done(); }); } }; test/defaults_test.js000066400000000000000000000011221516102243000152270ustar00rootroot00000000000000/* * 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.defaults = { test_server_not_running: function(test) { test.expect(1); try { get('http://localhost:3000/hello.txt', function(res, body) { throw new Error('Server should not be running yet'); }, function(err) { test.equals('ECONNREFUSED', err.code); test.done(); }); } catch (e) { test.done(); } } }; test/fixtures/000077500000000000000000000000001516102243000137005ustar00rootroot00000000000000test/fixtures/hello.txt000066400000000000000000000000071516102243000155410ustar00rootroot00000000000000Howdy! test/lib/000077500000000000000000000000001516102243000125755ustar00rootroot00000000000000test/lib/get.js000066400000000000000000000010031516102243000137040ustar00rootroot00000000000000/* * grunt-express-server * https://github.com/ericclemmons/grunt-express-server * * Copyright (c) 2013 Eric Clemmons * Licensed under the MIT license. */ 'use strict'; var http = require('http'); module.exports = function get(url, callback, error) { var req = http.get(url, function(res) { var body = ''; res.on('data', function(chunk) { body += chunk; }).on('end', function() { callback(res, body); }); }); if (error) { req.on('error', error) }; req.end(); } test/server-quiet.js000066400000000000000000000001641516102243000150210ustar00rootroot00000000000000"use strict"; /** * Test Server */ var app = require('./app'); module.exports = app.listen(app.get('port')); test/server.coffee000066400000000000000000000006711516102243000145120ustar00rootroot00000000000000"use strict" ### Test Server - CoffeeScript Edition ### app = require("./app.coffee") start = Date.now() log = (message) -> console.log "[" + (Date.now() - start) + "] " + message log "Begin coffeescript-server.coffee" setTimeout (-> module.exports = app.listen(app.get("port"), -> log "Express server listening on port " + app.get("port") ) ), 50 setTimeout (-> log "250ms timeout" ), 250 log "End coffeescript-server.coffee" test/server.js000066400000000000000000000007111516102243000136720ustar00rootroot00000000000000"use strict"; /** * Test Server */ var app = require('./app'); var start = Date.now(); var log = function(message) { console.log("[" + (Date.now() - start) + "] " + message); }; log("Begin server.js"); setTimeout(function() { module.exports = app.listen(app.get('port'), function() { log("Express server listening on port " + app.get('port')); }); }, 50); setTimeout(function() { log("250ms timeout"); }, 250); log("End server.js"); test/stoppable_test.js000066400000000000000000000007651516102243000154250ustar00rootroot00000000000000/* * 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.stoppable = { hello: function(test) { test.expect(1); get('http://localhost:3000/hello.txt', function(res, body) { test.done(); }, function(err) { test.equal('ECONNREFUSED', err.code, 'should return ECONNREFUSED'); test.done(); }); } };