peacecorps / medlink

A project to make it easier for Peace Corps Volunteers to order their medical supplies from a local Peace Corps Office. Volunteers can order by sms or webform. PC Staff interact with the orders in a simple to use dashboard.
https://www.youtube.com/watch?v=uNkwizhzMVA
Other
39 stars 36 forks source link

Set up Angular testing with Jasmine/Karma #18

Closed pstoica closed 11 years ago

pstoica commented 11 years ago

Unfortunately didn't get to do any client-side testing, so it'd be reassuring to focus on that (and do some refactoring too) for the next round and integrate it with CI.

jasnow commented 11 years ago

Reference: http://h30499.www3.hp.com/t5/HP-Software-Developers-Blog/What-goes-around-comes-around-Javascript-testing-with-Jasmine/ba-p/6089901

v3n commented 11 years ago

Thanks for the link, will definitely look at it. Angular seems like a cool tool so it's always nice to learn something I'm completely unfamiliar with.

Jonathan

On Jun 5, 2013, at 7:39 AM, Al Snow notifications@github.com wrote:

Reference: http://h30499.www3.hp.com/t5/HP-Software-Developers-Blog/What-goes-around-comes-around-Javascript-testing-with-Jasmine/ba-p/6089901

— Reply to this email directly or view it on GitHub.

pstoica commented 11 years ago

If y'all have any questions about how things are setup, just let me know! I'll run through and clean up a few things soon.

jasnow commented 11 years ago

Suggest setting this up even if you don't use it right away. Here is the short version:

  1. Watch Video: http://www.youtube.com/watch?v=MVw8N3hTfCI
  2. Install nodejs if you do not have it. You get npm too.
  3. Run "sudo npm install -g karma" to install karma.
  4. Run "karma init my.conf.js" to set up config file.
  5. Run "karma start my.conf.js" to start up GUI browser(s)/etc.
pstoica commented 11 years ago

I just set this up at my work so I'll get this set up pretty quickly. Only concern is that I don't think it would be wise to use cucumber for integration testing since you would have to tell the browser to wait (a couple of seconds) on every AJAX request, or hook into the JS to find out how many pending requests there are, and I don't feel these integration test suites were designed for that. Angular provides a testing suite that takes care of these concerns, but it's easier to use mocked JSON data as opposed to the real API (especially when database cleaning and factory_girl come in). Is mock data acceptable? Any other ideas? There's not a lot of information on how people approach this issue with end-to-end tests.

jasnow commented 11 years ago

I would encourage you to move your concern into a separate issue so to focus this issue on "Angular testing with Jasmine/Karma".

pstoica commented 11 years ago

I mean, this is questioning the need/usefulness for Cucumber/Capybara when Karma/Jasmine/Angular were designed to handle testing on their own. This isn't a separate issue, I need to understand how I'm setting up the testing framework.

jamesdabbs commented 11 years ago

+1 for mocking the data / unit testing the frontend. Full request specs are just too slow to TDD against. The only concern then is that your mocks get out of sync with what the controllers are sending back - which is where Travis running the full Cucumber suite helps - but I think having unit tests on the front end is valuable in and of itself.

pstoica commented 11 years ago

Agreed, I'll keep looking to see if there's some way to wait for all pending requests on Cucumber's side.

jasnow commented 11 years ago

Just turned off all of the cucumber tests for now. Will decide later on the future of these and other cucumber tests.

jasnow commented 11 years ago

FYI: https://weblogs.java.net/blog/developerpress/archive/2013/06/12/bdd-javascript

pstoica commented 11 years ago

I did some more research and Karma would be the wrong tool since we're depending on Rails's asset pipeline. The other thing is that real integration tests would use a real database, which needs to be in a known state--and there's no way to do that in Angular E2E tests without mocking (or Karma where multiple browsers can run the app asynchronously), while RSpec and Cucumber cover the whole spectrum fine, even if it might be slower. Capybara (with WebDriver, PhantomJS, or some other JS-enabled adapter) looks like it should be able to automatically handle asynchronous javascript by waiting and trying again if elements don't exist. I haven't tried it out yet, but I'm hoping it works for our purposes.

So I'll use Jasminerice to write unit tests with the asset pipeline intact, and Cucumber should hopefully be fine for integration tests.

jasnow commented 11 years ago

I saw this one in 24pullrequests repo: http://www.solitr.com/blog/2012/04/konacha-tutorial-javascript-testing-with-rails/

pstoica commented 11 years ago

Looks like that'll serve the same purpose as Jasminerice (using mocha instead of jasmine), but I think E2E/integration would still have to be through Cucumber/RSpec. Let me know if you have a preference between Jasminerice and Konacha.

jasnow commented 11 years ago

You pick and I will support.

jasnow commented 11 years ago

sample app: https://github.com/angular/angular-seed

jasnow commented 11 years ago

My favorite article so far: http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-testacular.html

Lots of code examples.

jasnow commented 11 years ago

This will be impacted by railsify effort.

jamesdabbs commented 11 years ago

If by "impacted" you mean "obviated" ...