How to Run Karma without Restarting Browsers In Between Test Suites

436 views
Skip to first unread message

Dan Deming

unread,
Mar 16, 2015, 9:40:43 AM3/16/15
to karma...@googlegroups.com
I'm using Karma with Grunt and the associated plugins. I have everything working using test configurations such as the following:

        apiUnitTests: {
          files: [
            { 
              src: [
              , 'tests/unit/mocks/base.mock.js'
              , 'modules/util/util.js'
              , 'tests/unit/modules/util/api.test.js' 
              ]
            , served: true
            }
          ]
        }
      , customerUnitTests: {
          files: [
            { 
              src: [
              , 'tests/unit/mocks/base.mock.js'
              , 'modules/util/util.js'
              , 'tests/unit/modules/util/customer.test.js' 
              ]
            , served: true
            }
          ]
        }

The problem with this setup is that when I run the tests, I see the following workflow:
1) Create new browser
2) Run API Tests
3) Destroy the browser
4) Create new browser
5) Run Customer Tests
6) Destroy the browser 

The behavior I want is to create a new browser instance, run ALL my tests and then destroy the browser instance.

I've tried the following:
* changing singleRun to false -- This doesn't work because the browser never gets created at all.
* Merging all my tests into 1 object that has multiple objects within its "files" array. This wouldn't be ideal if it worked because each test wouldn't be individually named. I could live with this and hack together aliases to get what I want, but in the end it doesn't seem to work anyway: The test files seem to "pollute" one another. I think it's trying to load every object in the array simultaneously rather than treating them as separate tests.

Any suggestions on how I can get the behavior I want?

Many thanks,
Dan

Mark Trostler

unread,
Mar 17, 2015, 11:50:06 AM3/17/15
to karma...@googlegroups.com
This cannot be done with separate karma stanzas in your Gruntfile.  Karma will either disconnect after all the tests have been run in the 'singleRun: true' case or never move on to the second stanza if you are autowatching.  Even if 'browsers' is empty and you manually connect to karma it will disconnect from the browser and you'll need to start another one to run the second set of tests.
Are you trying to do this in a singleRun/continuous environment or forever watching?
  Mark

--
You received this message because you are subscribed to the Google Groups "karma-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to karma-users...@googlegroups.com.
To post to this group, send email to karma...@googlegroups.com.
Visit this group at http://groups.google.com/group/karma-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/karma-users/d435769a-a65c-4158-bbf3-bdec1d7e29a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Deming

unread,
Mar 17, 2015, 1:03:34 PM3/17/15
to karma...@googlegroups.com
Hi Mark,

This is for both local dev and for CI -- once I know what my options are, I'll probably set up different configs for both.

Thanks for the response. It's good to know that I'm not missing something obvious and what I want to do isn't supported directly. I structured my tests the way I did because I make a distinction between unit tests and integration tests (my example code shows 2 test suites but I actually have 10 and growing). Sometimes my unit tests have modules mocked out which are included for real in the integration tests so I have different configurations of real code versus mocks, depending on the test.

I guess the long load times brought on by the browser being recreated for each test file are something I'll just have to live with for now. It's particularly painful when I run the suite against sauce labs browsers.

I did see this project https://www.npmjs.com/package/karma-environments which promises the ability to "Run multiple test suites in one karma process" which is exactly what I want to do. It seems like it may be somewhat time consuming to set up though, so I think I'll likely put up with the super-long load times for now. When it gets too painful though, I'm sure I'll need to figure something else out.
Reply all
Reply to author
Forward
0 new messages