Ghost/ghost/core/test/utils/overrides.js

46 lines
1.5 KiB
JavaScript
Raw Normal View History

Improved dev tooling (#13118) This commit achieves a few things: - ☑️ No longer having to remember whether a command is yarn something or grunt something - ☑️ Simplification of tools hopefully making them easier to remember and use - ☑️ Complete removal of the need for grunt from our test tooling Several of the tools still use grunt under the hood, but the **entrypoint** should aways be `yarn xxx`. - `grunt main` -> `yarn main` - `grunt dev` -> `yarn dev` - `grunt build` -> `yarn build` - `grunt test:file-or-folder` -> `yarn test file-or-folder` - `grunt test-unit` -> `yarn test:unit` - `grunt test-acceptance` -> `yarn test:acceptance` - `grunt test-regression` -> `yarn test:regression` - `grunt validate` -> removed due to lack of use There is now also `yarn test:all` to run all 3 classes of tests This PR also reorders & restructures the Gruntfile extensively so that: - The remaining useful commands are all at the top of the file - Config and other blah happens after all the useful commands - All release-only config happens in the release task at the very end of the file --- DONE: * Removed all references to npm/bower * Removed all references to lint / deprecated command * Moved debug to yarn dev:debug * Removed all references to travis * Removed broken help task + useless comment * Removed unused knex-migrator and clean:test setup tasks * Added new test commands, removed grunt validate * Moved stubClientFiles to test utility and use in the few tests that need it * Used mocha in yarn directly except grunt test:x * Swapped grunt test for yarn test * extensive cleanup and reshuffling
2021-07-05 22:02:22 +03:00
process.env.NODE_ENV = process.env.NODE_ENV || 'testing';
process.env.WEBHOOK_SECRET = process.env.WEBHOOK_SECRET || 'TEST_STRIPE_WEBHOOK_SECRET';
Improved dev tooling (#13118) This commit achieves a few things: - ☑️ No longer having to remember whether a command is yarn something or grunt something - ☑️ Simplification of tools hopefully making them easier to remember and use - ☑️ Complete removal of the need for grunt from our test tooling Several of the tools still use grunt under the hood, but the **entrypoint** should aways be `yarn xxx`. - `grunt main` -> `yarn main` - `grunt dev` -> `yarn dev` - `grunt build` -> `yarn build` - `grunt test:file-or-folder` -> `yarn test file-or-folder` - `grunt test-unit` -> `yarn test:unit` - `grunt test-acceptance` -> `yarn test:acceptance` - `grunt test-regression` -> `yarn test:regression` - `grunt validate` -> removed due to lack of use There is now also `yarn test:all` to run all 3 classes of tests This PR also reorders & restructures the Gruntfile extensively so that: - The remaining useful commands are all at the top of the file - Config and other blah happens after all the useful commands - All release-only config happens in the release task at the very end of the file --- DONE: * Removed all references to npm/bower * Removed all references to lint / deprecated command * Moved debug to yarn dev:debug * Removed all references to travis * Removed broken help task + useless comment * Removed unused knex-migrator and clean:test setup tasks * Added new test commands, removed grunt validate * Moved stubClientFiles to test utility and use in the few tests that need it * Used mocha in yarn directly except grunt test:x * Swapped grunt test for yarn test * extensive cleanup and reshuffling
2021-07-05 22:02:22 +03:00
require('../../core/server/overrides');
const {mochaHooks} = require('@tryghost/express-test').snapshot;
exports.mochaHooks = mochaHooks;
const chalk = require('chalk');
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');
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);
await domainEvents.allSettled();
await mentionsJobsService.allSettled();
await jobsService.allSettled();
// Last time for events emitted during jobs
await domainEvents.allSettled();
clearTimeout(timeout);
if (originalAfterEach) {
await originalAfterEach();
}
};