|
@@ -144,21 +144,36 @@ describe('utilityProcess module', () => {
|
|
|
});
|
|
|
|
|
|
describe('app \'child-process-gone\' event', () => {
|
|
|
+ const waitForCrash = (name: string) => {
|
|
|
+ return new Promise<Electron.Details>((resolve) => {
|
|
|
+ app.on('child-process-gone', function onCrash (_event, details) {
|
|
|
+ if (details.name === name) {
|
|
|
+ app.off('child-process-gone', onCrash);
|
|
|
+ resolve(details);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
ifit(!isWindows32Bit)('with default serviceName', async () => {
|
|
|
+ const name = 'Node Utility Process';
|
|
|
+ const crashPromise = waitForCrash(name);
|
|
|
utilityProcess.fork(path.join(fixturesPath, 'crash.js'));
|
|
|
- const [, details] = await once(app, 'child-process-gone') as [any, Electron.Details];
|
|
|
+ const details = await crashPromise;
|
|
|
expect(details.type).to.equal('Utility');
|
|
|
expect(details.serviceName).to.equal('node.mojom.NodeService');
|
|
|
- expect(details.name).to.equal('Node Utility Process');
|
|
|
+ expect(details.name).to.equal(name);
|
|
|
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
|
|
|
});
|
|
|
|
|
|
ifit(!isWindows32Bit)('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];
|
|
|
+ const name = crypto.randomUUID();
|
|
|
+ const crashPromise = waitForCrash(name);
|
|
|
+ utilityProcess.fork(path.join(fixturesPath, 'crash.js'), [], { serviceName: name });
|
|
|
+ const details = await crashPromise;
|
|
|
expect(details.type).to.equal('Utility');
|
|
|
expect(details.serviceName).to.equal('node.mojom.NodeService');
|
|
|
- expect(details.name).to.equal('Hello World!');
|
|
|
+ expect(details.name).to.equal(name);
|
|
|
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
|
|
|
});
|
|
|
});
|