Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test server task): stop the server when the test has ran
BREAKING CHANGE: The application server routes file arguments have changed because it was limited to only app and opts. Now this file accepts one server argument that is an object containing app, express, middleware, paths and server. Before: module.exports = (app, opts) => { app.get('/api/superheroes', (req, res) => ... } Now: module.exports = (server) => { var app = server.app app.get('/api/superheroes', (req, res) => ... }
- Loading branch information
Showing
19 changed files
with
236 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
module.exports = (config) -> | ||
q = require 'q' | ||
path = require 'path' | ||
Jasmine = require 'jasmine' | ||
Reporter = require 'jasmine-terminal-reporter' | ||
jasmineExpect = path.join config.node_modules.rb.src.relPath, 'jasmine-expect', 'index.js' | ||
|
||
jasmine = | ||
# properties | ||
# ========== | ||
defer: q.defer() | ||
jasmine: null | ||
results: status: null, total: 0, passed: 0, failed: 0, failedSpecs: [] | ||
|
||
# public | ||
# ====== | ||
init: (files) -> | ||
@_setJasmine() | ||
._setConfig files | ||
._setOnComplete() | ||
._addReporter() | ||
@ | ||
|
||
execute: -> # 5 seconds is the default spec timeout | ||
@jasmine.execute() | ||
@defer.promise | ||
|
||
getResults: -> | ||
@results | ||
|
||
# private | ||
# ======= | ||
_setJasmine: -> | ||
@jasmine = new Jasmine() | ||
@ | ||
|
||
_setConfig: (files) -> | ||
@jasmine.loadConfig | ||
spec_dir: '' | ||
spec_files: files | ||
helpers: [ jasmineExpect ] | ||
@ | ||
|
||
_setOnComplete: (defer) -> | ||
@jasmine.onComplete (passed) => | ||
@results.status = if passed then 'passed' else 'failed' | ||
@defer.resolve() | ||
@ | ||
|
||
_addReporter: -> | ||
@jasmine.addReporter new Reporter | ||
isVerbose: false | ||
showColors: true | ||
includeStackTrace: false | ||
|
||
@jasmine.addReporter | ||
specDone: (result) => | ||
@results.total++ | ||
return @results.passed++ if result.status is 'passed' | ||
@results.failed++ | ||
@results.failedSpecs.push result.fullName | ||
@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# default app configuration | ||
# ========================= | ||
module.exports = (server, config) -> | ||
app = server.app | ||
spa = config.spa.dist.file # ex: spa.html | ||
|
||
app.set 'x-powered-by', false # removes this http header | ||
app.use server.express.static server.paths.client | ||
app.use server.middleware.bodyParser.json() # parse application/json | ||
|
||
app.get '/', (req, res) -> | ||
msg = 'Hello Server!' | ||
return res.send msg unless config.build.client | ||
return res.send msg if config.exclude.spa | ||
res.sendFile spa, root: server.paths.client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
dir = __dirname # all paths are relative to this file | ||
path = require 'path' | ||
express = require 'express' | ||
bodyParser = require 'body-parser' # middleware for parsing the req.body | ||
config = require path.join dir, 'config.json' | ||
appFilePath = path.resolve dir, '..', config.dist.app.server.scripts.file | ||
clientDirPath = path.resolve dir, '..', '..', config.dist.app.client.dirName # creates absolute path to the client folder | ||
serverDirPath = path.resolve dir, '..', '..', config.dist.app.server.dirName | ||
|
||
# create the server object | ||
# ======================== | ||
server = require './server' | ||
server.express = express | ||
server.app = server.express() | ||
server.middleware = { bodyParser } | ||
server.paths = client: clientDirPath, server: serverDirPath | ||
server.server = require('./start-server') server.app, config | ||
require('./app-defaults') server, config | ||
|
||
# load optional http proxy | ||
# ======================== | ||
proxyFilePath = path.join dir, 'http-proxy.js' | ||
require(proxyFilePath) server.app, config if config.httpProxy.length | ||
|
||
# load optional app server dist entry script | ||
# ========================================== | ||
try require(appFilePath) server | ||
catch e | ||
if e.code and | ||
e.code.toLowerCase() is 'module_not_found' and | ||
e.message.indexOf(appFilePath) isnt -1 | ||
console.log 'No application server scripts to load.' | ||
else | ||
console.log e # log e if there is an actual error | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,3 @@ | ||
dir = __dirname # all paths are relative to this file | ||
path = require 'path' | ||
express = require 'express' | ||
bodyParser = require 'body-parser' | ||
config = require path.join dir, 'config.json' | ||
app = express() | ||
port = process.env.PORT or config.ports.server | ||
spa = config.spa.dist.file # ex: spa.html | ||
clientDirPath = path.resolve dir, '..', '..', config.dist.app.client.dirName # creates absolute path to the client folder | ||
appFilePath = path.resolve dir, '..', config.dist.app.server.scripts.file | ||
serverDirPath = path.resolve dir, '..', '..', config.dist.app.server.dirName | ||
proxyFilePath = path.join dir, 'http-proxy.js' | ||
|
||
# configure | ||
# ========= | ||
app.use express.static clientDirPath | ||
app.use bodyParser.json() # parse application/json | ||
|
||
app.listen port, -> | ||
console.log "#{config.server.msg.start} #{config.ports.server}" | ||
|
||
app.get '/', (req, res) -> | ||
msg = 'Hello Server!' | ||
return res.send msg unless config.build.client | ||
return res.send msg if config.exclude.spa | ||
res.sendFile spa, root: clientDirPath | ||
|
||
# options to pass | ||
# =============== | ||
opts = | ||
path: | ||
client: clientDirPath | ||
server: serverDirPath | ||
|
||
# load optional http proxy | ||
# ======================== | ||
require(proxyFilePath) app, config, opts if config.httpProxy.length | ||
|
||
# load optional app server dist entry script | ||
# ========================================== | ||
try require(appFilePath) app, opts | ||
catch e | ||
if e.code and | ||
e.code.toLowerCase() is 'module_not_found' and | ||
e.message.indexOf(appFilePath) isnt -1 | ||
console.log config.server.msg.noScripts | ||
else | ||
console.log e # log e if there is an actual error | ||
# Dynamically populated in init-server.js | ||
# ======================================= | ||
module.exports = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = (app, config) -> | ||
port = process.env.PORT or config.ports.server | ||
|
||
# must return server | ||
# ================== | ||
server = app.listen port, -> | ||
console.log "Server started on port #{port}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = -> | ||
q = require 'q' | ||
server = require('./server').server | ||
port = server.address().port | ||
|
||
defer = q.defer() | ||
server.close -> | ||
console.log "Server stopped on port #{port}" | ||
defer.resolve() | ||
|
||
defer.promise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.