Skip to content

Commit

Permalink
Try using browser tests as integration testing for browser-entry.js
Browse files Browse the repository at this point in the history
… by covering it in the `BUILDTMP/mocha.js` bundle
  • Loading branch information
ScottFreeCode committed Aug 2, 2017
1 parent afd632a commit d3aab5f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
26 changes: 18 additions & 8 deletions Makefile
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions 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));
};
10 changes: 2 additions & 8 deletions karma.conf.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 16 additions & 0 deletions 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)); } };

0 comments on commit d3aab5f

Please sign in to comment.