{"action":"closed","issue":{"url":"https://api.github.com/repos/shellscape/mocha-chrome/issues/24","repository_url":"https://api.github.com/repos/shellscape/mocha-chrome","labels_url":"https://api.github.com/repos/shellscape/mocha-chrome/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/shellscape/mocha-chrome/issues/24/comments","events_url":"https://api.github.com/repos/shellscape/mocha-chrome/issues/24/events","html_url":"https://github.com/shellscape/mocha-chrome/issues/24","id":320901673,"number":24,"title":"test failure results in orphaned chrome.exe processes","user":{"login":"Spongman","id":1088194,"avatar_url":"https://avatars2.githubusercontent.com/u/1088194?v=4","gravatar_id":"","url":"https://api.github.com/users/Spongman","html_url":"https://github.com/Spongman","followers_url":"https://api.github.com/users/Spongman/followers","following_url":"https://api.github.com/users/Spongman/following{/other_user}","gists_url":"https://api.github.com/users/Spongman/gists{/gist_id}","starred_url":"https://api.github.com/users/Spongman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Spongman/subscriptions","organizations_url":"https://api.github.com/users/Spongman/orgs","repos_url":"https://api.github.com/users/Spongman/repos","events_url":"https://api.github.com/users/Spongman/events{/privacy}","received_events_url":"https://api.github.com/users/Spongman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-05-07T18:12:25Z","updated_at":"2018-05-10T23:15:56Z","closed_at":"2018-05-10T23:15:56Z","author_association":"NONE","body":"> Please note that this template is not optional. If you proceed with this form,\r\nplease fill out **_all_** fields, or your issue may be closed as \"invalid.\"\r\nPlease do not delete this template. Please do remove this header to acknowledge this message.\r\n\r\n* Operating System: win64\r\n* Node Version: 10.0.0\r\n* NPM Version: 5.6.0\r\n* mocha Version: 3.5.3\r\n* mocha-chrome Version: 0.2.1\r\n\r\n- [x] This is a **bug**\r\n\r\n### Code\r\n\r\n### Expected Behavior\r\nchrome processes are killed after test failure\r\n\r\n### Actual Behavior\r\nchrome processes are left running\r\n\r\n### For Bugs; How can we reproduce the behavior?\r\n\r\ni'm pretty sure the issue is due to the fact that `exit()` is async.\r\n\r\nif you add `console.log` calls and a `try`/`catch` to `exit`, like this:\r\n```javascript\r\n  async exit (code) {\r\n    console.log('exit ' + code);\r\n    this.closed = true;\r\n    try {\r\n      console.log('close');\r\n      await this.client.close();\r\n      console.log('closed');\r\n    }\r\n    finally {\r\n      console.log('kill');\r\n      await this.instance.kill();\r\n      console.log('killed');\r\n    }\r\n\r\n    this.bus.emit('exit', 1);\r\n  }\r\n}\r\n```\r\n\r\nthen it _only_ prints `close` - the process exits before the async `close()` call returns.\r\n\r\nthis is because `exit` isn't `await`ed:\r\n\r\n```javascript\r\n    bus.on('ended', stats => {\r\n      this.ended = true;\r\n      this.exit(stats.failures);\r\n    });\r\n```\r\n\r\nhowever, adding an `await` here:\r\n```javascript\r\n    bus.on('ended', async stats => {\r\n      this.ended = true;\r\n      await this.exit(stats.failures);\r\n    });\r\n```\r\n\r\ndoesn't help because `Nanobus` doesn't support chaining async methods.\r\n\r\nthe runner looks like this:\r\n```javascript\r\n  grunt.registerMultiTask('mochaChrome', async function() {\r\n    var done = this.async();\r\n\r\n    try {\r\n      var options = this.data.options;\r\n\r\n      for (var testURL of options.urls) {\r\n        var my_opts = Object.assign({}, options);\r\n        my_opts.urls = undefined;\r\n        my_opts.url = testURL;\r\n        my_opts.chromeFlags = ['--no-sandbox', '--mute-audio'];\r\n        my_opts.logLevel = 'trace';\r\n        var runner = new MochaCrome(my_opts);\r\n        var result = new Promise((resolve, reject) => {\r\n          runner.on('ended', function(stats) {\r\n            if (stats.failures) {\r\n              reject(stats);\r\n            } else {\r\n              resolve(stats);\r\n            }\r\n          });\r\n          runner.on('failure', reject);\r\n        });\r\n\r\n        (async function () {\r\n          await runner.connect();\r\n          await runner.run();\r\n        })();\r\n\r\n        await result;\r\n      }\r\n\r\n      done();\r\n    }\r\n    catch (e) {\r\n      if (e instanceof Error) {\r\n        done(e);\r\n      } else {\r\n        done(new Error(e));\r\n      }\r\n    }\r\n  })\r\n```"}}
{"actor":{"display_login":"Spongman"}}