Spig
Spig

Reputation: 488

Are test cases in Jasmine 2.0 run in parallel

Are tests in Jasmine 2.0 run in parallel? In my experience they aren't but the article , referenced by Jasmine.js: Race Conditions when using "runs" suggests that Jasmine does run them in parallel so I wondered if I was writing my tests incorrectly.

Here is a set of tests that I would expect to execute in 1 second instead of 4 seconds.

describe("first suite", function() {
  it("first test", function(done) {
    expect(true).toBeTruthy();
    setTimeout(done, 1000);
  });

  it("second test", function(done) {
    expect(true).toBeTruthy();
    setTimeout(done, 1000);
  });
});

describe("second suite", function() {
  it("first test", function(done) {
    expect(true).toBeTruthy();
    setTimeout(done, 1000);
  });

  it("second test", function(done) {
    expect(true).toBeTruthy();
    setTimeout(done, 1000);
  });
});

Am I missing something?

jsFiddle

Upvotes: 13

Views: 12325

Answers (2)

Joel Jeske
Joel Jeske

Reputation: 1647

If you want to run your test in parallel and you are using karma as a test launcher, you can use karma-parallel to split up your tests across multiple browser instances. It runs specs in different browser instances and is very simple and easy to install:

npm i karma-parallel

and then add the 'parallel' to the frameworks list in karma.conf.js

module.exports = function(config) {
  config.set({
    frameworks: ['parallel', 'jasmine']
  });
};

karma-parallel

Disclosure: I am the author

Upvotes: 9

Gregg
Gregg

Reputation: 2638

Jasmine does not actually run your specs in parallel in any way. It is however possible to have specs whose asynchronous portion takes long enough that the built-in time limit elapses which will cause jasmine to start running the next spec, even though there may still be code running from earlier specs.

Upvotes: 20

Related Questions