Removed use of ghostServer variable pattern

refs https://github.com/TryGhost/Toolbox/issues/138

- There is no good reason to keep this extra variable around just call "stop" in couple very specific cases. Even for those cases, there's `testUtils.stopGhost` method which achieves the same without additional variable to track.
This commit is contained in:
Naz 2021-11-24 13:13:06 +04:00 committed by naz
parent 8dd33c5034
commit 231cfef086
29 changed files with 63 additions and 128 deletions

View File

@ -10,16 +10,15 @@ const labs = require('../../../core/shared/labs');
describe('Settings API', function () {
let request;
let ghostServer;
before(async function () {
ghostServer = await localUtils.startGhost();
await localUtils.startGhost();
request = supertest.agent(config.get('url'));
await localUtils.doAuth(request);
});
after(function () {
return ghostServer.stop();
return testUtils.stopGhost();
});
it('Can request all settings', async function () {
@ -262,6 +261,6 @@ describe('Settings API', function () {
.expect(200);
res.headers['x-cache-invalidate'].should.eql('/*');
await ghostServer.stop();
await testUtils.stopGhost();
});
});

View File

@ -12,13 +12,10 @@ const mailService = require('../../../../../core/server/services/mail/index');
let request;
describe('Authentication API v3', function () {
let ghostServer;
describe('Blog setup', function () {
before(function () {
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -139,8 +136,7 @@ describe('Authentication API v3', function () {
describe('Invitation', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
// simulates blog setup (initialises the owner)

View File

@ -71,7 +71,7 @@ describe('Identities API', function () {
describe('As non-Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -87,7 +87,7 @@ describe('Members Sigin URL API', function () {
describe('As non-Owner and non-Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -10,7 +10,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -70,7 +70,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -118,7 +118,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
requestEditor1 = supertest.agent(config.get('url'));
requestEditor2 = supertest.agent(config.get('url'));
})

View File

@ -8,7 +8,7 @@ let request;
describe('Pages API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -437,14 +437,12 @@ const defaultSettingsKeyTypes = [
];
describe('Settings API (canary)', function () {
let ghostServer;
let request;
describe('As Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -1270,9 +1268,8 @@ describe('Settings API (canary)', function () {
describe('As Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
request = supertest.agent(config.get('url'));
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
// create admin
@ -1295,8 +1292,7 @@ describe('Settings API (canary)', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -1356,8 +1352,7 @@ describe('Settings API (canary)', function () {
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -9,12 +9,9 @@ const events = require('../../../../../core/server/lib/common/events');
let request;
describe('Slack API', function () {
let ghostServer;
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -9,15 +9,13 @@ let request;
describe('User API', function () {
let editor;
let author;
let ghostServer;
let otherAuthor;
let admin;
describe('As Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -149,8 +147,7 @@ describe('User API', function () {
describe('As Editor', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -229,8 +226,7 @@ describe('User API', function () {
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -11,7 +11,7 @@ describe('Authors Content API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -13,13 +13,10 @@ const configUtils = require('../../../../utils/configUtils');
let request;
describe('Authentication API v2', function () {
let ghostServer;
describe('Blog setup: default config', function () {
before(function () {
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -138,8 +135,7 @@ describe('Authentication API v2', function () {
describe('Blog setup: custom config', function () {
before(function () {
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -261,8 +257,7 @@ describe('Authentication API v2', function () {
describe('Invitation', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
// simulates blog setup (initialises the owner)

View File

@ -10,7 +10,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -70,7 +70,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -118,7 +118,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
requestEditor1 = supertest.agent(config.get('url'));
requestEditor2 = supertest.agent(config.get('url'));
})

View File

@ -10,13 +10,11 @@ const localUtils = require('./utils');
const dnsPromises = require('dns').promises;
describe('Oembed API (v2)', function () {
let ghostServer;
let request;
before(function () {
return testUtils.startGhost()
.then((_ghostServer) => {
ghostServer = _ghostServer;
.then(() => {
request = supertest.agent(config.get('url'));
})
.then(() => {

View File

@ -8,7 +8,7 @@ let request;
describe('Pages API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -91,14 +91,12 @@ const defaultSettingsKeyTypes = [
];
describe('Settings API (v2)', function () {
let ghostServer;
let request;
describe('As Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -729,8 +727,7 @@ describe('Settings API (v2)', function () {
describe('As Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -754,8 +751,7 @@ describe('Settings API (v2)', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -815,8 +811,7 @@ describe('Settings API (v2)', function () {
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -9,12 +9,9 @@ const events = require('../../../../../core/server/lib/common/events');
let request;
describe('Slack API', function () {
let ghostServer;
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -9,15 +9,13 @@ let request;
describe('User API', function () {
let editor;
let author;
let ghostServer;
let otherAuthor;
let admin;
describe('As Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -149,8 +147,7 @@ describe('User API', function () {
describe('As Editor', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -229,8 +226,7 @@ describe('User API', function () {
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -11,7 +11,7 @@ describe('Authors Content API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -12,13 +12,10 @@ const mailService = require('../../../../../core/server/services/mail/index');
let request;
describe('Authentication API v3', function () {
let ghostServer;
describe('Blog setup', function () {
before(function () {
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -138,8 +135,7 @@ describe('Authentication API v3', function () {
describe('Invitation', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
// simulates blog setup (initialises the owner)

View File

@ -71,7 +71,7 @@ describe('Identities API', function () {
describe('As non-Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -87,7 +87,7 @@ describe('Members Sigin URL API', function () {
describe('As non-Owner and non-Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -10,7 +10,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -70,7 +70,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -118,7 +118,7 @@ describe('Notifications API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
requestEditor1 = supertest.agent(config.get('url'));
requestEditor2 = supertest.agent(config.get('url'));
})

View File

@ -8,7 +8,7 @@ let request;
describe('Pages API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -95,14 +95,12 @@ const defaultSettingsKeyTypes = [
];
describe('Settings API (v3)', function () {
let ghostServer;
let request;
describe('As Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -723,8 +721,7 @@ describe('Settings API (v3)', function () {
describe('As Admin', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -748,8 +745,7 @@ describe('Settings API (v3)', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -809,8 +805,7 @@ describe('Settings API (v3)', function () {
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -9,12 +9,9 @@ const events = require('../../../../../core/server/lib/common/events');
let request;
describe('Slack API', function () {
let ghostServer;
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -9,15 +9,13 @@ let request;
describe('User API', function () {
let editor;
let author;
let ghostServer;
let otherAuthor;
let admin;
describe('As Owner', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -149,8 +147,7 @@ describe('User API', function () {
describe('As Editor', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {
@ -229,8 +226,7 @@ describe('User API', function () {
describe('As Author', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -11,7 +11,7 @@ describe('Authors Content API', function () {
before(function () {
return testUtils.startGhost()
.then(function (_ghostServer) {
.then(function () {
request = supertest.agent(config.get('url'));
})
.then(function () {

View File

@ -18,8 +18,6 @@ const settingsCache = require('../../../core/shared/settings-cache');
let request;
describe('Dynamic Routing', function () {
let ghostServer;
function doEnd(done) {
return function (err, res) {
if (err) {
@ -47,8 +45,7 @@ describe('Dynamic Routing', function () {
});
return testUtils.startGhost()
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -290,8 +287,7 @@ describe('Dynamic Routing', function () {
configUtils.set('admin:redirects', false);
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -300,8 +296,7 @@ describe('Dynamic Routing', function () {
configUtils.restore();
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -486,8 +481,7 @@ describe('Dynamic Routing', function () {
configUtils.set('admin:redirects', false);
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -496,8 +490,7 @@ describe('Dynamic Routing', function () {
configUtils.restore();
return testUtils.startGhost({forceStart: true})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('url'));
});
});
@ -616,7 +609,7 @@ describe('Dynamic Routing', function () {
after(testUtils.teardownDb);
after(function () {
return ghostServer.stop();
return testUtils.stopGhost();
});
it('confirm current routing pattern', function (done) {

View File

@ -54,15 +54,12 @@ describe('Frontend Routing:Redirects', function () {
redirectsFileExts.forEach((ext) => {
describe(`Redirects (use redirects${ext} from test/utils/fixtures/data)`, function () {
let ghostServer;
before(function () {
configUtils.set('url', 'http://localhost:2370/');
urlUtils.stubUrlUtilsFromConfig();
return testUtils.startGhost({forceStart: true, redirectsFileExt: ext})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
});
});
@ -340,15 +337,12 @@ describe('Frontend Routing:Redirects', function () {
});
describe(`Subdirectory redirects (use redirects${ext} from test/utils/fixtures/data)`, function () {
var ghostServer;
before(function () {
configUtils.set('url', 'http://localhost:2370/blog/');
urlUtils.stubUrlUtilsFromConfig();
return testUtils.startGhost({forceStart: true, subdir: true, redirectsFileExt: ext})
.then(function (_ghostServer) {
ghostServer = _ghostServer;
.then(function () {
request = supertest.agent(config.get('server:host') + ':' + config.get('server:port'));
});
});