From 14d03d7b788f3ce0aba03e35bceda5962b7e0836 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2020 19:07:26 -0800 Subject: [PATCH] test: support for adding extra module paths (#26545) Co-authored-by: David Sanders --- spec-main/index.js | 7 +++++++ spec/static/index.html | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/spec-main/index.js b/spec-main/index.js index f4f9c0f0fd3d3..622cd927dab66 100644 --- a/spec-main/index.js +++ b/spec-main/index.js @@ -4,6 +4,13 @@ const v8 = require('v8'); Module.globalPaths.push(path.resolve(__dirname, '../spec/node_modules')); +// Extra module paths which can be used to load Mocha reporters +if (process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS) { + for (const modulePath of process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS.split(':')) { + Module.globalPaths.push(modulePath); + } +} + // We want to terminate on errors, not throw up a dialog process.on('uncaughtException', (err) => { console.error('Unhandled exception in main spec runner:', err); diff --git a/spec/static/index.html b/spec/static/index.html index f50197be966ee..9497bbcf8b20e 100644 --- a/spec/static/index.html +++ b/spec/static/index.html @@ -5,10 +5,18 @@ // Deprecated APIs are still supported and should be tested. process.throwDeprecation = false + const Module = require('module'); const path = require('path') const electron = require('electron') const { ipcRenderer } = electron + // Extra module paths which can be used to load Mocha reporters + if (process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS) { + for (const modulePath of process.env.ELECTRON_TEST_EXTRA_MODULE_PATHS.split(':')) { + Module.globalPaths.push(modulePath); + } + } + // Set up chai-as-promised here first to avoid conflicts // It must be loaded first or really strange things happen inside // chai that cause test failures