Skip to content

Commit

Permalink
Only add a fake spec when there are not any specs in the current inst…
Browse files Browse the repository at this point in the history
…ance but there are specs in another instance. fixes #30
  • Loading branch information
joeljeske committed Dec 1, 2018
1 parent 3702962 commit be2aa77
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/karma-parallelizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function createFakeTestContext(ctx, shouldUseDescription) {
var isFaking = false; // Are we currently faking out describe blocks to look for tests for other instances
var hasFocusedWhileFaking = false; // Have we found a focus tests for another instance
var hasFocusedWithoutFaking = false; // Have we registerd at least one focus test for this instance
var hasSpecs = false; // Have we registered at least one test for this instance
var hasOwnSpecs = false; // Have we registered at least one test for this instance
var hasOtherSpecs = false; // Have we seen at least one test for another instance
var forceDescribe = false; //

function wrapDescription(def) {
Expand All @@ -85,15 +86,16 @@ function createFakeTestContext(ctx, shouldUseDescription) {
}

// On focus spec in mocha we need to return the test result and need to
function wrap(fn, isFocus, isDescription, isSpec) {
function wrap(fn, isFocus, isDescription, isSpec, isSkipped) {
if (!fn) return fn;
return function(name, def) {
if (isDescription && depth === 0) {
// Reset isFaking on top-level descriptions
isFaking = !shouldUseDescription(name, def);
}

hasSpecs = hasSpecs || (isSpec && !isFaking);
hasOwnSpecs = hasOwnSpecs || (isSpec && !isFaking);
hasOtherSpecs = hasOtherSpecs || (isSpec && isFaking);
hasFocusedWhileFaking = hasFocusedWhileFaking || (isFocus && isFaking);
hasFocusedWithoutFaking = hasFocusedWithoutFaking || (isFocus && !isFaking);

Expand Down Expand Up @@ -148,9 +150,9 @@ function createFakeTestContext(ctx, shouldUseDescription) {
(ctx.fit || ctx.iit || ctx.it.only).call(ctx, 'should prevent other tests from running', function(){});
});
}
if (!hasSpecs) {
if (!hasOwnSpecs && hasOtherSpecs) {
ctx.describe('[karma-parallel] Add single test to prevent failure', function() {
(ctx.it || ctx.specify).call(ctx, 'should prevent failing by having sucessful tests', function(){});
(ctx.it || ctx.specify).call(ctx, 'should prevent on this shard failing by having successful tests', function(){});
});
}
forceDescribe = false;
Expand Down

0 comments on commit be2aa77

Please sign in to comment.