I am writing a chrome packaged app, using angular JS.

My setup uses grunt/karma/jasmine for building/unit testing, and everything was fine until I started using the chrome.* API. This of course was an issue as I had Travis-CI set up to use PhantomJS, but Phantom doesn't know about the chrome global var.

  1. Is there a way to run unit tests with karma that will not throw ReferenceError: Can't find variable: chrome for testing packaged apps, and so pass Travis-CI testing
  2. Is there a way to suppress the errors that PhantomJS is throwing (this sounds bad already)
有帮助吗?

解决方案

Few thoughts:

  1. You could polyfill/stub the chrome.* apis before running your tests, to simulate the chrome app environment. Not sure if anyone has already done this already (i.e. here is one quick example for node-webkit I found). It sounds like a useful library someone should write ;)

  2. Just skip those tests that you know will always fail on PhantomJS, by wrapping jasmine test definitions with a guard like if (!is_chrome_app) return;. One clean way to do this in jasmine is to create a defineChromeAppOnly helper that skips the define call if its not a chome app.

  3. You probably want an alternative system for actually running tests inside a real chrome app. I've always just built my own crude CI for this (or done it manually), but since this would be cool to make easier for CI, I've filed a request with Travis CI Team to support Chrome Packaged Apps. Star that issue if you are interested in what they reply.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top