From d0dfac438d8e143a55b8b3d972fac60d3fec926f Mon Sep 17 00:00:00 2001 From: Naz Date: Fri, 19 Nov 2021 15:51:19 +0400 Subject: [PATCH] Changed /^testing/ regexp use to startsWith method no issue - `startsWith` method is way easier to read and understand. also, **probably** has better performance comparing to building up a regexp and then matching --- core/boot.js | 2 +- core/server/services/email-analytics/jobs/index.js | 2 +- core/server/services/url/index.js | 2 +- core/shared/labs.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/boot.js b/core/boot.js index fcd341ebb8..0ba9675290 100644 --- a/core/boot.js +++ b/core/boot.js @@ -276,7 +276,7 @@ async function initBackgroundServices({config}) { themeService.loadInactiveThemes(); // we don't want to kick off background services that will interfere with tests - if (process.env.NODE_ENV.match(/^testing/)) { + if (process.env.NODE_ENV.startsWith('test')) { return; } diff --git a/core/server/services/email-analytics/jobs/index.js b/core/server/services/email-analytics/jobs/index.js index 1b1cecbc61..79705097a3 100644 --- a/core/server/services/email-analytics/jobs/index.js +++ b/core/server/services/email-analytics/jobs/index.js @@ -12,7 +12,7 @@ module.exports = { !hasScheduled && config.get('emailAnalytics') && config.get('backgroundJobs:emailAnalytics') && - !process.env.NODE_ENV.match(/^testing/) + !process.env.NODE_ENV.startsWith('test') ) { // Don't register email analytics job if we have no emails, // processor usage from many sites spinning up threads can be high. diff --git a/core/server/services/url/index.js b/core/server/services/url/index.js index 5abff73f18..7fefa323a6 100644 --- a/core/server/services/url/index.js +++ b/core/server/services/url/index.js @@ -10,7 +10,7 @@ let storagePath = config.getContentPath('data'); // TODO: remove this hack in favor of loading from the content path when it's possible to do so // by mocking content folders in pre-boot phase -if (process.env.NODE_ENV.match(/^testing/)){ +if (process.env.NODE_ENV.startsWith('test')){ storagePath = config.get('paths').urlCache; // NOTE: prevents test suites from overwriting cache fixtures. diff --git a/core/shared/labs.js b/core/shared/labs.js index 92047770a5..52ed759284 100644 --- a/core/shared/labs.js +++ b/core/shared/labs.js @@ -50,7 +50,7 @@ module.exports.getAll = () => { const labs = _.cloneDeep(settingsCache.get('labs')) || {}; ALPHA_FEATURES.forEach((alphaKey) => { - if (labs[alphaKey] && !(config.get('enableDeveloperExperiments') || process.env.NODE_ENV.match(/^testing/))) { + if (labs[alphaKey] && !(config.get('enableDeveloperExperiments') || process.env.NODE_ENV.startsWith('test'))) { delete labs[alphaKey]; } });