From a867503af63bcf24f935ae32fc8d88fe5e7a786a Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 23 Oct 2023 11:30:08 -0400 Subject: [PATCH] test: add spec for `child-process-gone` event for utility process (#40281) --- docs/api/utility-process.md | 2 +- spec/api-utility-process-spec.ts | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/api/utility-process.md b/docs/api/utility-process.md index 8880f3d693f6..f5e2542a21a4 100644 --- a/docs/api/utility-process.md +++ b/docs/api/utility-process.md @@ -29,7 +29,7 @@ Process: [Main](../glossary.md#main-process)
* `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 diff --git a/spec/api-utility-process-spec.ts b/spec/api-utility-process-spec.ts index f8b1280a3166..b87920d35415 100644 --- a/spec/api-utility-process-spec.ts +++ b/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'; import { ifit } from './lib/spec-helpers'; import { closeWindow } from './lib/window-helpers'; import { once } from 'node:events'; @@ -93,6 +93,26 @@ describe('utilityProcess module', () => { }); }); + 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'), [], {