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 child-process-gone event for utility process #40281

Merged
merged 1 commit into from Oct 23, 2023
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
2 changes: 1 addition & 1 deletion docs/api/utility-process.md
Expand Up @@ -29,7 +29,7 @@ Process: [Main](../glossary.md#main-process)<br />
* `inherit`: equivalent to \['ignore', 'inherit', 'inherit']
* `serviceName` string (optional) - Name of the process that will appear in `name` property of
[`child-process-gone` event of `app`](app.md#event-child-process-gone).
Default is `node.mojom.NodeService`.
Default is `Node Utility Process`.
* `allowLoadingUnsignedLibraries` boolean (optional) _macOS_ - With this flag, the utility process will be
launched via the `Electron Helper (Plugin).app` helper executable on macOS, which can be
codesigned with `com.apple.security.cs.disable-library-validation` and
Expand Down
22 changes: 21 additions & 1 deletion spec/api-utility-process-spec.ts
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import * as childProcess from 'node:child_process';
import * as path from 'node:path';
import { BrowserWindow, MessageChannelMain, utilityProcess } from 'electron/main';
import { BrowserWindow, MessageChannelMain, utilityProcess, app } from 'electron/main';

Check failure on line 4 in spec/api-utility-process-spec.ts

View check run for this annotation

trop / Backportable? - 25-x-y

spec/api-utility-process-spec.ts#L2-L4

Patch Conflict
Raw output
++<<<<<<< HEAD
 +import * as childProcess from 'child_process';
 +import * as path from 'path';
 +import { BrowserWindow, MessageChannelMain, utilityProcess } from 'electron/main';
++=======
+ import * as childProcess from 'node:child_process';
+ import * as path from 'node:path';
+ import { BrowserWindow, MessageChannelMain, utilityProcess, app } from 'electron/main';
++>>>>>>> test: add spec for `child-process-gone` event for utility process

Check failure on line 4 in spec/api-utility-process-spec.ts

View check run for this annotation

trop / Backportable? - 26-x-y

spec/api-utility-process-spec.ts#L2-L4

Patch Conflict
Raw output
++<<<<<<< HEAD
 +import * as childProcess from 'child_process';
 +import * as path from 'path';
 +import { BrowserWindow, MessageChannelMain, utilityProcess } from 'electron/main';
++=======
+ import * as childProcess from 'node:child_process';
+ import * as path from 'node:path';
+ import { BrowserWindow, MessageChannelMain, utilityProcess, app } from 'electron/main';
++>>>>>>> test: add spec for `child-process-gone` event for utility process
import { ifit } from './lib/spec-helpers';
import { closeWindow } from './lib/window-helpers';
import { once } from 'node:events';
Expand Down Expand Up @@ -93,6 +93,26 @@
});
});

describe('app \'child-process-gone\' event', () => {
it('with default serviceName', async () => {
utilityProcess.fork(path.join(fixturesPath, 'crash.js'));
const [, details] = await once(app, 'child-process-gone') as [any, Electron.Details];
expect(details.type).to.equal('Utility');
expect(details.serviceName).to.equal('node.mojom.NodeService');
expect(details.name).to.equal('Node Utility Process');
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
});

it('with custom serviceName', async () => {
utilityProcess.fork(path.join(fixturesPath, 'crash.js'), [], { serviceName: 'Hello World!' });
const [, details] = await once(app, 'child-process-gone') as [any, Electron.Details];
expect(details.type).to.equal('Utility');
expect(details.serviceName).to.equal('node.mojom.NodeService');
expect(details.name).to.equal('Hello World!');
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
});
});

describe('kill() API', () => {
it('terminates the child process gracefully', async () => {
const child = utilityProcess.fork(path.join(fixturesPath, 'endless.js'), [], {
Expand Down