Skip to content
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

Merged
merged 1 commit into from
Feb 13, 2016

Conversation

lloydcotten
Copy link
Contributor

This adds support for allowing files with extensions other than '.js' to be covered. It can be configured through package.json config, or command line args.

As per my comment in issue #161 (comment), there aren't any additional tests yet. If you feel some additional tests to cover this functionality would be helpful, I'd appreciate some guidance as to how you think they could be done (I'm not quite used to the way the existing tests are done). Even just pointing me to existing tests that I could pattern after, would be great.

I'd be glad to address any other comments also.

appendTransform(handleJs)

this.extensions.forEach(function (ext) {
require.extensions[ext] = require.extensions['.js']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use default-require-extensions here? Just in case require.extensions['.js'] has been messed with already by some other module?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to use this.

@novemberborn
Copy link
Contributor

The new extensions are pointed to .js. This assumes files with those new extensions can be treated as .js, right? E.g. it wouldn't add support for CoffeeScript or TypeScript.

@@ -212,7 +217,14 @@ NYC.prototype._maybeInstrumentSource = function (code, filename, relFile) {
return null
}

return this.transform(code, {filename: filename, relFile: relFile})
var ext = path.extname(filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that extname only returns the last extension. Looping through the registered transforms to see if they match the filename would let us support .foo.bar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to use the Array filter function to find matching extensions.

@bcoe
Copy link
Member

bcoe commented Feb 9, 2016

@lloydcotten would it be possible to add a test for this functionality? I differ to @jamestalmage and @novemberborn's other comments -- they've become the subject matter experts on the codebases that facilitate the extension overrides.

@lloydcotten
Copy link
Contributor Author

@novemberborn This would not support CoffeeScript or TypeScript. We would have to somehow allow custom hooks to be added. Wouldn't that work the same way as it already does for Babel anyway?

@lloydcotten
Copy link
Contributor Author

@bcoe I took some time today to try to figure out the best way to add some tests around this. I've taken a stab at it. Not sure if it's accomplished the best way possible, but the functionality is covered and passes.

Any feedback is welcome. I'll be glad to try to refactor anything. Once every one is OK with it, I'll squash the commits. I'm removing the [WIP] tag.

@lloydcotten
Copy link
Contributor Author

  • Squash commits

@lloydcotten lloydcotten changed the title [WIP] Add support for configurable file extensions Add support for configurable file extensions Feb 9, 2016
@@ -53,7 +54,12 @@ function NYC (opts) {
// require extensions can be provided as config in package.json.
this.require = arrify(config.require || opts.require)

this.transform = this._createTransform()
this.extensions = arrify(config.extensions || opts.extension)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should access config.extension I think. Like --require results in opts.require and config.require, so should --extension.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add .js onto this.extensions. That way you can use it in _maybeInstrumentSource(). Could also map it to ensure all extensions are lowercased.

@novemberborn
Copy link
Contributor

@lloydcotten

This would not support CoffeeScript or TypeScript. We would have to somehow allow custom hooks to be added. Wouldn't that work the same way as it already does for Babel anyway?

I'm not sure really. Not the end of the world if that doesn't work right away.

I took some time today to try to figure out the best way to add some tests around this. I've taken a stab at it. Not sure if it's accomplished the best way possible, but the functionality is covered and passes.

Tests look pretty good! Should test with multiple extensions since there is looping logic. The case insensitive matching needs covering as well.

@lloydcotten
Copy link
Contributor Author

@novemberborn I updated the PR with some refactoring based on your comments. When I hear your feedback on my question about the tests, I'll modify the tests as necessary and add one to cover case insensitive matching.

@@ -53,7 +54,14 @@ function NYC (opts) {
// require extensions can be provided as config in package.json.
this.require = arrify(config.require || opts.require)

this.transform = this._createTransform()
this.extensions = arrify(config.extension || opts.extension).concat(['.js']).map(function (ext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can concat with strings. In other words concat('.js') is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha - learn something new every day. I did not know that.

@novemberborn
Copy link
Contributor

@lloydcotten nice work so far! We can clean up the main package.json later I think, and let's discuss opts over config separately.

@@ -12,7 +12,8 @@
"exclude": [
"**/blarg",
"**/blerg"
]
],
"extension": [".es6", ".foo.BAR"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@bcoe
Copy link
Member

bcoe commented Feb 11, 2016

@lloydcotten thanks for the hard work, I've been swamped this week but will get a release out Saturday.

@novemberborn
Copy link
Contributor

@lloydcotten this is great, thanks!

Looks like your PR now contains some duplicate commits that are already in bcoe:master though.

@lloydcotten
Copy link
Contributor Author

@bco, @novemberborn you're welcome. Thanks for the cooperation and feedback on the PR.

Not sure why the duplicate commits - must've goofed with my squash somehow. I'll take a look.

@lloydcotten
Copy link
Contributor Author

OK - I've cleaned up the commit history. Should be good to go now. Let me know if you need anything else on this PR.

bcoe added a commit that referenced this pull request Feb 13, 2016
Add support for configurable file extensions
@bcoe bcoe merged commit db17eec into istanbuljs:master Feb 13, 2016
@bcoe
Copy link
Member

bcoe commented Feb 13, 2016

@lloydcotten thanks for the wonderful contribution \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants