{"action":"created","issue":{"url":"https://api.github.com/repos/karma-runner/karma-mocha/issues/55","labels_url":"https://api.github.com/repos/karma-runner/karma-mocha/issues/55/labels{/name}","comments_url":"https://api.github.com/repos/karma-runner/karma-mocha/issues/55/comments","events_url":"https://api.github.com/repos/karma-runner/karma-mocha/issues/55/events","html_url":"https://github.com/karma-runner/karma-mocha/issues/55","id":58482580,"number":55,"title":"Expose Mocha runner on global/window","user":{"login":"brianmhunt","id":135528,"avatar_url":"https://avatars.githubusercontent.com/u/135528?v=3","gravatar_id":"","url":"https://api.github.com/users/brianmhunt","html_url":"https://github.com/brianmhunt","followers_url":"https://api.github.com/users/brianmhunt/followers","following_url":"https://api.github.com/users/brianmhunt/following{/other_user}","gists_url":"https://api.github.com/users/brianmhunt/gists{/gist_id}","starred_url":"https://api.github.com/users/brianmhunt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianmhunt/subscriptions","organizations_url":"https://api.github.com/users/brianmhunt/orgs","repos_url":"https://api.github.com/users/brianmhunt/repos","events_url":"https://api.github.com/users/brianmhunt/events{/privacy}","received_events_url":"https://api.github.com/users/brianmhunt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-22T00:29:23Z","updated_at":"2015-02-22T21:42:03Z","closed_at":null,"body":"At [`adapter.js:132`](https://github.com/karma-runner/karma-mocha/blob/master/src/adapter.js#L132), it would be very helpful for some use cases to expose the runner with e.g.\r\n\r\n```javascript\r\nwindow.__mochaRunner__ = mocha.run();\r\n```\r\n\r\nThis gives users the option to hook for any of the mocha events. For example, I like to use speech synthesis to tell me when a test fails, with something like (pardon the CoffeeScript):\r\n\r\n```coffeescript\r\nwindow.__mochaRunner__.on 'fail', ->\r\n  msg = new SpeechSynthesisUtterance(\"Bad karma. \" + @currentTest.fullTitle())\r\n  speechSynthesis.cancel()\r\n  speechSynthesis.speak(msg)\r\n  $(window).unload(-> speechSynthesis.cancel())\r\n```\r\n\r\nPlease correct me if I am wrong (I am fairly new to Karma), but the alternatives to achieve this simple hook seem to be rather daunting. They seem to be:\r\n\r\n  1. writing another karma reporter,\r\n  2. writing another karma-mocha test reporter (probably forked from this one) with speech synthesis built in or the runner exposed,\r\n  3. some horrendous monkey-patching (e.g. overloading `mocha.run`), or\r\n  4. involving some 3rd party libraries that do the horrendous monkey patching (i.e. a mocha-multi-reporter).\r\n\r\nWhich all seem to be overkill for such a simple hook that is available via the runner. But then, I could very well be missing a rather obvious option here, but having spent a couple hours rooting through karma's source I did not see anything sticking out, and mocha is designed to make this possible by exposing the runner - so that would seem to be the easiest option.\r\n\r\nThanks & cheers. :beers:"},"comment":{"url":"https://api.github.com/repos/karma-runner/karma-mocha/issues/comments/75462734","html_url":"https://github.com/karma-runner/karma-mocha/issues/55#issuecomment-75462734","issue_url":"https://api.github.com/repos/karma-runner/karma-mocha/issues/55","id":75462734,"user":{"login":"maksimr","id":616193,"avatar_url":"https://avatars.githubusercontent.com/u/616193?v=3","gravatar_id":"","url":"https://api.github.com/users/maksimr","html_url":"https://github.com/maksimr","followers_url":"https://api.github.com/users/maksimr/followers","following_url":"https://api.github.com/users/maksimr/following{/other_user}","gists_url":"https://api.github.com/users/maksimr/gists{/gist_id}","starred_url":"https://api.github.com/users/maksimr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maksimr/subscriptions","organizations_url":"https://api.github.com/users/maksimr/orgs","repos_url":"https://api.github.com/users/maksimr/repos","events_url":"https://api.github.com/users/maksimr/events{/privacy}","received_events_url":"https://api.github.com/users/maksimr/received_events","type":"User","site_admin":false},"created_at":"2015-02-22T21:42:03Z","updated_at":"2015-02-22T21:42:03Z","body":"@brianmhunt thanks! Good point"}}