test: fix some failing and disabled node specs (#19518)

* test: fix some failing and disabled node specs

These tests were failing due to mismatched stacktraces as a result of
our Module._load hook.  This fixes those by adding a flag to optionally
not hook those calls and instead do the asar override eagily.

* ELECTRON_EAGER_ASAR_HOOK => ELECTRON_EAGER_ASAR_HOOK_FOR_TESTING

* test: parallel/test-zlib-unused-weak consistently fails

Co-authored-by: Cheng Zhao <zcbenz@github.com>
This commit is contained in:
Samuel Attard 2020-01-14 23:07:03 -08:00 committed by Cheng Zhao
parent 49262b604d
commit b31c02ef31
3 changed files with 34 additions and 41 deletions

View file

@ -711,31 +711,42 @@
overrideAPISync(Module._extensions, '.node', 1)
overrideAPISync(fs, 'openSync')
// Lazily override the child_process APIs only when child_process is fetched the first time
const originalModuleLoad = Module._load
Module._load = (request, ...args) => {
const loadResult = originalModuleLoad(request, ...args)
if (request === 'child_process') {
if (!v8Util.getHiddenValue(loadResult, 'asar-ready')) {
v8Util.setHiddenValue(loadResult, 'asar-ready', true)
// Just to make it obvious what we are dealing with here
const childProcess = loadResult
const overrideChildProcess = (childProcess) => {
// Executing a command string containing a path to an asar archive
// confuses `childProcess.execFile`, which is internally called by
// `childProcess.{exec,execSync}`, causing Electron to consider the full
// command as a single path to an archive.
const { exec, execSync } = childProcess
childProcess.exec = invokeWithNoAsar(exec)
childProcess.exec[util.promisify.custom] = invokeWithNoAsar(exec[util.promisify.custom])
childProcess.execSync = invokeWithNoAsar(execSync)
// Executing a command string containing a path to an asar
// archive confuses `childProcess.execFile`, which is internally
// called by `childProcess.{exec,execSync}`, causing
// Electron to consider the full command as a single path
// to an archive.
const { exec, execSync } = childProcess
childProcess.exec = invokeWithNoAsar(exec)
childProcess.exec[util.promisify.custom] = invokeWithNoAsar(exec[util.promisify.custom])
childProcess.execSync = invokeWithNoAsar(execSync)
overrideAPI(childProcess, 'execFile')
overrideAPISync(childProcess, 'execFileSync')
}
overrideAPI(childProcess, 'execFile')
overrideAPISync(childProcess, 'execFileSync')
// Lazily override the child_process APIs only when child_process is
// fetched the first time. We will eagerly override the child_process APIs
// when this env var is set so that stack traces generated inside node unit
// tests will match. This env var will only slow things down in users apps
// and should not be used.
if (process.env.ELECTRON_EAGER_ASAR_HOOK_FOR_TESTING) {
overrideChildProcess(require('child_process'))
} else {
const originalModuleLoad = Module._load
Module._load = (request, ...args) => {
const loadResult = originalModuleLoad(request, ...args)
if (request === 'child_process') {
if (!v8Util.getHiddenValue(loadResult, 'asar-ready')) {
v8Util.setHiddenValue(loadResult, 'asar-ready', true)
// Just to make it obvious what we are dealing with here
const childProcess = loadResult
overrideChildProcess(childProcess)
}
}
return loadResult
}
return loadResult
}
}
})()