0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🐛 Readded missing server.start event

closes #12118

- server.start was mistakenly removed in 71f02d25e9
- it is used for loading themes (and other things) and is critical
- added tests to prevent this regressing again in future
This commit is contained in:
Hannah Wolfe 2020-08-11 10:07:00 +01:00
parent 3b2d3f1d60
commit e84621d6ef
2 changed files with 21 additions and 0 deletions

View file

@ -252,6 +252,8 @@ module.exports.announceServerReadiness = function (error = null) {
if (error) {
message.started = false;
message.error = error;
} else {
events.emit('server.start');
}
// CASE: IPC communication to the CLI for local process manager

View file

@ -2,6 +2,7 @@ const should = require('should');
const sinon = require('sinon');
const configUtils = require('../../utils/configUtils');
const {events} = require('../../../core/server/lib/common');
const bootstrapSocket = require('@tryghost/bootstrap-socket');
@ -9,6 +10,7 @@ describe('GhostServer', function () {
describe('announceServerReadiness', function () {
let GhostServer;
let socketStub;
let eventSpy;
beforeEach(function () {
// Have to re-require each time to clear the internal flag
@ -20,12 +22,16 @@ describe('GhostServer', function () {
// stub socket connectAndSend method
socketStub = sinon.stub(bootstrapSocket, 'connectAndSend');
// Spy for the events that get called
eventSpy = sinon.spy(events, 'emit');
});
afterEach(function () {
process.send = undefined;
configUtils.restore();
socketStub.restore();
eventSpy.restore();
});
it('it resolves a promise', function () {
@ -96,5 +102,18 @@ describe('GhostServer', function () {
process.send.calledOnce.should.be.true();
socketStub.calledOnce.should.be.true();
});
it('sends server.start event correctly on success', function () {
GhostServer.announceServerReadiness();
eventSpy.calledOnce.should.be.true();
eventSpy.firstCall.args[0].should.eql('server.start');
});
it('does not send server.start event on failure', function () {
GhostServer.announceServerReadiness(new Error('something went wrong'));
eventSpy.calledOnce.should.be.false();
});
});
});