karma-sharding
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -41,3 +41,3 @@ const _ = require('lodash'); | ||
var specs = files.served.map(f => config.base + f.path.replace(basePath, '')) | ||
.filter(p => config.specMatcher.test(p)); | ||
.filter(p => config.specMatcher.test(p)); | ||
config.sets = splitArray(specs, config.browserCount); | ||
@@ -64,8 +64,8 @@ var lastSet = config.sets && config.sets.length && config.sets[config.sets.length - 1]; | ||
function handleFileListModified(fullConfig, config, files, log) { | ||
setupSets(config, fullConfig.basePath, files); | ||
setupSharding(config, fullConfig, log); | ||
log.debug('config.sets:', config.sets); | ||
setupSets(config, fullConfig.basePath, files); | ||
setupSharding(config, fullConfig, log); | ||
log.debug('config.sets:', config.sets); | ||
} | ||
function handleBrowserRegister(config, browser, log) { | ||
function handleBrowserRegister(config, browser) { | ||
config.indexMap[browser.id] = config.sets.shift(); | ||
@@ -78,8 +78,8 @@ } | ||
switch(event) { | ||
case 'file_list_modified': | ||
handleFileListModified(fullConfig, config, entry, log); | ||
break; | ||
case 'browser_register': | ||
handleBrowserRegister(config, entry, log); | ||
break; | ||
case 'file_list_modified': | ||
handleFileListModified(fullConfig, config, entry, log); | ||
break; | ||
case 'browser_register': | ||
handleBrowserRegister(config, entry); | ||
break; | ||
} | ||
@@ -86,0 +86,0 @@ return originalEmit.apply(emitter, arguments); |
@@ -22,6 +22,6 @@ // Coverage Reporter | ||
var path = require('path') | ||
var istanbul = require('istanbul') | ||
var minimatch = require('minimatch') | ||
var _ = require('lodash') | ||
var path = require('path'); | ||
var istanbul = require('istanbul'); | ||
var minimatch = require('minimatch'); | ||
var _ = require('lodash'); | ||
@@ -32,5 +32,5 @@ // START OF CHANGE NEEDED ONLY FOR KARMA-SHARDING | ||
// var SourceCacheStore = require('./source-cache-store') | ||
var globalSourceCache = require('karma-coverage/lib/source-cache') | ||
var coverageMap = require('karma-coverage/lib/coverage-map') | ||
var SourceCacheStore = require('karma-coverage/lib/source-cache-store') | ||
var globalSourceCache = require('karma-coverage/lib/source-cache'); | ||
var coverageMap = require('karma-coverage/lib/coverage-map'); | ||
var SourceCacheStore = require('karma-coverage/lib/source-cache-store'); | ||
// END OF CHANGE NEEDED ONLY FOR KARMA-SHARDING | ||
@@ -40,6 +40,6 @@ | ||
if (path.isAbsolute) { | ||
return path.isAbsolute(file) | ||
return path.isAbsolute(file); | ||
} | ||
return path.resolve(file) === path.normalize(file) | ||
return path.resolve(file) === path.normalize(file); | ||
} | ||
@@ -49,3 +49,3 @@ | ||
var CoverageReporter = function (rootConfig, helper, logger, emitter) { | ||
var log = logger.create('coverage') | ||
var log = logger.create('coverage'); | ||
@@ -55,3 +55,3 @@ // Instance variables | ||
this.adapters = [] | ||
this.adapters = []; | ||
@@ -61,7 +61,7 @@ // Options | ||
var config = rootConfig.coverageReporter || {} | ||
var basePath = rootConfig.basePath | ||
var reporters = config.reporters | ||
var sourceCache = globalSourceCache.get(basePath) | ||
var includeAllSources = config.includeAllSources === true | ||
var config = rootConfig.coverageReporter || {}; | ||
var basePath = rootConfig.basePath; | ||
var reporters = config.reporters; | ||
var sourceCache = globalSourceCache.get(basePath); | ||
var includeAllSources = config.includeAllSources === true; | ||
@@ -71,12 +71,12 @@ var aggregator = config.browserId || 'id'; // ADDED BY KARMA-SHARDING | ||
if (config.watermarks) { | ||
config.watermarks = helper.merge({}, istanbul.config.defaultConfig().reporting.watermarks, config.watermarks) | ||
config.watermarks = helper.merge({}, istanbul.config.defaultConfig().reporting.watermarks, config.watermarks); | ||
} | ||
if (!helper.isDefined(reporters)) { | ||
reporters = [config] | ||
reporters = [config]; | ||
} | ||
var collectors | ||
var pendingFileWritings = 0 | ||
var fileWritingFinished = function () {} | ||
var collectors; | ||
var pendingFileWritings = 0; | ||
var fileWritingFinished = function () {}; | ||
@@ -86,13 +86,13 @@ function writeReport (reporter, collector) { | ||
if (typeof config._onWriteReport === 'function') { | ||
var newCollector = config._onWriteReport(collector) | ||
var newCollector = config._onWriteReport(collector); | ||
if (typeof newCollector === 'object') { | ||
collector = newCollector | ||
collector = newCollector; | ||
} | ||
} | ||
reporter.writeReport(collector, true) | ||
reporter.writeReport(collector, true); | ||
} catch (e) { | ||
log.error(e) | ||
log.error(e); | ||
} | ||
--pendingFileWritings | ||
--pendingFileWritings; | ||
} | ||
@@ -103,6 +103,6 @@ | ||
_.forEach(collectors, function (collector) { | ||
collector.dispose() | ||
}) | ||
collector.dispose(); | ||
}); | ||
fileWritingFinished() | ||
fileWritingFinished(); | ||
} | ||
@@ -113,11 +113,11 @@ } | ||
// Exclude keys will always be relative, but covObj keys can be absolute or relative | ||
var excludeKey = isAbsolute(key) ? path.relative(basePath, key) : key | ||
var excludeKey = isAbsolute(key) ? path.relative(basePath, key) : key; | ||
// Also normalize for files that start with `./`, etc. | ||
excludeKey = path.normalize(excludeKey) | ||
excludeKey = path.normalize(excludeKey); | ||
return excludeKey | ||
return excludeKey; | ||
} | ||
function removeFiles (covObj, patterns) { | ||
var obj = {} | ||
var obj = {}; | ||
@@ -127,16 +127,16 @@ Object.keys(covObj).forEach(function (key) { | ||
var found = patterns.some(function (pattern) { | ||
return minimatch(normalize(key), pattern, {dot: true}) | ||
}) | ||
return minimatch(normalize(key), pattern, {dot: true}); | ||
}); | ||
// if no patterns match, keep the key | ||
if (!found) { | ||
obj[key] = covObj[key] | ||
obj[key] = covObj[key]; | ||
} | ||
}) | ||
}); | ||
return obj | ||
return obj; | ||
} | ||
function overrideThresholds (key, overrides) { | ||
var thresholds = {} | ||
var thresholds = {}; | ||
@@ -146,8 +146,8 @@ // First match wins | ||
if (minimatch(normalize(key), pattern, {dot: true})) { | ||
thresholds = overrides[pattern] | ||
return true | ||
thresholds = overrides[pattern]; | ||
return true; | ||
} | ||
}) | ||
}); | ||
return thresholds | ||
return thresholds; | ||
} | ||
@@ -172,16 +172,16 @@ | ||
} | ||
} | ||
}; | ||
var thresholds = helper.merge({}, defaultThresholds, config.check) | ||
var thresholds = helper.merge({}, defaultThresholds, config.check); | ||
var rawCoverage = collector.getFinalCoverage() | ||
var globalResults = istanbul.utils.summarizeCoverage(removeFiles(rawCoverage, thresholds.global.excludes)) | ||
var eachResults = removeFiles(rawCoverage, thresholds.each.excludes) | ||
var rawCoverage = collector.getFinalCoverage(); | ||
var globalResults = istanbul.utils.summarizeCoverage(removeFiles(rawCoverage, thresholds.global.excludes)); | ||
var eachResults = removeFiles(rawCoverage, thresholds.each.excludes); | ||
// Summarize per-file results and mutate original results. | ||
Object.keys(eachResults).forEach(function (key) { | ||
eachResults[key] = istanbul.utils.summarizeFileCoverage(eachResults[key]) | ||
}) | ||
eachResults[key] = istanbul.utils.summarizeFileCoverage(eachResults[key]); | ||
}); | ||
var coverageFailed = false | ||
var coverageFailed = false; | ||
@@ -194,33 +194,33 @@ function check (name, thresholds, actuals) { | ||
'functions' | ||
] | ||
]; | ||
keys.forEach(function (key) { | ||
var actual = actuals[key].pct | ||
var actualUncovered = actuals[key].total - actuals[key].covered | ||
var threshold = thresholds[key] | ||
var actual = actuals[key].pct; | ||
var actualUncovered = actuals[key].total - actuals[key].covered; | ||
var threshold = thresholds[key]; | ||
if (threshold < 0) { | ||
if (threshold * -1 < actualUncovered) { | ||
coverageFailed = true | ||
coverageFailed = true; | ||
log.error(browser.name + ': Uncovered count for ' + key + ' (' + actualUncovered + | ||
') exceeds ' + name + ' threshold (' + -1 * threshold + ')') | ||
') exceeds ' + name + ' threshold (' + -1 * threshold + ')'); | ||
} | ||
} else { | ||
if (actual < threshold) { | ||
coverageFailed = true | ||
coverageFailed = true; | ||
log.error(browser.name + ': Coverage for ' + key + ' (' + actual + | ||
'%) does not meet ' + name + ' threshold (' + threshold + '%)') | ||
'%) does not meet ' + name + ' threshold (' + threshold + '%)'); | ||
} | ||
} | ||
}) | ||
}); | ||
} | ||
check('global', thresholds.global, globalResults) | ||
check('global', thresholds.global, globalResults); | ||
Object.keys(eachResults).forEach(function (key) { | ||
var keyThreshold = helper.merge(thresholds.each, overrideThresholds(key, thresholds.each.overrides)) | ||
check('per-file' + ' (' + key + ') ', keyThreshold, eachResults[key]) | ||
}) | ||
var keyThreshold = helper.merge(thresholds.each, overrideThresholds(key, thresholds.each.overrides)); | ||
check('per-file' + ' (' + key + ') ', keyThreshold, eachResults[key]); | ||
}); | ||
return coverageFailed | ||
return coverageFailed; | ||
} | ||
@@ -231,49 +231,49 @@ | ||
function generateOutputDir (browserName, dir, subdir) { | ||
dir = dir || 'coverage' | ||
subdir = subdir || browserName | ||
dir = dir || 'coverage'; | ||
subdir = subdir || browserName; | ||
if (_.isFunction(subdir)) { | ||
subdir = subdir(browserName) | ||
subdir = subdir(browserName); | ||
} | ||
return path.join(dir, subdir) | ||
return path.join(dir, subdir); | ||
} | ||
this.onRunStart = function (browsers) { | ||
collectors = Object.create(null) | ||
collectors = Object.create(null); | ||
// TODO(vojta): remove once we don't care about Karma 0.10 | ||
if (browsers) { | ||
browsers.forEach(this.onBrowserStart.bind(this)) | ||
browsers.forEach(this.onBrowserStart.bind(this)); | ||
} | ||
} | ||
}; | ||
this.onBrowserStart = function (browser) { | ||
if (!collectors[browser[aggregator]]) { // ADDED BY KARMA-SHARDING | ||
collectors[browser[aggregator]] = new istanbul.Collector() // CHANGE MADE BY KARMA-SHARDING | ||
collectors[browser[aggregator]] = new istanbul.Collector(); // CHANGE MADE BY KARMA-SHARDING | ||
if (!includeAllSources) return | ||
if (!includeAllSources) return; | ||
collectors[browser[aggregator]].add(coverageMap.get()) // CHANGE MADE BY KARMA-SHARDING | ||
collectors[browser[aggregator]].add(coverageMap.get()); // CHANGE MADE BY KARMA-SHARDING | ||
} // ADDED BY KARMA-SHARDING | ||
} | ||
}; | ||
this.onBrowserComplete = function (browser, result) { | ||
var collector = collectors[browser[aggregator]] // CHANGE MADE BY KARMA-SHARDING | ||
var collector = collectors[browser[aggregator]]; // CHANGE MADE BY KARMA-SHARDING | ||
if (!collector) return | ||
if (!result || !result.coverage) return | ||
if (!collector) return; | ||
if (!result || !result.coverage) return; | ||
collector.add(result.coverage) | ||
} | ||
collector.add(result.coverage); | ||
}; | ||
this.onSpecComplete = function (browser, result) { | ||
if (!result.coverage) return | ||
if (!result.coverage) return; | ||
collectors[browser[aggregator]].add(result.coverage) // CHANGE MADE BY KARMA-SHARDING | ||
} | ||
collectors[browser[aggregator]].add(result.coverage); // CHANGE MADE BY KARMA-SHARDING | ||
}; | ||
this.onRunComplete = function (browsers, results) { | ||
var checkedCoverage = {} | ||
var checkedCoverage = {}; | ||
@@ -288,3 +288,3 @@ reporters.forEach(function (reporterConfig) { | ||
if (seen[browser[aggregator]]) { | ||
return | ||
return; | ||
} | ||
@@ -294,6 +294,6 @@ seen[browser[aggregator]] = 1; | ||
var collector = collectors[browser[aggregator]] // CHANGE MADE BY KARMA-SHARDING | ||
var collector = collectors[browser[aggregator]]; // CHANGE MADE BY KARMA-SHARDING | ||
if (!collector) { | ||
return | ||
return; | ||
} | ||
@@ -303,7 +303,7 @@ | ||
if (config.hasOwnProperty('check') && !checkedCoverage[browser[aggregator]]) { // CHANGE MADE BY KARMA-SHARDING | ||
checkedCoverage[browser[aggregator]] = true // CHANGE MADE BY KARMA-SHARDING | ||
var coverageFailed = checkCoverage(browser, collector) | ||
checkedCoverage[browser[aggregator]] = true; // CHANGE MADE BY KARMA-SHARDING | ||
var coverageFailed = checkCoverage(browser, collector); | ||
if (coverageFailed) { | ||
if (results) { | ||
results.exitCode = 1 | ||
results.exitCode = 1; | ||
} | ||
@@ -313,13 +313,13 @@ } | ||
pendingFileWritings++ | ||
pendingFileWritings++; | ||
var mainDir = reporterConfig.dir || config.dir | ||
var subDir = reporterConfig.subdir || config.subdir | ||
var simpleOutputDir = generateOutputDir(browser.name, mainDir, subDir) | ||
var resolvedOutputDir = path.resolve(basePath, simpleOutputDir) | ||
var mainDir = reporterConfig.dir || config.dir; | ||
var subDir = reporterConfig.subdir || config.subdir; | ||
var simpleOutputDir = generateOutputDir(browser.name, mainDir, subDir); | ||
var resolvedOutputDir = path.resolve(basePath, simpleOutputDir); | ||
var outputDir = helper.normalizeWinPath(resolvedOutputDir) | ||
var outputDir = helper.normalizeWinPath(resolvedOutputDir); | ||
var sourceStore = _.isEmpty(sourceCache) ? null : new SourceCacheStore({ | ||
sourceCache: sourceCache | ||
}) | ||
}); | ||
var options = helper.merge({ | ||
@@ -331,24 +331,24 @@ sourceStore: sourceStore | ||
emitter: emitter | ||
}) | ||
var reporter = istanbul.Report.create(reporterConfig.type || 'html', options) | ||
}); | ||
var reporter = istanbul.Report.create(reporterConfig.type || 'html', options); | ||
// If reporting to console or in-memory skip directory creation | ||
var toDisk = !reporterConfig.type || !reporterConfig.type.match(/^(text|text-summary|in-memory)$/) | ||
var hasNoFile = _.isUndefined(reporterConfig.file) | ||
// If reporting to console or in-memory skip directory creation | ||
var toDisk = !reporterConfig.type || !reporterConfig.type.match(/^(text|text-summary|in-memory)$/); | ||
var hasNoFile = _.isUndefined(reporterConfig.file); | ||
if (!toDisk && hasNoFile) { | ||
writeReport(reporter, collector) | ||
return | ||
writeReport(reporter, collector); | ||
return; | ||
} | ||
helper.mkdirIfNotExists(outputDir, function () { | ||
log.debug('Writing coverage to %s', outputDir) | ||
writeReport(reporter, collector) | ||
disposeCollectors() | ||
}) | ||
}) | ||
}) | ||
log.debug('Writing coverage to %s', outputDir); | ||
writeReport(reporter, collector); | ||
disposeCollectors(); | ||
}); | ||
}); | ||
}); | ||
disposeCollectors() | ||
} | ||
disposeCollectors(); | ||
}; | ||
@@ -359,14 +359,14 @@ this.onExit = function (done) { | ||
typeof config._onExit === 'function' | ||
? (function (done) { return function () { config._onExit(done) } }(done)) | ||
: done | ||
) | ||
? (function (done) { return function () { config._onExit(done); }; }(done)) | ||
: done | ||
); | ||
} else { | ||
(typeof config._onExit === 'function' ? config._onExit(done) : done()) | ||
(typeof config._onExit === 'function' ? config._onExit(done) : done()); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
CoverageReporter.$inject = ['config', 'helper', 'logger', 'emitter'] | ||
CoverageReporter.$inject = ['config', 'helper', 'logger', 'emitter']; | ||
// PUBLISH | ||
module.exports = CoverageReporter | ||
module.exports = CoverageReporter; |
{ | ||
"name": "karma-sharding", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "Karma plugin to allow tests to be distributed across multiple browsers", | ||
@@ -14,3 +14,6 @@ "engines": { | ||
"scripts": { | ||
"test": "if [ -d './coverage' ]; then rm -rf './coverage'; fi && ./node_modules/.bin/karma start" | ||
"clean": "if [ -d './coverage' ]; then rm -rf './coverage'; fi", | ||
"karma": "./node_modules/.bin/karma start", | ||
"lint": "./node_modules/.bin/eslint --fix --config .eslintrc.json lib/\\*.js test/\\*.js index.js", | ||
"test": "npm run clean && npm run lint && npm run karma" | ||
}, | ||
@@ -56,2 +59,3 @@ "repository": { | ||
"devDependencies": { | ||
"eslint": "^4.9.0", | ||
"jasmine-core": "^2.8.0", | ||
@@ -58,0 +62,0 @@ "karma": "^1.7.1", |
# karma-sharding | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/rschuft/karma-sharding) | ||
[![npm version](https://img.shields.io/npm/v/karma-sharding.svg?style=flat-square)](https://www.npmjs.com/package/karma-sharding) | ||
[![npm downloads](https://img.shields.io/npm/dm/karma-sharding.svg?style=flat-square)](https://www.npmjs.com/package/karma-sharding) | ||
[![Build Status](https://travis-ci.org/rschuft/karma-sharding.svg?branch=master)](https://travis-ci.org/rschuft/karma-sharding) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/rschuft/karma-sharding) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/3ef0f0244485d9ca0573/maintainability)](https://codeclimate.com/github/rschuft/karma-sharding/maintainability) | ||
[![dependencies Status](https://david-dm.org/rschuft/karma-sharding/status.svg)](https://david-dm.org/rschuft/karma-sharding) | ||
[![devDependencies Status](https://david-dm.org/rschuft/karma-sharding/dev-status.svg)](https://david-dm.org/rschuft/karma-sharding?type=dev) | ||
[![optionalDependencies Status](https://david-dm.org/rschuft/karma-sharding/optional-status.svg)](https://david-dm.org/rschuft/karma-sharding?type=optional) | ||
@@ -11,0 +12,0 @@ > Karma plugin to allow tests to be distributed across multiple browsers |
35071
23
664
76
5