Fixed broken "mock express" style e2e tests

- done a fastest-possible overhaul on this style of tests to try to get them to work independently again

This is a pattern that was introduced a while ago to try to speed up our e2e tests and I'm not sure if it's staying or going
It uses a minimal frontend-only version of the boot process and a custom-built express testing tool
However it's really old and out of date because of the boot refactor and several changes since
This highlights the key problem with it - it doesn't rely on any of our "core" boot process, it makes it up, and therefore how reliable are these tests?
Ideally we need to get these tests working with the real boot process in some capacity
We would then need to make sure we have all the tests in e2e-frontend written in this style
This commit is contained in:
Hannah Wolfe 2021-10-20 10:10:50 +01:00
parent c273727b5f
commit 2ff6fdfab8
No known key found for this signature in database
GPG Key ID: 9F8C7532D0A6BA55
5 changed files with 116 additions and 292 deletions

View File

@ -6,10 +6,9 @@ const testUtils = require('../../../utils');
const mockUtils = require('../../../utils/mocks');
const configUtils = require('../../../utils/configUtils');
const urlUtils = require('../../../utils/urlUtils');
const appService = require('../../../../core/frontend/services/apps');
const routeSettingsService = require('../../../../core/server/services/route-settings');
const themeEngine = require('../../../../core/frontend/services/theme-engine');
const siteApp = require('../../../../core/server/web/parent/app');
describe('Integration - Web - Site canary', function () {
let app;
@ -21,19 +20,12 @@ describe('Integration - Web - Site canary', function () {
let postSpy;
describe('default routes.yaml', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {
@ -368,7 +360,7 @@ describe('Integration - Web - Site canary', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/': {templates: ['home']}
@ -395,11 +387,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -497,7 +485,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('no collections', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/something/': {
@ -511,11 +499,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -548,7 +532,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('static permalink route', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -569,11 +553,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -652,7 +632,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('primary author permalink', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -668,11 +648,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -735,7 +711,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('primary tag permalink', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -751,11 +727,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -833,7 +805,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('collection/routes with data key', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/my-page/': {
@ -906,11 +878,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1002,7 +970,7 @@ describe('Integration - Web - Site canary', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1020,11 +988,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1069,7 +1033,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('two templates', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1084,11 +1048,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1121,7 +1081,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('home.hbs priority', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1140,11 +1100,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1195,7 +1151,7 @@ describe('Integration - Web - Site canary', function () {
before(testUtils.teardownDb);
before(testUtils.setup('users:roles', 'posts'));
before(function () {
before(async function () {
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme-channels'});
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
@ -1320,13 +1276,8 @@ describe('Integration - Web - Site canary', function () {
}
});
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
});
beforeEach(function () {
@ -1531,7 +1482,7 @@ describe('Integration - Web - Site canary', function () {
});
describe('extended routes.yaml (5): rss override', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/podcast/rss/': {
@ -1569,11 +1520,7 @@ describe('Integration - Web - Site canary', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {

View File

@ -6,10 +6,9 @@ const testUtils = require('../../../utils');
const mockUtils = require('../../../utils/mocks');
const configUtils = require('../../../utils/configUtils');
const urlUtils = require('../../../utils/urlUtils');
const appService = require('../../../../core/frontend/services/apps');
const routeSettingsService = require('../../../../core/server/services/route-settings');
const themeEngine = require('../../../../core/frontend/services/theme-engine');
const siteApp = require('../../../../core/server/web/parent/app');
describe('Integration - Web - Site v2', function () {
let app;
@ -21,19 +20,12 @@ describe('Integration - Web - Site v2', function () {
let postSpy;
describe('default routes.yaml', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {
@ -56,6 +48,7 @@ describe('Integration - Web - Site v2', function () {
after(function () {
configUtils.restore();
urlUtils.restore();
sinon.restore();
});
describe('behaviour: default cases', function () {
@ -367,7 +360,7 @@ describe('Integration - Web - Site v2', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/': {templates: ['home']}
@ -394,11 +387,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -496,7 +485,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('no collections', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/something/': {templates: ['something']}
@ -508,11 +497,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -545,7 +530,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('static permalink route', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -566,11 +551,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -649,7 +630,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('primary author permalink', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -665,11 +646,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -732,7 +709,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('primary tag permalink', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -748,11 +725,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -830,7 +803,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('collection/routes with data key', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/my-page/': {
@ -903,11 +876,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -999,7 +968,7 @@ describe('Integration - Web - Site v2', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1017,11 +986,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1069,7 +1034,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('two templates', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1084,11 +1049,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1121,7 +1082,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('home.hbs priority', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1140,11 +1101,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1198,7 +1155,7 @@ describe('Integration - Web - Site v2', function () {
before(testUtils.teardownDb);
before(testUtils.setup('users:roles', 'posts'));
before(function () {
before(async function () {
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme-channels'});
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
@ -1323,13 +1280,8 @@ describe('Integration - Web - Site v2', function () {
}
});
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
});
beforeEach(function () {
@ -1534,7 +1486,7 @@ describe('Integration - Web - Site v2', function () {
});
describe('extended routes.yaml (5): rss override', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/podcast/rss/': {
@ -1572,11 +1524,7 @@ describe('Integration - Web - Site v2', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {

View File

@ -6,10 +6,9 @@ const testUtils = require('../../../utils');
const mockUtils = require('../../../utils/mocks');
const configUtils = require('../../../utils/configUtils');
const urlUtils = require('../../../utils/urlUtils');
const appService = require('../../../../core/frontend/services/apps');
const routeSettingsService = require('../../../../core/server/services/route-settings');
const themeEngine = require('../../../../core/frontend/services/theme-engine');
const siteApp = require('../../../../core/server/web/parent/app');
describe('Integration - Web - Site v3', function () {
let app;
@ -21,19 +20,12 @@ describe('Integration - Web - Site v3', function () {
let postSpy;
describe('default routes.yaml', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {
@ -56,6 +48,7 @@ describe('Integration - Web - Site v3', function () {
after(function () {
configUtils.restore();
urlUtils.restore();
sinon.restore();
});
describe('behaviour: default cases', function () {
@ -367,7 +360,7 @@ describe('Integration - Web - Site v3', function () {
describe('extended routes.yaml: collections', function () {
describe('2 collections', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/': {
@ -396,11 +389,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -498,7 +487,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('no collections', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/something/': {templates: ['something']}
@ -510,11 +499,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -547,7 +532,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('static permalink route', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -568,11 +553,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -651,7 +632,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('primary author permalink', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -667,11 +648,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -734,7 +711,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('primary tag permalink', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -749,12 +726,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -832,7 +804,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('collection/routes with data key', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/my-page/': {
@ -905,11 +877,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1001,7 +969,7 @@ describe('Integration - Web - Site v3', function () {
describe('extended routes.yaml: templates', function () {
describe('default template, no template', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1019,11 +987,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1071,7 +1035,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('two templates', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1086,11 +1050,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon);
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1123,7 +1083,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('home.hbs priority', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {},
@ -1142,11 +1102,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {
@ -1200,7 +1156,7 @@ describe('Integration - Web - Site v3', function () {
before(testUtils.teardownDb);
before(testUtils.setup('users:roles', 'posts'));
before(function () {
before(async function () {
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme-channels'});
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
@ -1325,13 +1281,9 @@ describe('Integration - Web - Site v3', function () {
}
});
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
app = await testUtils.integrationTesting.initGhost();
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(10);
});
beforeEach(function () {
@ -1536,7 +1488,7 @@ describe('Integration - Web - Site v3', function () {
});
describe('extended routes.yaml (5): rss override', function () {
before(function () {
before(async function () {
sinon.stub(routeSettingsService, 'loadRouteSettingsSync').returns({
routes: {
'/about/': 'about',
@ -1575,11 +1527,7 @@ describe('Integration - Web - Site v3', function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {theme: 'test-theme'});
return testUtils.integrationTesting.initGhost()
.then(function () {
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
});
app = await testUtils.integrationTesting.initGhost();
});
beforeEach(function () {

View File

@ -25,7 +25,7 @@ describe('Integration - Web - vhosts', function () {
});
describe('no separate admin', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
@ -33,17 +33,10 @@ describe('Integration - Web - vhosts', function () {
configUtils.set('url', 'http://example.com');
configUtils.set('admin:url', null);
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {
@ -144,7 +137,7 @@ describe('Integration - Web - vhosts', function () {
});
describe('separate admin host', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
@ -152,17 +145,10 @@ describe('Integration - Web - vhosts', function () {
configUtils.set('url', 'http://example.com');
configUtils.set('admin:url', 'https://admin.example.com');
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {
@ -305,7 +291,7 @@ describe('Integration - Web - vhosts', function () {
});
describe('separate admin host w/ admin redirects disabled', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
@ -314,17 +300,10 @@ describe('Integration - Web - vhosts', function () {
configUtils.set('admin:url', 'https://admin.example.com');
configUtils.set('admin:redirects', false);
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {
@ -353,7 +332,7 @@ describe('Integration - Web - vhosts', function () {
});
describe('same host separate protocol', function () {
before(function () {
before(async function () {
testUtils.integrationTesting.urlService.resetGenerators();
testUtils.integrationTesting.defaultMocks(sinon, {amp: true});
testUtils.integrationTesting.overrideGhostConfig(configUtils);
@ -361,17 +340,10 @@ describe('Integration - Web - vhosts', function () {
configUtils.set('url', 'http://example.com');
configUtils.set('admin:url', 'https://example.com');
return testUtils.integrationTesting.initGhost()
.then(function () {
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
sinon.stub(themeEngine.getActive(), 'engine').withArgs('ghost-api').returns('v2');
sinon.stub(themeEngine.getActive(), 'config').withArgs('posts_per_page').returns(2);
app = siteApp({start: true});
return testUtils.integrationTesting.urlServiceInitAndWait();
})
.then(() => {
return appService.init();
});
app = await testUtils.integrationTesting.initGhost();
});
before(function () {

View File

@ -8,6 +8,10 @@ const settingsService = require('../../core/server/services/settings');
const settingsCache = require('../../core/shared/settings-cache');
const imageLib = require('../../core/server/lib/image');
const themeService = require('../../core/server/services/themes');
const helperService = require('../../core/frontend/services/helpers');
const appService = require('../../core/frontend/services/apps');
const siteApp = require('../../core/server/web/parent/app');
// Other Test Utilities
const configUtils = require('./configUtils');
@ -39,13 +43,24 @@ module.exports = {
sandbox.stub(imageLib.imageSize, 'getImageSizeFromUrl').resolves();
},
initGhost: () => {
/**
* This is a really rough frontend-only version of Ghost boot
* In order for this test pattern to be really considered the right pattern this needs to be replaced
* With something based on the real boot
* @returns {object} express App
*/
initGhost: async () => {
models.init();
await settingsService.init();
urlServiceUtils.init();
await themeService.init();
await helperService.init();
return settingsService.init()
.then(() => {
return themeService.init();
});
const app = siteApp({start: true});
await appService.init();
await urlServiceUtils.isFinished();
return app;
},
routing: {
@ -54,11 +69,5 @@ module.exports = {
}
},
// Temporary function just for test/regression/site/site_spec.js
async urlServiceInitAndWait() {
urlServiceUtils.init();
return await urlServiceUtils.isFinished();
},
urlService: urlServiceUtils
};