karma-sharding
Advanced tools
Comparing version 4.3.3 to 4.4.0
const _ = require('lodash'); | ||
const { isSpecFile, splitArray } = require('./utils'); | ||
const { isSpecFile } = require('./matchers'); | ||
function getConfig(fullConfig) { | ||
@@ -13,2 +12,3 @@ // ensure we can manipulate config settings | ||
config.indexMap = {}; | ||
config.getSets = config.getSets ? config.getSets : getSets; | ||
return config; | ||
@@ -31,19 +31,12 @@ } | ||
// modified from example at: | ||
// https://stackoverflow.com/questions/8188548/splitting-a-js-array-into-n-arrays | ||
function splitArray(flatArray, numCols){ | ||
const maxColLength = Math.ceil(flatArray.length/numCols); | ||
const nestedArray = _.chunk(flatArray, maxColLength); | ||
for (var i = nestedArray.length; i < numCols; i++) { | ||
nestedArray.push([]); | ||
} | ||
return nestedArray; | ||
function setupSets(config, basePath, files) { | ||
config.sets = config.getSets(config, basePath, files); | ||
config.performSharding = _.last(config.sets).length; | ||
} | ||
function setupSets(config, basePath, files) { | ||
// can be redefined in sharding config | ||
function getSets(config, basePath, files) { | ||
var specs = files.served.map(f => config.base + f.path.replace(basePath, '')) | ||
.filter(p => isSpecFile(p, config.specMatcher)); | ||
config.sets = splitArray(specs, config.browserCount); | ||
var lastSet = config.sets && config.sets.length && config.sets[config.sets.length - 1]; | ||
config.performSharding = (lastSet && lastSet.length); | ||
return splitArray(specs, config.browserCount); | ||
} | ||
@@ -50,0 +43,0 @@ |
@@ -1,2 +0,2 @@ | ||
const { isSpecFile } = require('./matchers'); | ||
const { isSpecFile } = require('./utils'); | ||
@@ -3,0 +3,0 @@ const idParamExtractor = /\/\?id=(\d+)/; |
{ | ||
"name": "karma-sharding", | ||
"version": "4.3.3", | ||
"version": "4.4.0", | ||
"description": "Karma plugin to allow tests to be distributed across multiple browsers", | ||
@@ -34,2 +34,7 @@ "engines": { | ||
"url": "https://github.com/rschuft" | ||
}, | ||
{ | ||
"name": "Mikhail Zheludev", | ||
"email": "jbubsk@gmail.com", | ||
"url": "https://github.com/jbubsk" | ||
} | ||
@@ -36,0 +41,0 @@ ], |
@@ -26,7 +26,15 @@ # karma-sharding | ||
specMatcher: /(spec|test)s?\.js/i, | ||
base: '/base' | ||
base: '/base', | ||
getSets: function(config, basePath, files) { | ||
// splitForBrowsers - some util function | ||
return splitForBrowsers(files.served) | ||
.map(oneBrowserSet => [someInitScript].concat(oneBrowserSet)); | ||
} | ||
} | ||
} | ||
``` | ||
`getSets` might be overridden when files from `karma.files` config should be organized in certain view, for example: | ||
`karma.files` has set - `[setup.js, one.unit.js, two.unit.js]` - and it must be combined for each browser as `[setup.js, one.unit.js]` and `[setup.js, two.unit.js]` | ||
## Installation | ||
@@ -33,0 +41,0 @@ |
36811
694
85