`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 someglobal
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(() => {
....
});