CodeChimp
CodeChimp

Reputation: 8154

Starting Meteor with Velocity test without the Chrome pop-up

In my quest to gather knowledge about how to use Velocity, I ran across a snippet that mentioned a shell variable to set the browser Velocity used to run Karma in PhantomJS as apposed to creating a Chrome window pop-up each time I run my app in DEV-mode. At the time I shrugged it off, but after having implemented some testing in two of my apps, I can say it's an annoying pain to have the tests running in a pop-up window.

Does someone know if how one might get the tests running such that they run in PhantomJS and not in a Chrome pop-up windows? I thought the variable was something like VELOCITY_BROWSER=PhantomJS, but that doesn't seem to work. Also, is there a way to setup Meteor so that it simply sets this as a default so I don't have to create the variable each time, like in a config or something?

Upvotes: 5

Views: 887

Answers (2)

quetzalcoatl
quetzalcoatl

Reputation: 33506

In sanjo:jasmine 0.17.0 on Windows, PhantomJS has some issues with meteor's autoupdate feature. You may have problems with re-running tests when you change the app's code.

If you'd like to stick with Chrome window, it can be somewhat hid by using chrome's commandline options, but you'd need to update karma-chrome-launcher\index.js to include these:

return [
  '--user-data-dir=' + this._tempDir,
  '--no-default-browser-check',
  '--no-first-run',
  '--disable-default-apps',
  '--disable-popup-blocking',
  '--disable-translate',
  '--window-position=-800,0',    // <-- added
  '--window-size=800,600'        // <-- added
].concat(flags, [url])

The window will show up, but will be created off-screen, and somehow luckily doesn't even steal the keyboard focus.

Upvotes: 0

CodeChimp
CodeChimp

Reputation: 8154

I found the answer for those that find this and were also wondering how to prevent the Karma popup.

I am using the sanjo:jasmine test suite, which uses Karma for the client integration tests. You can set the default browser to PhantomJS by simply adding this to your environment when you run meteor:

JASMINE_BROWSER=PhantomJS

Or, if you just want to turn off client integration tests altogether simply adding this:

JASMINE_CLIENT_UNIT=0

So, for instance you can run your app like JASMINE_BROWSER=PhantomJS meteor, and you will not get the popup any longer. What I did was created a meteor.sh in my app root folder that I use to launch with environment variables like so:

#!/bin/sh
JASMINE_BROWSER=PhantomJS meteor

This is only for convenience so I wouldn't have to remember the variable to do this. This should work on any *nix-based OS. You could also make an alias if you wanted. It would look something like:

alias meteor=JASMINE_BROWSER=PhantomJS meteor

I may be slightly off in the syntax, but I think that should work.

To use PhantomJS you do need to have it installed, so run this in a terminal:

npm install -g phantomjs

Or, if you are on a Mac run (you will need brew installed):

brew install phantomjs

Hope this helps someone in the future.

Upvotes: 9

Related Questions