karma-parallel
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -11,6 +11,17 @@ 'use strict'; | ||
const overrideSpecSuite = getSpecSuiteOverrider(shardIndexInfo); | ||
['describe', 'ddescribe', 'fdescribe'].forEach(function(methodName) { | ||
replaceMethod(root, methodName, overrideSpecSuite); | ||
const strategy = getSpecSuiteStrategy(shardIndexInfo); | ||
const overrideSpecSuite = createSpecSuiteOverrider(strategy); | ||
// Mocha uses describe.only|skip | ||
// Jasmine uses fdescribe|ddescribe|xdescribe | ||
replaceMethod(root, 'describe', function(method) { | ||
const overriden = overrideSpecSuite(method); | ||
replaceMethod(overriden, 'only', overrideSpecSuite); | ||
replaceMethod(overriden, 'skip', overrideSpecSuite); | ||
return overriden; | ||
}); | ||
replaceMethod(root, 'xdescribe', overrideSpecSuite); | ||
replaceMethod(root, 'fdescribe', overrideSpecSuite); | ||
replaceMethod(root, 'ddescribe', overrideSpecSuite); | ||
} | ||
@@ -39,19 +50,19 @@ | ||
function getSpecSuiteOverrider(shardIndexInfo) { | ||
function getSpecSuiteStrategy(shardIndexInfo) { | ||
switch (shardIndexInfo.shardStrategy) { | ||
case 'description-length': | ||
return createDescriptionLengthSpecSuiteOverrider(shardIndexInfo); | ||
return createDescriptionLengthStragegy(shardIndexInfo); | ||
case 'round-robin': | ||
/* falls through */ | ||
default: | ||
return createRoundRobinBasedSpecSuiteOverrider(shardIndexInfo); | ||
return createRoundRobinStrategy(shardIndexInfo); | ||
} | ||
} | ||
function createDescriptionLengthSpecSuiteOverrider({shardIndex, executors}) { | ||
function createSpecSuiteOverrider(strategy) { | ||
let depth = 0; | ||
return function overrideSpecSuite(origDescribe) { | ||
return function(description, specDefinitions) { | ||
// If we are a top-level describe but our description doesn't match our responsibility, skip it | ||
if (depth === 0 && description.length % executors !== shardIndex) { | ||
// If we are a top-level, ask our strategy if we should be interested in this suite | ||
if (depth === 0 && !strategy(description, specDefinitions)) { | ||
// console.log('[skipping]', description); | ||
@@ -69,19 +80,14 @@ } else { | ||
function createRoundRobinBasedSpecSuiteOverrider({shardIndex, executors}) { | ||
let depth = 0; | ||
function createDescriptionLengthStragegy({shardIndex, executors}) { | ||
return function overrideSpecSuite(description/*, specDefinitions*/) { | ||
return description.length % executors === shardIndex; | ||
}; | ||
} | ||
function createRoundRobinStrategy({shardIndex, executors}) { | ||
// Increment the count on each top level describe to determine | ||
// round-robin responsibility | ||
let count = 0; | ||
return function overrideSpecSuite(origDescribe) { | ||
return function(description, specDefinitions) { | ||
// If we are a top-level describe but our description doesn't match our responsibility, skip it | ||
if (depth === 0 && count++ % executors !== shardIndex) { | ||
// console.log('[skipping]', description); | ||
} else { | ||
origDescribe(description, function() { | ||
depth++; | ||
specDefinitions(); | ||
depth--; | ||
}); | ||
} | ||
}; | ||
return function(/*description, specDefinitions*/) { | ||
return count++ % executors === shardIndex; | ||
}; | ||
@@ -88,0 +94,0 @@ } |
@@ -57,3 +57,3 @@ { | ||
}, | ||
"version": "0.1.0" | ||
"version": "0.1.1" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25700
418