mozilla / oghliner

template and tool for deploying Offline Web Apps to GitHub Pages
https://mozilla.github.io/oghliner/
Apache License 2.0
116 stars 17 forks source link

Adding the infrastructure for enabling browser tests for the service worker. #257

Closed delapuente closed 8 years ago

delapuente commented 8 years ago

@marco-c this is some boilerplate needed to start writing the tests. Do you mind to review? Asking @mykmelez for additional input.

I'm not adding these tests to the test task as it is not possible to run them without the browsers, so, AFAIK, they can not be executed on Travis but at least, we could test the worker inside the Service Worker environment.

Notice that enabling testing the service worker without browsers is still possible if we browserify the serviceworker and export oghliner API, mocking everything else.

Actually tests for this interface is exactly what I'm going to do but I prefer to run them inside the real context to be as realistic as possible.

mykmelez commented 8 years ago

I'm not adding these tests to the test task as it is not possible to run them without the browsers, so, AFAIK, they can not be executed on Travis but at least, we could test the worker inside the Service Worker environment.

It's ok to start with a separate task that we can run locally, but it seems like it should be possible to run these tests on Travis too. For PluotSorbet, we use SlimerJS to run tests in Travis on Firefox/Gecko, and presumably PhantomJS works similarly for testing on WebKit (although that's not the same thing as testing in Chrome).

Also, Firefox and Chrome themselves are installed in Travis environments and can be run via xvfb. GUI and Headless Browser Testing talks about browser testing on Travis generally, while How to run JavaScript tests in Chrome on Travis describes a particular example.

Of course we have to make sure we have a version of each browser that supports service workers. And I'm unfamiliar with Karma, so I don't know how easy it is to hook it up. It's fine to start with tests that just run locally. However, ultimately we should enhance those tests to run in Travis too, and it seems possible to do.

delapuente commented 8 years ago

You're completely right. @marco-c was enlightening me about ways of testing browsers on Travis. Waiting for his feedback as well.

marco-c commented 8 years ago

We talked on IRC about SlimerJS and Selenium, but we'll probably be able to directly use Karma on Travis, we just need to download the browsers and maybe create custom karma launchers (they're pretty simple, for example: https://github.com/karma-runner/karma-firefox-launcher/blob/master/index.js).

Here's some documentation: http://karma-runner.github.io/0.8/plus/Travis-CI.html

marco-c commented 8 years ago

We'll need to use a custom launcher also because that one doesn't really work on Linux (it always picks up the globally installed Firefox, it doesn't care if it's Nightly, Aurora, etc.).

delapuente commented 8 years ago

Don't worry about the launchers, we must override binary paths for the browser via environment variables. It is a known issue I already experimented when working with Arch Linux.