Skip to content

Commit

Permalink
correct coverage for files swapped by the browser field in package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
mlrawlings committed Nov 22, 2016
1 parent c673751 commit 270ae3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"jshint": "^2.5.0",
"lasso": "^2.4.1",
"lasso-marko": "^2.1.0",
"lasso-resolve-from": "^1.2.0",
"md5-hex": "^1.3.0",
"mkdirp": "^0.5.1",
"mocha": "^2.3.3",
Expand Down
11 changes: 10 additions & 1 deletion test/browser-tests-runner/lasso-istanbul-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var fs = require('fs');
var istanbul = require('istanbul-lib-instrument');
var resolve = require('lasso-resolve-from');

module.exports = function(lasso, pluginConfig) {
var instrumenter = istanbul.createInstrumenter();
Expand All @@ -15,7 +17,14 @@ module.exports = function(lasso, pluginConfig) {
|| file.includes('benchmark/')
) return code;

return instrumenter.instrumentSync(code, context.dependency.file);
if(context.dependency.type === 'commonjs-def') {
var unwrappedCode = code.replace(/^\$\_mod[^\n]+?\{ /, '').replace(/\n\}\);$/, '');
}

var actualFile = resolve(__dirname, file).path;
var instrumentedCode = instrumenter.instrumentSync(unwrappedCode || code, actualFile);

return unwrappedCode ? code.replace(unwrappedCode, instrumentedCode) : instrumentedCode;
}
});
}

0 comments on commit 270ae3d

Please sign in to comment.