2021-07-05 22:02:22 +03:00
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'testing';
|
2022-02-17 16:26:16 +03:00
|
|
|
process.env.WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || 'TEST_STRIPE_WEBHOOK_SECRET';
|
2021-07-05 22:02:22 +03:00
|
|
|
|
|
|
|
require('../../core/server/overrides');
|
2022-02-08 17:33:19 +03:00
|
|
|
|
2022-02-22 06:33:42 +03:00
|
|
|
const {mochaHooks} = require('@tryghost/express-test').snapshot;
|
2022-03-17 00:10:49 +03:00
|
|
|
exports.mochaHooks = mochaHooks;
|
2023-03-07 15:20:28 +03:00
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
const chalk = require('chalk');
|
2023-03-07 15:20:28 +03:00
|
|
|
const mockManager = require('./e2e-framework-mock-manager');
|
|
|
|
|
|
|
|
const originalBeforeAll = mochaHooks.beforeAll;
|
|
|
|
mochaHooks.beforeAll = async function () {
|
|
|
|
if (originalBeforeAll) {
|
|
|
|
await originalBeforeAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable network in tests to prevent any accidental requests
|
|
|
|
mockManager.disableNetwork();
|
|
|
|
};
|
2023-04-06 10:05:16 +03:00
|
|
|
|
|
|
|
const originalAfterEach = mochaHooks.afterEach;
|
|
|
|
mochaHooks.afterEach = async function () {
|
|
|
|
const domainEvents = require('@tryghost/domain-events');
|
|
|
|
const mentionsJobsService = require('../../core/server/services/mentions-jobs');
|
|
|
|
const jobsService = require('../../core/server/services/jobs');
|
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
let timeout = setTimeout(() => {
|
|
|
|
// eslint-disable-next-line no-console
|
|
|
|
console.error(chalk.yellow('\n[SLOW TEST] It takes longer than 2s to wait for all jobs and events to settle in the afterEach hook\n'));
|
|
|
|
}, 2000);
|
|
|
|
|
2023-04-06 10:05:16 +03:00
|
|
|
await domainEvents.allSettled();
|
|
|
|
await mentionsJobsService.allSettled();
|
|
|
|
await jobsService.allSettled();
|
|
|
|
|
|
|
|
// Last time for events emitted during jobs
|
|
|
|
await domainEvents.allSettled();
|
|
|
|
|
2023-09-21 17:17:05 +03:00
|
|
|
clearTimeout(timeout);
|
|
|
|
|
2023-04-06 10:05:16 +03:00
|
|
|
if (originalAfterEach) {
|
|
|
|
await originalAfterEach();
|
|
|
|
}
|
|
|
|
};
|