diff --git a/test/regression/api/canary/admin/site.test.js b/test/regression/api/canary/admin/site.test.js index 31bec20e58..008cd4be94 100644 --- a/test/regression/api/canary/admin/site.test.js +++ b/test/regression/api/canary/admin/site.test.js @@ -1,4 +1,5 @@ const should = require('should'); +const framework = require('../../../../utils/e2e-framework'); const testUtils = require('../../../../utils'); const localUtils = require('./utils'); const config = require('../../../../../core/shared/config'); @@ -7,7 +8,7 @@ describe('Config API', function () { let request; before(async function () { - request = await localUtils.getAuthenticatedAgent(); + request = await framework.getAgent(); }); it('can retrieve config and all expected properties', async function () { diff --git a/test/utils/e2e-framework.js b/test/utils/e2e-framework.js new file mode 100644 index 0000000000..4d1fdb79bc --- /dev/null +++ b/test/utils/e2e-framework.js @@ -0,0 +1,36 @@ +// Set of common function that should be main building blocks for e2e tests. +// The e2e tests usually consist of following building blocks: +// - request agent +// - state builder +// - output state checker +// +// The request agetnt is responsible for making HTTP-like requests to an application (express app in case of Ghost). +// Note there's no actual need to make an HTTP request to an actual server, bypassing HTTP and hooking into the application +// directly is enough and reduces dependence on blocking a port (allows to run tests in parallel). +// +// The state builder is responsible for building the state of the application. Usually it's done by using pre-defined fixtures. +// Can include building a DB state, file system state (themes, config files), building configuration state (config files) etc. +// +// The output state checker is responsible for checking the response from the app after performing a request. + +const supertest = require('supertest'); + +const boot = require('../../core/boot'); + +const startGhost = () => { + const defaults = { + backend: true, + frontend: false, + server: false + }; + + return boot(defaults); +}; + +const getAgent = async () => { + const app = await startGhost(); + + return supertest.agent(app); +}; + +module.exports.getAgent = getAgent;