Skip to content

Commit

Permalink
test: add spec for app.getAppMetrics() for utility process (#40317)
Browse files Browse the repository at this point in the history
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
  • Loading branch information
miniak and trop[bot] committed Oct 24, 2023
1 parent 301f3da commit 7ac2e49
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/api-utility-process-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BrowserWindow, MessageChannelMain, utilityProcess, app } from 'electron
import { ifit } from './lib/spec-helpers';
import { closeWindow } from './lib/window-helpers';
import { once } from 'node:events';
import { setImmediate } from 'node:timers/promises';

const fixturesPath = path.resolve(__dirname, 'fixtures', 'api', 'utility-process');
const isWindowsOnArm = process.platform === 'win32' && process.arch === 'arm64';
Expand Down Expand Up @@ -106,6 +107,36 @@ describe('utilityProcess module', () => {
});
});

describe('app.getAppMetrics()', () => {
it('with default serviceName', async () => {
const child = utilityProcess.fork(path.join(fixturesPath, 'endless.js'));
await once(child, 'spawn');
expect(child.pid).to.not.be.null();

await setImmediate();

const details = app.getAppMetrics().find(item => item.pid === child.pid)!;
expect(details).to.be.an('object');
expect(details.type).to.equal('Utility');
expect(details.serviceName).to.to.equal('node.mojom.NodeService');
expect(details.name).to.equal('Node Utility Process');
});

it('with custom serviceName', async () => {
const child = utilityProcess.fork(path.join(fixturesPath, 'endless.js'), [], { serviceName: 'Hello World!' });
await once(child, 'spawn');
expect(child.pid).to.not.be.null();

await setImmediate();

const details = app.getAppMetrics().find(item => item.pid === child.pid)!;
expect(details).to.be.an('object');
expect(details.type).to.equal('Utility');
expect(details.serviceName).to.to.equal('node.mojom.NodeService');
expect(details.name).to.equal('Hello World!');
});
});

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

0 comments on commit 7ac2e49

Please sign in to comment.