Skip to content

Commit

Permalink
fix: pass correct args to tranformer (#153) (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkir authored and bcoe committed Mar 31, 2018
1 parent 6d89cca commit 2b2250f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/istanbul-lib-hook/lib/hook.js
Expand Up @@ -26,7 +26,7 @@ function transformFn(matcher, transformer, verbose) {
console.error('Module load hook: transform [' + options.filename + ']');
}
try {
transformed = transformer(code, options);
transformed = transformer(code, options.filename);
changed = true;
} catch (ex) {
console.error('Transformation error for', options.filename, '; return original code');
Expand Down
14 changes: 14 additions & 0 deletions packages/istanbul-lib-hook/test/hook.test.js
@@ -1,6 +1,7 @@
/* globals describe, it, beforeEach, afterEach */
var hook = require('../lib/hook'),
assert = require('chai').assert,
path = require('path'),
currentHook,
matcher = function (file) {
return file.indexOf('foo.js') > 0;
Expand Down Expand Up @@ -44,6 +45,19 @@ describe('hooks', function () {
assert.equal(foo.bar(), 'bar');
});

it('calls the transformer with the correct args', function () {
var transformerArgs;
function transformerStub() {
transformerArgs = arguments;
return '';
}
hookIt(matcher, transformerStub, {verbose: true});
require('./data/foo');
assert.ok(transformerArgs);
assert.equal(typeof transformerArgs[0], 'string');
assert.equal(transformerArgs[1], path.resolve(__dirname, './data/foo.js'));
});

it('skips baz', function () {
var foo = require('./data/baz');
assert.ok(foo.baz);
Expand Down

0 comments on commit 2b2250f

Please sign in to comment.