jeffrifwald / babel-istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
144 stars 23 forks source link

[added] a `--babel-config` CLI option - a configurable alternative to .babelrc #39

Closed thealjey closed 8 years ago

thealjey commented 8 years ago

The --babel-config CLI option lets you set a specific configuration file to use for babel. It's an alternative to .babelrc, but it can be located anywhere, so one does not have to rely on Babel searching the file system for it. Supports .yaml, .yml, .json and .js files.

jeffrifwald commented 8 years ago

Just had one comment @thealjey

thealjey commented 8 years ago

@jmcriffey please check now

jeffrifwald commented 8 years ago

Cool, LGTM. Thanks!

danjford commented 8 years ago

Is there an example / documentation of how we can use this? Is it an option that we can add to the istanbul.yml? I can't seem to get it working with something like this in the terminal: ./node_modules/.bin/babel-istanbul --babel-config conf/babel.json

thealjey commented 8 years ago

@danjford --babel-config is a CLI option, you specify it like so: --babel-config conf/babel.json or --babel-config conf/babel.yml or --babel-config conf/babel.js The configuration object is passed directly to Babel. What you need to check is the version of Babel that babel-istanbul uses and whether or not the configuration you provide to it is supported by that version of Babel.

What do you mean it's not working, does it not do anything or do you see an error? What are the contents of conf/babel.json?

danjford commented 8 years ago

I tried using the command ./node_modules/.bin/babel-istanbul --babel-config conf/babel.json cover ./node_modules/mocha/bin/_mocha to cover my mocha tests. In this case it gave an error saying that conf/babel.json wasn't a command.

image

My babel.json contained:

{
  "presets": [ "es2015" ]
}

The reason I was trying to change where the babel configurations were due to having a conflict with another library that didn't want "presets": [ "es2015" ] in the .babelrc.

As I couldn't get the --babel-config option working with babel-istanbul I've just put a work around into the .babelrc so that it doesn't conflict with the other library. The work around I've done is specified the environment in the .babelrc file as tests so that when I run the tests I just set NODE_ENV=tests, which means the conflicting library will not read the presets.

thealjey commented 8 years ago

@danjford duh, try this babel-istanbul cover --babel-config conf/babel.json ./node_modules/mocha/bin/_mocha babel-istanbul needs a command first, that's why it told you that it wasn't a valid "command" :smiley_cat:

danjford commented 8 years ago

Running ./node_modules/.bin/babel-istanbul would be the same as babel-istanbul except one is installed to a project and the other is installed globally :p

I'm looking back and I've tried replicating the issue but for some reason the command that I mentioned in the previous comment works now... so never mind lol :+1:

thealjey commented 8 years ago

@danjford, that's not the point, you noticed that there's babel-istanbul instead of ./node_modules/.bin/babel-istanbul (which is basically the same fking thing), but you didn't notice that cover was right after it. That's the reason :laughing:

danjford commented 8 years ago

Ah my mistake, I think it's actually that I left out the = as it would work as ./node_modules/.bin/babel-istanbul --babel-config=conf/babel.json cover ./node_modules/mocha/bin/_mocha.