Skip to content

Commit

Permalink
separate server from run-server for mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
joelanman committed Nov 3, 2016
1 parent 3fac745 commit e86546b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gulp/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var config = require('./config.json')

gulp.task('server', function () {
nodemon({
script: 'server.js',
script: 'run-server.js',
ext: 'js, json',
ignore: [config.paths.public + '*',
config.paths.assets + '*',
Expand Down
33 changes: 33 additions & 0 deletions run-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var utils = require('./lib/utils.js')
var app = require('./server.js')
var browserSync = require('browser-sync')
var packageJson = require('./package.json')

// Grab environment variables specified in Procfile or as Heroku config vars
var releaseVersion = packageJson.version
var env = process.env.NODE_ENV || 'development'

console.log('\nGOV.UK Prototype kit v' + releaseVersion)
// Display warning not to use kit for production services.
console.log('\nNOTICE: the kit is for building prototypes, do not use it for production services.')

// start the app
utils.findAvailablePort(app, function (port) {
console.log('Listening on port ' + port + ' url: http://localhost:' + port)
if (env === 'production') {
app.listen(port)
} else {
app.listen(port - 50, function () {
browserSync({
proxy: 'localhost:' + (port - 50),
port: port,
ui: false,
files: ['public/**/*.*', 'app/views/**/*.*'],
ghostmode: false,
open: false,
notify: false,
logLevel: 'error'
})
})
}
})
26 changes: 0 additions & 26 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var favicon = require('serve-favicon')
var app = express()
var documentationApp = express()
var bodyParser = require('body-parser')
var browserSync = require('browser-sync')
var config = require('./app/config.js')
var utils = require('./lib/utils.js')
var packageJson = require('./package.json')
Expand Down Expand Up @@ -182,29 +181,4 @@ if (useDocumentation) {
})
}

console.log('\nGOV.UK Prototype kit v' + releaseVersion)
// Display warning not to use kit for production services.
console.log('\nNOTICE: the kit is for building prototypes, do not use it for production services.')

// start the app
utils.findAvailablePort(app, function (port) {
console.log('Listening on port ' + port + ' url: http://localhost:' + port)
if (env === 'production') {
app.listen(port)
} else {
app.listen(port - 50, function () {
browserSync({
proxy: 'localhost:' + (port - 50),
port: port,
ui: false,
files: ['public/**/*.*', 'app/views/**/*.*'],
ghostmode: false,
open: false,
notify: false,
logLevel: 'error'
})
})
}
})

module.exports = app
12 changes: 9 additions & 3 deletions test/spec/sanity-checks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global describe, it, before */
/* eslint-env mocha */

var request = require('supertest')
var assert = require('assert')
var path = require('path')
Expand All @@ -9,10 +10,15 @@ var fs = require('fs')
*/
describe('The prototype kit', function () {
var app
var server

before(function (done) {
before(function () {
app = require('../../server')
done()
server = app.listen(3000)
})

after(function () {
server.close()
})

it('should generate assets into the /public folder', function () {
Expand Down

0 comments on commit e86546b

Please sign in to comment.