alex-seville / blanket

blanket.js is a simple code coverage library for javascript. Designed to be easy to install and use, for both browser and nodejs.
http://blanketjs.org
Other
1.41k stars 179 forks source link

support mocha transpilers #469

Open gregglind opened 9 years ago

gregglind commented 9 years ago

Goal

Transpiled code should be covered, either in original or transpiled forms. (SO THAT things like react-jsx, es6 will work)

node ./node_modules/mocha/bin/mocha  -r blanket  --compilers js:mocha-traceur test/blanketed.js

implementation ideas

https://github.com/mochajs/mocha/blob/master/bin/_mocha#L292-L301

var extensions = ['js'];
program.compilers.forEach(function(c) {
  var compiler = c.split(':')
  , ext = compiler[0]
  , mod = compiler[1];
  if (mod[0] == '.') mod = join(process.cwd(), mod);
  require(mod);
  extensions.push(ext);
    program.watchExtensions.push(ext);
});
gregglind commented 9 years ago

(working on a custom loader, based on the coffee script one at: https://gist.github.com/a6e636742a04274a9bf1 )

danvk commented 9 years ago

This would be great. I've done something similar to hack in JSX/Harmony support w/ blanket here.

jaredly commented 9 years ago

:+1:

dcousens commented 8 years ago

Any further work on this? I'm currently trying to use blanket like this:

mocha --compilers js:babel/register --require blanket

And naturally esprima is exploding pretty quickly.

screendriver commented 8 years ago

:+1: Same here.

mocha --compilers js:babel/register --require blanket test/*.js*

does not work.

afreidz commented 8 years ago

+1

scruffles commented 8 years ago

looks similar to the pull request I made to add multiple loader support and a CXJS loader: https://github.com/alex-seville/blanket/pull/523 after extracting some common functionality, new loaders become much easier: https://github.com/scruffles/blanket/blob/208230900d43d50c7a71b30d5f74445cfae7423a/src/node-loaders/cjsx.js

mattdell commented 8 years ago

I'm having the same problem as @dcousens. React + ES6 just won't happen with blanket.

I've been through the mocha-react repo but I still can't figure this out.

scruffles commented 8 years ago

currently there is no command line switch that will add support for a loader, but you can add support for a loader with 12 lines of code. Just copy and alter this file, and configure it like this:

  "config": {
    "blanket": {
      "loader": "../../../test/cjsx-loader"
    }
  },

I haven't tried JSX, but it works fine with CJSX.

It seems like extending it further to support the command line syntax suggested above shouldn't take too much work. If someone does implement that, please send a pull request to Alex, so we can all benefit.

kristoferjoseph commented 8 years ago

Would be sweet if you could just do this: mocha --compilers js:babel/register --require blanket --reporter html-cov > coverage.html

Any feedback?

gh0stonio commented 8 years ago

:+1: @kristoferjoseph

lomteslie commented 8 years ago

+1 This would amazingly useful.

scruffles commented 8 years ago

I have a local implementation that preserves backwards compatibility. You still have to apply a loader in your config:

  "config": {
    "blanket": {
      "loader": ["./node-loaders/dynamic-loader"]

After that, it just wraps all the existing mocha loaders and instruments those files that fit the filters. The coverage report still shows the transpiled javascript. I didn't mess with any of the fundamentals. Just introduced a new loader.

I could make it the default loader. Also, as far as I can tell the existing loader concept could go away completely. I didn't want to do any more work until I was sure I wasn't wasting my time. Should I submit a pull request as it is now and weed out the loader concept in a separate request? Is this the direction the project should go?