test: add spec for app.getAppMetrics() for utility process (#40306)

This commit is contained in:
Milan Burda 2023-10-24 09:25:30 -04:00 committed by GitHub
parent a867503af6
commit 54ff706b71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import { ifit } from './lib/spec-helpers';
import { closeWindow } from './lib/window-helpers'; import { closeWindow } from './lib/window-helpers';
import { once } from 'node:events'; import { once } from 'node:events';
import { pathToFileURL } from 'node:url'; import { pathToFileURL } from 'node:url';
import { setImmediate } from 'node:timers/promises';
const fixturesPath = path.resolve(__dirname, 'fixtures', 'api', 'utility-process'); const fixturesPath = path.resolve(__dirname, 'fixtures', 'api', 'utility-process');
const isWindowsOnArm = process.platform === 'win32' && process.arch === 'arm64'; const isWindowsOnArm = process.platform === 'win32' && process.arch === 'arm64';
@ -113,6 +114,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', () => { describe('kill() API', () => {
it('terminates the child process gracefully', async () => { it('terminates the child process gracefully', async () => {
const child = utilityProcess.fork(path.join(fixturesPath, 'endless.js'), [], { const child = utilityProcess.fork(path.join(fixturesPath, 'endless.js'), [], {