Skip to content

Commit 0171f08

Browse files
committed
fix(mocha): fix server not closing
1 parent ccea1f3 commit 0171f08

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

Diff for: templates/app/mocha.global.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import app from './';<% if (filters.mongoose) { %>
22
import mongoose from 'mongoose';<% } %>
33

4+
<%_ if(!filters.ws) { -%>
45
after(function(done) {
56
app.angularFullstack.on('close', () => done());<% if (filters.mongoose) { %>
67
mongoose.connection.close();<% } %>
78
app.angularFullstack.close();
8-
});
9+
app.primus.end();
10+
});<% } %>
11+
<%_ if(filters.ws) { -%>
12+
let count = 0;
13+
after(function(done) {
14+
app.angularFullstack.on('close', () => {
15+
if(++count === 2) done();
16+
});
17+
mongoose.connection.close();
18+
app.angularFullstack.close();
19+
app.primus.end(() => {
20+
if(++count === 2) done();
21+
});
22+
});<% } %>

Diff for: templates/app/server/app.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ function startServer() {
4545
<% if(filters.sequelize) { %>
4646
sqldb.sequelize.sync()
4747
<%_ if(filters.ws) { -%>
48-
.then(wsInitPromise)<% } %>
48+
.then(wsInitPromise)
49+
.then(primus => {
50+
app.primus = primus;
51+
})<% } %>
4952
.then(startServer)
5053
.catch(err => {
5154
console.log('Server failed to start due to error: %s', err);
5255
});
5356
<% } else { %>
5457
<%_ if(filters.ws) { -%>
5558
wsInitPromise
59+
.then(primus => {
60+
app.primus = primus;
61+
})
5662
.then(startServer)
5763
.catch(err => {
5864
console.log('Server failed to start due to error: %s', err);

Diff for: templates/app/server/config/websockets(ws).js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default function initWebSocketServer(server) {
5353
primus.save(path.join(__dirname, '../../client/components/socket/primus.js'), err => {
5454
if(err) return reject(err);
5555

56-
resolve();
56+
resolve(primus);
5757
});
5858
});
5959
}

0 commit comments

Comments
 (0)