{"action":"created","issue":{"url":"https://api.github.com/repos/18F/generator-18F-static/issues/5","repository_url":"https://api.github.com/repos/18F/generator-18F-static","labels_url":"https://api.github.com/repos/18F/generator-18F-static/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/18F/generator-18F-static/issues/5/comments","events_url":"https://api.github.com/repos/18F/generator-18F-static/issues/5/events","html_url":"https://github.com/18F/generator-18F-static/pull/5","id":173541708,"number":5,"title":"[WIP] Unit test scaffolding with mocha + jsdom","user":{"login":"shawnbot","id":113896,"avatar_url":"https://avatars.githubusercontent.com/u/113896?v=3","gravatar_id":"","url":"https://api.github.com/users/shawnbot","html_url":"https://github.com/shawnbot","followers_url":"https://api.github.com/users/shawnbot/followers","following_url":"https://api.github.com/users/shawnbot/following{/other_user}","gists_url":"https://api.github.com/users/shawnbot/gists{/gist_id}","starred_url":"https://api.github.com/users/shawnbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shawnbot/subscriptions","organizations_url":"https://api.github.com/users/shawnbot/orgs","repos_url":"https://api.github.com/users/shawnbot/repos","events_url":"https://api.github.com/users/shawnbot/events{/privacy}","received_events_url":"https://api.github.com/users/shawnbot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-26T20:54:33Z","updated_at":"2016-08-27T03:18:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/18F/generator-18F-static/pulls/5","html_url":"https://github.com/18F/generator-18F-static/pull/5","diff_url":"https://github.com/18F/generator-18F-static/pull/5.diff","patch_url":"https://github.com/18F/generator-18F-static/pull/5.patch"},"body":"This is a first pass at what a generator for JS unit tests might look like. @msecret, take a look if you have some time and let's chat about it soon. Here's the skinny:\r\n\r\n1. Prompt: which test framework to use. We offer [Jasmine] and [Mocha], but only Mocha has unit test scaffolding currently. (The APIs are very similar, though.)\r\n1. Prompt: which assertion style/library to use. I offer Node's native `assert` (the default), [expect], and [should]; but currently the native `assert` is the only one used in the example spec. Maybe we should offer [chai], too, or instead of expect? **Or maybe we settle on Jasmine because it just includes [expect-like assertions](http://jasmine.github.io/2.4/introduction.html#section-Expectations) out of the box?**\r\n1. Prompt: do you need a \"browser-like DOM?\" If so, we [add](https://github.com/18F/generator-18F-static/blob/test-unit/generators/test-unit/index.js#L71-L73) [jsdom] and [jsdom-global] to the dependencies. If the test framework is Mocha, then we also [register jsdom-global in `mocha.opts`](https://github.com/18F/generator-18F-static/blob/test-unit/generators/test-unit/index.js#L133-L143). This means that you have a pure-JS DOM in all of your unit tests!\r\n1. Install the requisite npm `devDependencies`.\r\n1. Copy the `test/unit` directory from the requested framework's template directory, which includes an [example spec](https://github.com/18F/generator-18F-static/blob/test-unit/generators/test-unit/templates/mocha/test/unit/example.spec.js) for [lib/lower.js](https://github.com/18F/generator-18F-static/blob/test-unit/generators/test-unit/templates/lib/lower.js).\r\n1. Add a `test` script that runs `{framework} test/unit/**/*.spec.js`.\r\n\r\nA lot of the logic for this lives in JS rather than in a templated `package.json`, but that's really just because I'm not super familiar with EJS templates and wanted to get things done. I'm happy to move the logic into a template if that's what y'all would prefer.\r\n\r\nI'm not sure about the best way to incorporate this into the main generator, or if there's a standard practice around that with Yeoman. For instance, does the main one just add a prompt for whether the user wants JS unit tests, then \"composes\" this one if so? @juliaelman, maybe you know something about this?\r\n\r\n[chai]: http://chaijs.com/\r\n[expect]: https://www.npmjs.com/package/expect\r\n[jasmine]: http://jasmine.github.io/\r\n[jsdom]: https://github.com/tmpvar/jsdom\r\n[jsdom-global]: https://npm.im/jsdom-global\r\n[mocha]: http://mochajs.org/\r\n[should]: https://shouldjs.github.io/\r\n"},"comment":{"url":"https://api.github.com/repos/18F/generator-18F-static/issues/comments/242892463","html_url":"https://github.com/18F/generator-18F-static/pull/5#issuecomment-242892463","issue_url":"https://api.github.com/repos/18F/generator-18F-static/issues/5","id":242892463,"user":{"login":"juliaelman","id":955558,"avatar_url":"https://avatars.githubusercontent.com/u/955558?v=3","gravatar_id":"","url":"https://api.github.com/users/juliaelman","html_url":"https://github.com/juliaelman","followers_url":"https://api.github.com/users/juliaelman/followers","following_url":"https://api.github.com/users/juliaelman/following{/other_user}","gists_url":"https://api.github.com/users/juliaelman/gists{/gist_id}","starred_url":"https://api.github.com/users/juliaelman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliaelman/subscriptions","organizations_url":"https://api.github.com/users/juliaelman/orgs","repos_url":"https://api.github.com/users/juliaelman/repos","events_url":"https://api.github.com/users/juliaelman/events{/privacy}","received_events_url":"https://api.github.com/users/juliaelman/received_events","type":"User","site_admin":false},"created_at":"2016-08-27T03:18:56Z","updated_at":"2016-08-27T03:18:56Z","body":"@shawnbot your assumption is correct! We will need to shift things around a bit to make it all work correctly and am happy to help with the organization.\r\n\r\nAs for where the logic lives, totally ok to leave it in the `test-unit` generator scripts. In general, I usually lean towards simple logic in the templates themselves and more complexity elsewhere.\r\n\r\nAlso, my two cents on `mocha + chai` vs. `Jasmine` question. We should check in with Front end Guild on which one folks want/need. It might also be good for us to choose one or the other for now, so as not to have to maintain them both."}}
{"actor":{"display_login":"juliaelman"}}