Skip to content

Instantly share code, notes, and snippets.

@nicolaracco
Last active December 30, 2015 00:09
Show Gist options
  • Save nicolaracco/7747356 to your computer and use it in GitHub Desktop.
Save nicolaracco/7747356 to your computer and use it in GitHub Desktop.
# app.coffee
require 'express'
class Server
constructor: ->
@app = express()
@server = http.createServer(@app)
@io = SocketIO.listen @server, logger: @logger
@configure_app()
start: =>
@server.listen 3000
process.send? status: 'started' # if send is defined, we are inside the fork
configure_app: =>
...
# spec/requests/login_page_spec.coffee
TestServer = require '../helpers/test_server'
describe 'Login Page', ->
beforeAll (done) ->
@server = new TestServer done
...
afterAll (done) ->
@server.destroy done
# spec/helpers/test_server.coffee
#
# This module is included in all the specs
fork = require('child_process').fork
class TestServer
childCmd: "app.coffee"
childSettings:
cwd : "#{__dirname}/../.."
execPath: "./node_modules/coffee-script/bin/coffee"
constructor: (done) ->
@child = fork @childCmd, [], @childSettings
@child.on 'message', (data) ->
done() if data.status is 'message'
destroy: (done) =>
@child.on 'exit', -> done()
@child.kill 'SIGTERM'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment