joeljeske / karma-parallel

A Karma JS Framework to support sharding tests to run in parallel across multiple browsers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Parallel` throws away global beforeEach in multi-browser mode

docentovich opened this issue · comments

  • **I'm submitting a ... **

    • bug report
    • feature request
  • What is the current behavior?
    If I have some global beforeEach or afterEach methods defined in none of the describe block, in multi-browser mode, some browser instances will ignore such beforeEach or afterEach, as they will do if they were wrapped in some describe block. But when I didn't wrap beforeEach or afterEach in any describe block I expected that they will run in each test runs in each browser.

  • What is the expected behavior?
    global beforeEach or afterEach (not wrapped in any describe block) runs in each test run in each browser instance

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

My workaround:

Karma config:

module.exports = function (config) {
    basePath: '',
    frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
    plugins: [
    parallelOptions: {
      shardStrategy: 'custom',
      customShardStrategy: function (config) {
        window.parallelDescribeCount = window.parallelDescribeCount || 0;

        if (
          config.description === 'important beforeEach or afterEach go next!' // <===== there
        ) {
          return true;

        return (
          window.parallelDescribeCount % config.executors === config.shardIndex


describe('important beforeEach or afterEach go next!', () => {
  beforeAll(() => {
    console.log('important describe');

// beforeEach and afterEach go after  'important beforeEach or afterEach go next!' description. If i wrap it in description
// karma will ignore this beforeEach and afterEach on every other describe blocks 
beforeEach(() => {
afterEach(() => {