-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We experienced a lot of issues replacing mocha because server.js had a lot of complicated code and it wasn’t clear what was happening. This commit starts to address this issue by splitting the server and the app logic into separate files (server.js and app.js) As mentioned in this blog http://www.albertgao.xyz/2017/05/24/how-to-test-expressjs-with-jest-and-supertest/. There is no need to add listeners to the app for testing and seems to be a best practice.
- Loading branch information
1 parent
c82d3c6
commit 1e6d8c3
Showing
3 changed files
with
35 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// NPM dependencies | ||
const browserSync = require('browser-sync') | ||
|
||
// Local dependencies | ||
const app = require('./app.js') | ||
const config = require('./app/config.js') | ||
const utils = require('./lib/utils.js') | ||
|
||
// Set up configuration variables | ||
var useBrowserSync = config.useBrowserSync.toLowerCase() | ||
var env = (process.env.NODE_ENV || 'development').toLowerCase() | ||
|
||
// Find a free port and start the server | ||
utils.findAvailablePort(app, function (port) { | ||
console.log('Listening on port ' + port + ' url: http://localhost:' + port) | ||
if (env === 'production' || useBrowserSync === 'false') { | ||
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 |