From 58e4b5d93feeb6f8ff3e24dd27d7a9d7a4889fd6 Mon Sep 17 00:00:00 2001 From: ScottFreeCode Date: Sun, 18 Jun 2017 02:22:12 -0400 Subject: [PATCH] Try using browser tests as integration testing for `browser-entry.js` by covering it in the `BUILDTMP/mocha.js` bundle --- Makefile | 26 ++++++++++++++++++-------- instrumentBrowserEntry.js | 11 +++++++++++ karma.conf.js | 10 ++-------- nycInstrumenter.js | 16 ++++++++++++++++ 4 files changed, 47 insertions(+), 16 deletions(-) create mode 100644 instrumentBrowserEntry.js create mode 100644 nycInstrumenter.js diff --git a/Makefile b/Makefile index 2fa367e8ff..fcd4c3f60a 100644 --- a/Makefile +++ b/Makefile @@ -7,25 +7,35 @@ ifdef COVERAGE define test_node $(NYC) --report-dir coverage/reports/$(1) $(MOCHA) endef + instrument_browser := -t ./instrumentBrowserEntry else test_node := $(MOCHA) endif +define bundle_command + $(BROWSERIFY) ./browser-entry \ + $(1) \ + --plugin ./scripts/dedefine \ + --ignore 'fs' \ + --ignore 'glob' \ + --ignore 'path' \ + --ignore 'supports-color' > $@ +endef + TM_BUNDLE = JavaScript\ mocha.tmbundle SRC = $(shell find lib -name "*.js" -type f | LC_ALL=C sort) TESTS = $(shell find test -name "*.js" -type f | sort) all: mocha.js -mocha.js BUILDTMP/mocha.js: $(SRC) browser-entry.js - @printf "==> [Browser :: build]\n" +mocha.js: $(SRC) browser-entry.js + @printf "==> [Browser :: Build]\n" + $(call bundle_command) + +BUILDTMP/mocha.js: $(SRC) browser-entry.js + @printf "==> [Browser :: Build :: Test]\n" mkdir -p ${@D} - $(BROWSERIFY) ./browser-entry \ - --plugin ./scripts/dedefine \ - --ignore 'fs' \ - --ignore 'glob' \ - --ignore 'path' \ - --ignore 'supports-color' > $@ + $(call bundle_command,$(instrument_browser)) clean: @printf "==> [Clean]\n" diff --git a/instrumentBrowserEntry.js b/instrumentBrowserEntry.js new file mode 100644 index 0000000000..2e53dc08af --- /dev/null +++ b/instrumentBrowserEntry.js @@ -0,0 +1,11 @@ +'use strict'; + +var browserifyIstanbul = require('browserify-istanbul'); + +var nyc = require('./nycInstrumenter'); + +var overrideOptions = { ignore: ['**/lib/**', '**/node_modules/**', '**/test/**'], instrumenter: nyc }; + +module.exports = function (file, options) { + return browserifyIstanbul(file, Object.assign({}, options, overrideOptions)); +}; diff --git a/karma.conf.js b/karma.conf.js index b58ffbdc85..a95fd321d8 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -6,13 +6,7 @@ var mkdirp = require('mkdirp'); var baseBundleDirpath = path.join(__dirname, '.karma'); var osName = require('os-name'); var workaroundMultiplePreprocessorIncompatibility = require('browserify-istanbul'); -var istanbulLib; -try { - istanbulLib = require('nyc/node_modules/istanbul-lib-instrument'); -} catch (ignore) { - istanbulLib = require('istanbul-lib-instrument'); -} -var nyc = { Instrumenter: function (options) { return istanbulLib.createInstrumenter(options); } }; +var nyc = require('./nycInstrumenter'); module.exports = function (config) { var bundleDirpath; @@ -162,7 +156,7 @@ module.exports = function (config) { subdir: '.', includeAllSources: true }; - cfg.browserify.transform = [ workaroundMultiplePreprocessorIncompatibility({ ignore: ['**/node_modules/**', '**/test/**'], instrumenter: nyc, instrumenterConfig: { autoWrap: true, embedSource: true, produceSourceMap: true, noCompact: false } }) ]; + cfg.browserify.transform = [ workaroundMultiplePreprocessorIncompatibility({ ignore: ['**/node_modules/**', '**/test/**'], instrumenter: nyc }) ]; console.error('Reporting coverage to ' + cfg.coverageReporter.dir); } diff --git a/nycInstrumenter.js b/nycInstrumenter.js new file mode 100644 index 0000000000..ca3da3952c --- /dev/null +++ b/nycInstrumenter.js @@ -0,0 +1,16 @@ +'use strict'; + +var defaultOptions = { + autoWrap: true, + embedSource: true, + produceSourceMap: true, + noCompact: false +}; + +var istanbulLib; +try { + istanbulLib = require('nyc/node_modules/istanbul-lib-instrument'); +} catch (ignore) { + istanbulLib = require('istanbul-lib-instrument'); +} +module.exports = { Instrumenter: function (options) { return istanbulLib.createInstrumenter(Object.assign({}, defaultOptions, options)); } };