{"action":"created","issue":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/1375","repository_url":"https://api.github.com/repos/tmpvar/jsdom","labels_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1375/labels{/name}","comments_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1375/comments","events_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1375/events","html_url":"https://github.com/tmpvar/jsdom/pull/1375","id":131502952,"number":1375,"title":"Use Mocha & Karma for test cases","user":{"login":"Joris-van-der-Wel","id":745898,"avatar_url":"https://avatars.githubusercontent.com/u/745898?v=3","gravatar_id":"","url":"https://api.github.com/users/Joris-van-der-Wel","html_url":"https://github.com/Joris-van-der-Wel","followers_url":"https://api.github.com/users/Joris-van-der-Wel/followers","following_url":"https://api.github.com/users/Joris-van-der-Wel/following{/other_user}","gists_url":"https://api.github.com/users/Joris-van-der-Wel/gists{/gist_id}","starred_url":"https://api.github.com/users/Joris-van-der-Wel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Joris-van-der-Wel/subscriptions","organizations_url":"https://api.github.com/users/Joris-van-der-Wel/orgs","repos_url":"https://api.github.com/users/Joris-van-der-Wel/repos","events_url":"https://api.github.com/users/Joris-van-der-Wel/events{/privacy}","received_events_url":"https://api.github.com/users/Joris-van-der-Wel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-04T23:14:55Z","updated_at":"2016-02-07T15:27:58Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/tmpvar/jsdom/pulls/1375","html_url":"https://github.com/tmpvar/jsdom/pull/1375","diff_url":"https://github.com/tmpvar/jsdom/pull/1375.diff","patch_url":"https://github.com/tmpvar/jsdom/pull/1375.patch"},"body":"See #1036\r\n\r\nThis PR contains all the infrastructure needed:\r\n* Mocha is used for the test cases and as the runner.\r\n* [mocha-sugar-free](https://github.com/Joris-van-der-Wel/mocha-sugar-free) is used so that we can use the style of coding we are used to. For example `it()`, `describe()`, etc are globals in mocha, mocha-sugar-free lets you define them using `require()`. It also adds support for arrow functions, which mocha does not like. One extra feature I added which is convenient in jsdom is that you can exclude a test case from being run in the browser by passing options to mocha's `it()` function. Instead of having to blacklist/whitelist test files (what we did in the past)\r\n* Karma is used instead of selenium. This speeds up the tests on your own machine a lot, and it also lets you easily test mobile browsers (all you have to do is navigate to your lan ip address).\r\n* Browser tests are now being run both with and without a Worker. Previously tests were only run within a Worker. I created a karma plugin for this: [karma-mocha-webworker](https://www.npmjs.com/package/karma-mocha-webworker)\r\n* [karma-browserify](https://www.npmjs.com/package/karma-browserify) is used instead of having to generate a bundle ourselves. This plugin supports fast incremental rebuilds (which then trigger a fresh test run). Getting this to work actually took me the most time of everything because I had to fix a few issues in browserify and karma-browserify\r\n\r\nSo far I have converted one test case to mocha (test/jsdom/env.js). I made a small tool for myself which takes care of most of the conversion. Until all test cases have been converted, the mocha tests can live alongside the nodeunit tests (and the npm test commands and the travis build will run both).\r\n\r\nHere is a successful travis build: https://travis-ci.org/Joris-van-der-Wel/jsdom/builds/107108618"},"comment":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/comments/181032205","html_url":"https://github.com/tmpvar/jsdom/pull/1375#issuecomment-181032205","issue_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1375","id":181032205,"user":{"login":"Joris-van-der-Wel","id":745898,"avatar_url":"https://avatars.githubusercontent.com/u/745898?v=3","gravatar_id":"","url":"https://api.github.com/users/Joris-van-der-Wel","html_url":"https://github.com/Joris-van-der-Wel","followers_url":"https://api.github.com/users/Joris-van-der-Wel/followers","following_url":"https://api.github.com/users/Joris-van-der-Wel/following{/other_user}","gists_url":"https://api.github.com/users/Joris-van-der-Wel/gists{/gist_id}","starred_url":"https://api.github.com/users/Joris-van-der-Wel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Joris-van-der-Wel/subscriptions","organizations_url":"https://api.github.com/users/Joris-van-der-Wel/orgs","repos_url":"https://api.github.com/users/Joris-van-der-Wel/repos","events_url":"https://api.github.com/users/Joris-van-der-Wel/events{/privacy}","received_events_url":"https://api.github.com/users/Joris-van-der-Wel/received_events","type":"User","site_admin":false},"created_at":"2016-02-07T15:27:58Z","updated_at":"2016-02-07T15:27:58Z","body":"> Why Chai? These days I tend to prefer the built-in assert. But I'm happy to be convinced if you think there's a killer feature we should be using.\r\n\r\nIt has more assertion functions like `assert.isFunction(fn)`\r\n\r\nThe plugins that chai has could also be useful:\r\n\r\nPromises:\r\n```javascript\r\nreturn assert.eventually.equal(Promise.resolve(2 + 2), 4, \"This had better be true, eventually\");\r\n```\r\n\r\nDOM:\r\n```javascript\r\nexpect(document.querySelector('main article')).to.have.attr('foo').match(/bar/)\r\n```\r\n\r\nAnd if we come up with useful assertions for jsdom, we could easily release them as a chai plugin, instead of using a hypothetical `test/util.js\"\r\n\r\nI do not feel strongly towards chai though, whatever works is fine with me."}}