-
-
Notifications
You must be signed in to change notification settings - Fork 361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for configurable file extensions #163
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function probe () {} | ||
|
||
// When instrumented there will be references to variables like | ||
// __cov_pwkoI2PYHp3LJXkn_erl1Q in the probe() source. | ||
module.exports = function () { | ||
return /\b__cov_\B/.test(probe + '') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function probe () {} | ||
|
||
// When instrumented there will be references to variables like | ||
// __cov_pwkoI2PYHp3LJXkn_erl1Q in the probe() source. | ||
module.exports = function () { | ||
return /\b__cov_\B/.test(probe + '') | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
"exclude": [ | ||
"**/blarg", | ||
"**/blerg" | ||
] | ||
], | ||
"extension": [".es6", ".foo.BAR"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Until it is easier to use opts over package.json config, I mixed the casing here a bit to test case-insensitive extension matching. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,22 @@ describe('nyc', function () { | |
|
||
nyc.exclude.length.should.eql(19) | ||
}) | ||
|
||
it("loads 'extension' patterns from package.json#config.nyc", function () { | ||
var nyc = new NYC({ | ||
cwd: path.resolve(__dirname, '../fixtures') | ||
}) | ||
|
||
nyc.extensions.length.should.eql(3) | ||
}) | ||
|
||
it("loads 'extension' from package.json#nyc", function () { | ||
var nyc = new NYC({ | ||
cwd: path.resolve(__dirname, '../..') | ||
}) | ||
|
||
nyc.extensions.length.should.eql(2) | ||
}) | ||
}) | ||
|
||
describe('_prepGlobPatterns', function () { | ||
|
@@ -232,6 +248,42 @@ describe('nyc', function () { | |
}) | ||
}) | ||
|
||
describe('compile handlers for custom extensions are assigned', function () { | ||
it('assigns a function to custom extensions', function () { | ||
var nyc = new NYC({ | ||
cwd: path.resolve(__dirname, '../fixtures') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the |
||
}) | ||
nyc.reset() | ||
nyc.wrap() | ||
|
||
require.extensions['.es6'].should.be.a.function | ||
require.extensions['.foo.bar'].should.be.a.function | ||
|
||
// default should still exist | ||
require.extensions['.js'].should.be.a.function | ||
}) | ||
|
||
it('calls the `_handleJs` function for custom file extensions', function () { | ||
// the `require` call to istanbul is deferred, loaded here so it doesn't mess with the hooks callCount | ||
require('istanbul') | ||
|
||
var nyc = new NYC({ | ||
cwd: path.resolve(__dirname, '../fixtures') | ||
}) | ||
|
||
sinon.spy(nyc, '_handleJs') | ||
|
||
nyc.reset() | ||
nyc.wrap() | ||
|
||
var check1 = require('../fixtures/check-instrumented.es6') | ||
var check2 = require('../fixtures/check-instrumented.foo.bar') | ||
check1().should.be.true | ||
check2().should.be.true | ||
nyc._handleJs.callCount.should.equal(2) | ||
}) | ||
}) | ||
|
||
function testSignal (signal, done) { | ||
var nyc = (new NYC({ | ||
cwd: fixtures | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking you could iterate over
this.extensions
here, though we're veering quite far into premature optimization land.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree - it's more concise in the code to just use
for...in
. And in most cases I would think we would have 2 or 3 extensions to iterate through at the most. Yes it could be many files, but still I think it has to get into the 100s of thousands before any noticeable difference betweenfor..in
andfor
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not making a ext => transform object/Map?