Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add spec for --require filtering in NODE_OPTIONS #29508

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions shell/common/node_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ void stop_and_close_uv_loop(uv_loop_t* loop) {
bool g_is_initialized = false;

bool IsPackagedApp() {
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 =
Expand Down
23 changes: 23 additions & 0 deletions spec-main/node-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/module/fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(1);