*Hi everyone,*
We've been experiencing issues with tests execution of our electron
application, and I'd like to share what our research led to, in case a
similar problem appears in the future.
The Problem:
In our environment running `npm test` [
https://github.com/GPII/gpii-app/blob/master/package.json#L22] resulted in
all tests running and executing successfully. But strangely the same
electron test process wasn't finishing although there is a `process.exit`
call (which is reached) right after the tests conclusion is logged [
https://github.com/fluid-project/node-jqunit/blob/master/lib/jqUnit-node.js#L192].
So, why doesn't the process finish after a call to the `process.exit`
method?
The Cause:
First of all, there is one interesting thing about the `process.exit`
method inside an electron process - [
https://github.com/electron/electron/blob/b5dec9990eb34a711c57a4f639b2c4c8de866d5f/lib/browser/init.js#L100],
it is mapped to `app.exit`. This fact, combined with the linked
implementation in the `node-jqunit` module (that uses `process.exit`) and
this issue - [https://github.com/electron/electron/issues/8915], seem to
result in the described behaviour. Inside our test process (`npm test`)
more than 6 such electron window objects were created and not destroyed,
which caused the buggy `exit` behaviour to appear.
Our Solution:
As I already mentioned, in our environment we created multiple
electron objects (such s Tray and BrowserWindows) without destroying them
explicitly. We didn't notice a problem at first as the number of created
objects was small enough and, surprisingly, the final call to `app.quit` [
https://github.com/electron/electron/blob/master/docs/api/app.md#appquit]
seemed to be enough for everything to be closed correctly (it doesn't share
the problematic behaviour of `app.exit`). We enabled destruction of the
electron objects once their corresponding components' destruction has taken
place. This seemed to be enough for the electron application to exit
properly.
General Solution:
It appears that once we update our electron dependency to a newer
version, the problem will be fixed. For reference, this is the first
version that includes the fix
https://github.com/electron/electron/releases/tag/v1.6.7 for this issue.
(Not recommended) A workaround would be including a code snippet somewhere
inside the electron process:
`process.exit = require("electron").app.quit`
Calling the `app.quit` seems to work properly unlike the `app.exit`. In my
opinion we should manually take care of destruction of electron objects for
now in order to avoid the problematic number of processes being created.
And to highlight it again - this problem affects only applications that use
the `app.exit` [
https://github.com/electron/electron/blob/master/docs/api/app.md#appexitexitcode]
method for exiting an electron process.
*Best,*
*The Astea Team*
--
*The information in this e-mail and any accompanying files is intended only
for the recipients named above. This message may contain CONFIDENTIAL
INFORMATION THAT IS LEGALLY PRIVILEGED. If you are not an intended
recipient, you may not download, copy, disseminate, distribute or use in
any way the information in this e-mail. Any of these actions can be a
criminal offense. If you have received this e-mail in error, please notify
Astea Solutions AD immediately by reply e-mail, and delete this e-mail and
any copies of it.*
_______________________________________________
Architecture mailing list
[email protected]
https://lists.gpii.net/mailman/listinfo/architecture