mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Improved webhooks e2e test bootstrap speed
refs https://github.com/TryGhost/Toolbox/issues/214 - Calling `getMembersAPIAgent` and `getAdminAPIAgent` separately was booting Ghost twice, which caused a significant performance degradation. - Additionally, having two calls was slightly ugly and having once utility function that delivers multiple agents at once feels like more readable syntax
This commit is contained in:
parent
9b4d61ef2e
commit
884f837bd7
2 changed files with 42 additions and 3 deletions
|
@ -14,8 +14,11 @@ describe('Members API', function () {
|
||||||
// And it's initialised at boot - so mocking it before
|
// And it's initialised at boot - so mocking it before
|
||||||
// Probably wanna replace this with a settinfs fixture mock or smth??
|
// Probably wanna replace this with a settinfs fixture mock or smth??
|
||||||
mockManager.setupStripe();
|
mockManager.setupStripe();
|
||||||
membersAgent = await agentProvider.getMembersAPIAgent();
|
|
||||||
adminAgent = await agentProvider.getAdminAPIAgent();
|
const agents = await agentProvider.getAgentsForMembers();
|
||||||
|
membersAgent = agents.membersAgent;
|
||||||
|
adminAgent = agents.adminAgent;
|
||||||
|
|
||||||
await fixtureManager.init('members');
|
await fixtureManager.init('members');
|
||||||
await adminAgent.loginAsOwner();
|
await adminAgent.loginAsOwner();
|
||||||
});
|
});
|
||||||
|
|
|
@ -196,11 +196,47 @@ const getMembersAPIAgent = async () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @returns {Promise<{adminAgent: TestAgent, membersAgent: TestAgent}>} agent
|
||||||
|
*/
|
||||||
|
const getAgentsForMembers = async () => {
|
||||||
|
let membersAgent;
|
||||||
|
let adminAgent;
|
||||||
|
|
||||||
|
const bootOptions = {
|
||||||
|
frontend: true
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const app = await startGhost(bootOptions);
|
||||||
|
const originURL = configUtils.config.get('url');
|
||||||
|
|
||||||
|
membersAgent = new TestAgent(app, {
|
||||||
|
apiURL: '/members/',
|
||||||
|
originURL
|
||||||
|
});
|
||||||
|
adminAgent = new TestAgent(app, {
|
||||||
|
apiURL: '/ghost/api/canary/admin/',
|
||||||
|
originURL
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
error.message = `Unable to create test agent. ${error.message}`;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
adminAgent,
|
||||||
|
membersAgent
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
// request agent
|
// request agent
|
||||||
agentProvider: {
|
agentProvider: {
|
||||||
getAdminAPIAgent,
|
getAdminAPIAgent,
|
||||||
getMembersAPIAgent
|
getMembersAPIAgent,
|
||||||
|
getAgentsForMembers
|
||||||
},
|
},
|
||||||
|
|
||||||
// Mocks and Stubs
|
// Mocks and Stubs
|
||||||
|
|
Loading…
Add table
Reference in a new issue