blanket icon indicating copy to clipboard operation
blanket copied to clipboard

support mocha transpilers

Open gregglind opened this issue 9 years ago • 13 comments

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

  • --compilers option for blanket?
  • hook deeper in mocha?

Ref code

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 avatar Jan 21 '15 22:01 gregglind

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

gregglind avatar Jan 21 '15 22:01 gregglind

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

danvk avatar Feb 11 '15 18:02 danvk

:+1:

jaredly avatar Apr 30 '15 21:04 jaredly

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.

dcousens avatar Aug 08 '15 02:08 dcousens

:+1: Same here.

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

does not work.

screendriver avatar Aug 20 '15 09:08 screendriver

+1

afreidz avatar Aug 27 '15 21:08 afreidz

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

scruffles avatar Sep 17 '15 14:09 scruffles

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.

mattdell avatar Dec 05 '15 22:12 mattdell

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.

scruffles avatar Dec 14 '15 03:12 scruffles

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

Any feedback?

kristoferjoseph avatar Jan 19 '16 22:01 kristoferjoseph

:+1: @kristoferjoseph

gh0stonio avatar Jan 30 '16 14:01 gh0stonio

+1 This would amazingly useful.

lomteslie avatar Feb 03 '16 15:02 lomteslie

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?

scruffles avatar Feb 05 '16 05:02 scruffles