Added resolveMx stub to all E2E tests

refs https://ghost.slack.com/archives/C04TMVA1D7A/p1679391135060629
refs 1b0adcf4ab

The same issue when sending emails from E2E tests, where the tests timeout when resolving mx records for invalid domains.
This commit is contained in:
Simon Backx 2023-03-21 11:23:29 +01:00
parent 9239fe497f
commit a016f53b7e

View File

@ -19,7 +19,8 @@ const originalMailServiceSend = mailService.GhostMailer.prototype.send;
const labs = require('../../core/shared/labs');
const events = require('../../core/server/lib/common/events');
const settingsCache = require('../../core/shared/settings-cache');
const dnsPromises = require('dns').promises;
const dns = require('dns');
const dnsPromises = dns.promises;
const StripeMocker = require('./stripe-mocker');
let fakedLabsFlags = {};
@ -49,6 +50,14 @@ const disableNetwork = () => {
});
}
if (!dns.resolveMx.restore) {
// without this, Node will try and resolve the domain name but local DNS
// resolvers can take a while to timeout, which causes the tests to timeout
// `nodemailer-direct-transport` calls `dns.resolveMx`, so if we stub that
// function and return an empty array, we can avoid any real DNS lookups
sinon.stub(dns, 'resolveMx').yields(null, []);
}
// Allow localhost
// Multiple enableNetConnect with different hosts overwrite each other, so we need to add one and use the allowedNetworkDomains variable
nock.enableNetConnect((host) => {