From b47835b4c26a27187f983804c77bec16b04a4826 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 6 Jul 2016 23:38:09 -0700 Subject: [PATCH] drop jsoncov/htmlcov reporters; closes #2356 --- .gitignore | 2 - Makefile | 17 +- index.js | 6 +- karma.conf.js | 2 - lib/reporters/html-cov.js | 56 ----- lib/reporters/index.js | 2 - lib/reporters/json-cov.js | 152 ------------- lib/reporters/templates/coverage.pug | 51 ----- lib/reporters/templates/menu.pug | 13 -- lib/reporters/templates/script.html | 34 --- lib/reporters/templates/style.html | 324 --------------------------- package.json | 2 - 12 files changed, 5 insertions(+), 656 deletions(-) delete mode 100644 lib/reporters/html-cov.js delete mode 100644 lib/reporters/json-cov.js delete mode 100644 lib/reporters/templates/coverage.pug delete mode 100644 lib/reporters/templates/menu.pug delete mode 100644 lib/reporters/templates/script.html delete mode 100644 lib/reporters/templates/style.html diff --git a/.gitignore b/.gitignore index cc19425077..943d6ace8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -coverage.html -lib-cov .DS_Store node_modules test-outputs diff --git a/Makefile b/Makefile index 31365aaf51..5f4f67416b 100644 --- a/Makefile +++ b/Makefile @@ -15,26 +15,13 @@ mocha.js: $(SRC) $(SUPPORT) @$(BROWSERIFY) ./browser-entry \ --ignore 'fs' \ --ignore 'glob' \ - --ignore 'jade' \ --ignore 'path' \ - --ignore 'supports-color' \ - --exclude './lib-cov/mocha' > $@ + --ignore 'supports-color' > $@ clean: @printf "==> [Clean]\n" rm -f mocha.js rm -rf test-outputs - rm -rf lib-cov - rm -f coverage.html - -test-cov: lib-cov - @printf "==> [Test :: Coverage]\n" - @COV=1 $(MAKE) test REPORTER=html-cov > coverage.html - -lib-cov: - @printf "==> [Coverage]\n" - @rm -fr ./$@ - @jscoverage lib $@ lint: @printf "==> [Test :: Lint]\n" @@ -204,4 +191,4 @@ tm: @printf "==> [TM]\n" @open editors/$(TM_BUNDLE) -.PHONY: test-cov test-jsapi test-compilers watch test test-node test-bdd test-tdd test-qunit test-exports test-unit test-integration non-tty tm clean test-browser test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports lint test-only test-global-only +.PHONY: test-jsapi test-compilers watch test test-node test-bdd test-tdd test-qunit test-exports test-unit test-integration non-tty tm clean test-browser test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports lint test-only test-global-only diff --git a/index.js b/index.js index 169b271770..d2b7d19609 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -module.exports = process.env.COV - ? require('./lib-cov/mocha') - : require('./lib/mocha'); +'use strict'; + +module.exports = require('./lib/mocha'); diff --git a/karma.conf.js b/karma.conf.js index 704aab026e..757be725a4 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -31,9 +31,7 @@ module.exports = function(config) { debug: true, configure: function configure(b) { b.ignore('glob') - .ignore('pug') .ignore('supports-color') - .exclude('./lib-cov/mocha') .on('bundled', function(err, content) { if (!err && bundleDirpath) { // write bundle to directory for debugging diff --git a/lib/reporters/html-cov.js b/lib/reporters/html-cov.js deleted file mode 100644 index 8c6bac4d72..0000000000 --- a/lib/reporters/html-cov.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Module dependencies. - */ - -var JSONCov = require('./json-cov'); -var readFileSync = require('fs').readFileSync; -var join = require('path').join; - -/** - * Expose `HTMLCov`. - */ - -exports = module.exports = HTMLCov; - -/** - * Initialize a new `JsCoverage` reporter. - * - * @api public - * @param {Runner} runner - */ -function HTMLCov(runner) { - var pug = require('pug'); - var file = join(__dirname, '/templates/coverage.pug'); - var str = readFileSync(file, 'utf8'); - var fn = pug.compile(str, { filename: file }); - var self = this; - - JSONCov.call(this, runner, false); - - runner.on('end', function() { - process.stdout.write(fn({ - cov: self.cov, - coverageClass: coverageClass - })); - }); -} - -/** - * Return coverage class for a given coverage percentage. - * - * @api private - * @param {number} coveragePctg - * @return {string} - */ -function coverageClass(coveragePctg) { - if (coveragePctg >= 75) { - return 'high'; - } - if (coveragePctg >= 50) { - return 'medium'; - } - if (coveragePctg >= 25) { - return 'low'; - } - return 'terrible'; -} diff --git a/lib/reporters/index.js b/lib/reporters/index.js index 51f5cffee1..221a81d95b 100644 --- a/lib/reporters/index.js +++ b/lib/reporters/index.js @@ -14,6 +14,4 @@ exports.XUnit = exports.xunit = require('./xunit'); exports.Markdown = exports.markdown = require('./markdown'); exports.Progress = exports.progress = require('./progress'); exports.Landing = exports.landing = require('./landing'); -exports.JSONCov = exports['json-cov'] = require('./json-cov'); -exports.HTMLCov = exports['html-cov'] = require('./html-cov'); exports.JSONStream = exports['json-stream'] = require('./json-stream'); diff --git a/lib/reporters/json-cov.js b/lib/reporters/json-cov.js deleted file mode 100644 index a1ead3728c..0000000000 --- a/lib/reporters/json-cov.js +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Module dependencies. - */ - -var Base = require('./base'); -var JSON = require('json3'); - -/** - * Expose `JSONCov`. - */ - -exports = module.exports = JSONCov; - -/** - * Initialize a new `JsCoverage` reporter. - * - * @api public - * @param {Runner} runner - * @param {boolean} output - */ -function JSONCov(runner, output) { - Base.call(this, runner); - - output = arguments.length === 1 || output; - var self = this; - var tests = []; - var failures = []; - var passes = []; - - runner.on('test end', function(test) { - tests.push(test); - }); - - runner.on('pass', function(test) { - passes.push(test); - }); - - runner.on('fail', function(test) { - failures.push(test); - }); - - runner.on('end', function() { - var cov = global._$jscoverage || {}; - var result = self.cov = map(cov); - result.stats = self.stats; - result.tests = tests.map(clean); - result.failures = failures.map(clean); - result.passes = passes.map(clean); - if (!output) { - return; - } - process.stdout.write(JSON.stringify(result, null, 2)); - }); -} - -/** - * Map jscoverage data to a JSON structure - * suitable for reporting. - * - * @api private - * @param {Object} cov - * @return {Object} - */ - -function map(cov) { - var ret = { - instrumentation: 'node-jscoverage', - sloc: 0, - hits: 0, - misses: 0, - coverage: 0, - files: [] - }; - - for (var filename in cov) { - if (Object.prototype.hasOwnProperty.call(cov, filename)) { - var data = coverage(filename, cov[filename]); - ret.files.push(data); - ret.hits += data.hits; - ret.misses += data.misses; - ret.sloc += data.sloc; - } - } - - ret.files.sort(function(a, b) { - return a.filename.localeCompare(b.filename); - }); - - if (ret.sloc > 0) { - ret.coverage = (ret.hits / ret.sloc) * 100; - } - - return ret; -} - -/** - * Map jscoverage data for a single source file - * to a JSON structure suitable for reporting. - * - * @api private - * @param {string} filename name of the source file - * @param {Object} data jscoverage coverage data - * @return {Object} - */ -function coverage(filename, data) { - var ret = { - filename: filename, - coverage: 0, - hits: 0, - misses: 0, - sloc: 0, - source: {} - }; - - data.source.forEach(function(line, num) { - num++; - - if (data[num] === 0) { - ret.misses++; - ret.sloc++; - } else if (data[num] !== undefined) { - ret.hits++; - ret.sloc++; - } - - ret.source[num] = { - source: line, - coverage: data[num] === undefined ? '' : data[num] - }; - }); - - ret.coverage = ret.hits / ret.sloc * 100; - - return ret; -} - -/** - * Return a plain-object representation of `test` - * free of cyclic properties etc. - * - * @api private - * @param {Object} test - * @return {Object} - */ -function clean(test) { - return { - duration: test.duration, - currentRetry: test.currentRetry(), - fullTitle: test.fullTitle(), - title: test.title - }; -} diff --git a/lib/reporters/templates/coverage.pug b/lib/reporters/templates/coverage.pug deleted file mode 100644 index edd59d8864..0000000000 --- a/lib/reporters/templates/coverage.pug +++ /dev/null @@ -1,51 +0,0 @@ -doctype html -html - head - title Coverage - meta(charset='utf-8') - include script.html - include style.html - body - #coverage - h1#overview Coverage - include menu - - #stats(class=coverageClass(cov.coverage)) - .percentage #{cov.coverage | 0}% - .sloc= cov.sloc - .hits= cov.hits - .misses= cov.misses - - #files - for file in cov.files - .file - h2(id=file.filename)= file.filename - #stats(class=coverageClass(file.coverage)) - .percentage #{file.coverage | 0}% - .sloc= file.sloc - .hits= file.hits - .misses= file.misses - - table#source - thead - tr - th Line - th Hits - th Source - tbody - for line, number in file.source - if line.coverage > 0 - tr.hit - td.line= number - td.hits= line.coverage - td.source= line.source - else if 0 === line.coverage - tr.miss - td.line= number - td.hits 0 - td.source= line.source - else - tr - td.line= number - td.hits - td.source= line.source || ' ' diff --git a/lib/reporters/templates/menu.pug b/lib/reporters/templates/menu.pug deleted file mode 100644 index c682e3f0ee..0000000000 --- a/lib/reporters/templates/menu.pug +++ /dev/null @@ -1,13 +0,0 @@ -#menu - li - a(href='#overview') overview - for file in cov.files - li - span.cov(class=coverageClass(file.coverage)) #{file.coverage | 0} - a(href='##{file.filename}') - segments = file.filename.split('/') - basename = segments.pop() - if segments.length - span.dirname= segments.join('/') + '/' - span.basename= basename - a#logo(href='http://mochajs.org/') m diff --git a/lib/reporters/templates/script.html b/lib/reporters/templates/script.html deleted file mode 100644 index 073cf7939c..0000000000 --- a/lib/reporters/templates/script.html +++ /dev/null @@ -1,34 +0,0 @@ - diff --git a/lib/reporters/templates/style.html b/lib/reporters/templates/style.html deleted file mode 100644 index 4c9c37cfd9..0000000000 --- a/lib/reporters/templates/style.html +++ /dev/null @@ -1,324 +0,0 @@ - diff --git a/package.json b/package.json index 2a284eb289..cd1850783d 100644 --- a/package.json +++ b/package.json @@ -311,7 +311,6 @@ "json3": "3.3.2", "lodash.create": "3.1.1", "mkdirp": "0.5.1", - "pug": "2.0.0-beta3", "supports-color": "3.1.2", "to-iso-string": "0.0.2" }, @@ -349,7 +348,6 @@ "events": "./lib/browser/events.js", "tty": "./lib/browser/tty.js", "./index.js": "./browser-entry.js", - "pug": false, "fs": false, "glob": false, "path": false,