test: add spec for --require filtering in NODE_OPTIONS (#29501)

This commit is contained in:
Milan Burda 2021-06-03 07:46:44 +02:00 committed by GitHub
parent d8d6e2ebc0
commit 8040cb788f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -938,6 +938,10 @@ void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
// static
bool App::IsPackaged() {
auto env = base::Environment::Create();
if (env->HasVar("ELECTRON_FORCE_IS_PACKAGED"))
return true;
base::FilePath exe_path;
base::PathService::Get(base::FILE_EXE, &exe_path);
base::FilePath::StringType base_name =

View file

@ -132,6 +132,29 @@ describe('node feature', () => {
child.stderr.on('data', listener);
child.stdout.on('data', listener);
});
it('does allow --require in non-packaged apps', async () => {
const appPath = path.join(fixtures, 'module', 'noop.js');
const env = Object.assign({}, process.env, {
NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}`
});
// App should exit with code 1.
const child = childProcess.spawn(process.execPath, [appPath], { env });
const [code] = await emittedOnce(child, 'exit');
expect(code).to.equal(1);
});
it('does not allow --require in packaged apps', async () => {
const appPath = path.join(fixtures, 'module', 'noop.js');
const env = Object.assign({}, process.env, {
ELECTRON_FORCE_IS_PACKAGED: 'true',
NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}`
});
// App should exit with code 0.
const child = childProcess.spawn(process.execPath, [appPath], { env });
const [code] = await emittedOnce(child, 'exit');
expect(code).to.equal(0);
});
});
ifdescribe(features.isRunAsNodeEnabled())('Node.js cli flags', () => {

1
spec/fixtures/module/fail.js vendored Normal file
View file

@ -0,0 +1 @@
process.exit(1);