From e84621d6efa1c9dc3a0beeab654f3a92d0c14245 Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Tue, 11 Aug 2020 10:07:00 +0100 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=90=9B=20Readded=20missing=20server.st?= =?UTF-8?q?art=20event?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #12118 - server.start was mistakenly removed in https://github.com/TryGhost/Ghost/commit/71f02d25e9da2bbae727d5c3ead5c6d9b0de02ef - it is used for loading themes (and other things) and is critical - added tests to prevent this regressing again in future --- core/server/ghost-server.js | 2 ++ test/unit/server/ghost-server_spec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/core/server/ghost-server.js b/core/server/ghost-server.js index 59e1acfab6..47984fbc64 100644 --- a/core/server/ghost-server.js +++ b/core/server/ghost-server.js @@ -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 diff --git a/test/unit/server/ghost-server_spec.js b/test/unit/server/ghost-server_spec.js index 8829876ae9..661c6ed51c 100644 --- a/test/unit/server/ghost-server_spec.js +++ b/test/unit/server/ghost-server_spec.js @@ -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(); + }); }); });