mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
ba8f082d41
no issue This change waits for domain events and jobs before continuing with the next test. This prevents issues where background tasks in tests are executed when the next test is running and the configurations have changed, causing random error logs and test failures. It also includes a change in Stripe mocking in one E2E test to make use of the new StripeMocker instead of custom mocking in each test (also to reduce error logs).
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
process.env.NODE_ENV = process.env.NODE_ENV || 'testing';
|
|
process.env.WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || 'TEST_STRIPE_WEBHOOK_SECRET';
|
|
|
|
require('../../core/server/overrides');
|
|
|
|
const {mochaHooks} = require('@tryghost/express-test').snapshot;
|
|
exports.mochaHooks = mochaHooks;
|
|
|
|
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();
|
|
};
|
|
|
|
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');
|
|
|
|
await domainEvents.allSettled();
|
|
await mentionsJobsService.allSettled();
|
|
await jobsService.allSettled();
|
|
|
|
// Last time for events emitted during jobs
|
|
await domainEvents.allSettled();
|
|
|
|
if (originalAfterEach) {
|
|
await originalAfterEach();
|
|
}
|
|
};
|