Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel throws away global beforeEach in multi-browser mode #64

Open
1 of 2 tasks
docentovich opened this issue Dec 2, 2020 · 0 comments
Open
1 of 2 tasks

Parallel throws away global beforeEach in multi-browser mode #64

docentovich opened this issue Dec 2, 2020 · 0 comments

Comments

@docentovich
Copy link

docentovich commented Dec 2, 2020

  • **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) {
  config.set({
    basePath: '',
    frameworks: ['parallel', 'jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-parallel'),
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma'),
    ],
    parallelOptions: {
      shardStrategy: 'custom',
      customShardStrategy: function (config) {
        window.parallelDescribeCount = window.parallelDescribeCount || 0;
        window.parallelDescribeCount++;

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

        return (
          window.parallelDescribeCount % config.executors === config.shardIndex
        );
      },
    },
  });
};

some-test-helper-with-global-beforeEach:

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(() => {
....
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant