Browse Source

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

Milan Burda 1 year ago
parent
commit
54ff706b71
1 changed files with 31 additions and 0 deletions
  1. 31 0
      spec/api-utility-process-spec.ts

+ 31 - 0
spec/api-utility-process-spec.ts

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