Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6341799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:06:38+00:00 2026-05-24T20:06:38+00:00

I have an express server which I am testing using vows. I want to

  • 0

I have an express server which I am testing using vows. I want to run the server from within the vows test suite, so that I dont need to have it running in the background in order for the test suite to work, then I can just create a cake task which runs the server and tests it in isolation.

In server.coffee I have created the (express) server, configured it, set up routes and called app.listen(port) like this:

# Express - setup
express = require 'express'
app = module.exports = express.createServer()

# Express - configure and set up routes
app.configure ->
   app.set 'views', etc....
   ....

# Express - start
app.listen 3030

In my simple routes-test.js I have :

vows    = require('vows'),
assert  = require('assert'),
server  = require('../app/server/server');

// Create a Test Suite
vows.describe('routes').addBatch({
    'GET /'     : respondsWith(200),
    'GET /401'  : respondsWith(401),
    'GET /403'  : respondsWith(403),
    'GET /404'  : respondsWith(404),
    'GET /500'  : respondsWith(500),
    'GET /501'  : respondsWith(501)
}).export(module);

where respondsWith(code) is similar in functionality to the one in the vows doc…

When I require server in the above test, it automatically begins running the server and the tests run and pass, which is great, but I dont feel like I am doing it the ‘right’ way.

I dont have much control over when the server begins, and what happens if I want to configure the server to point to a ‘test’ environment rather than the default one, or change the default logging level for when im testing?

PS I am going to convert my vows to Coffeescript but for now its all in js as im in learning mode from the docs!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:06:40+00:00Added an answer on May 24, 2026 at 8:06 pm

    That is an interesting question because exactly last night I did what you want to do. I have a little CoffeScript Node.js app which happened to be written like the one you showed. Then, I refactored it, creating the following app.coffee:

    # ... Imports
    app = express.createServer()
    
    # Create a helper function
    exports.start = (options={port:3000, logfile:undefined})->
      # A function defined in another module which configures the app
      conf.configure app, options 
      app.get '/', index.get
      # ... Other routes
      console.log 'Starting...'
      app.listen options.port
    

    Now I have an index.coffee (equivalent to your server.coffee) as simple as:

    require('./app').start port:3000
    

    Then, I wrote some tests using Jasmine-node and Zombie.js. The test framework is different but the principle is the same:

    app = require('../../app')
    # ...
    
    # To avoid annoying logging during tests
    logfile = require('fs').createWriteStream 'extravagant-zombie.log'
    
    # Use the helper function to start the app
    app.start port: 3000, logfile: logfile
    
    describe "GET '/'", ->
      it "should have no blog if no one was registered", ->
        zombie.visit 'http://localhost:3000', (err, browser, status) ->
          expect(browser.text 'title').toEqual 'My Title'
          asyncSpecDone()
        asyncSpecWait()
    

    The point is: what I did and I would suggest is to create a function in a module which starts the server. Then, call this function wherever you want. I do not know if it is “good design”, but it works and seems readable and practical to me.

    Also, I suspect there is no “good design” in Node.js and CoffeScript yet. Those are brand new, very innovative technologies. Of course, we can “feel something is wrong” – like this situation, where two different people didn’t like the design and changed it. We can feel the “wrong way”, but it does not mean there is a “right way” already. Summing up, I believe we will have to invent some “right ways” in your development 🙂

    (But it is good to ask about good ways of doing things, too. Maybe someone has a good idea and the public discussion will be helpful for other developers.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an application that installs SQL Server Express from the command line and
I have a database (SQL server express 2008) which has a column that is
SQL Server Express does not have the Tasks -> Import Data option that other
I have upgraded a SQL Server Express 2005 instance to Standard using the best
I currently have a SQL Server (Express 2005) database to hold some transaction/metadata that
We have a product that runs Sql Server Express 2005 and uses mainly ASP.NET.
Assume that you have a running SQL Server Express instance named (local)\SQLEXPRESS. Its database
I'm using SQL Server 2005 express I have a datetime field in a table
I have a piece of code that creates an SQL Server Express 2008 in
I have a Node.js Express app that I'm hosting on Nodejitsu. I'm already using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.