2020-11-29 00:14

support mocha transpilers


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


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);


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39903375 weixin_39903375 5月前

    +1 This would amazingly useful.

    点赞 评论 复制链接分享
  • weixin_39543758 weixin_39543758 5月前

    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?

    点赞 评论 复制链接分享
  • weixin_39778815 weixin_39778815 5月前

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

    点赞 评论 复制链接分享
  • weixin_39610353 weixin_39610353 5月前

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

    点赞 评论 复制链接分享
  • weixin_39597399 weixin_39597399 5月前


    点赞 评论 复制链接分享
  • weixin_39699670 weixin_39699670 5月前

    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.

    点赞 评论 复制链接分享
  • weixin_39803552 weixin_39803552 5月前

    :+1: Same here.

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

    does not work.

    点赞 评论 复制链接分享
  • weixin_39922004 weixin_39922004 5月前


    点赞 评论 复制链接分享
  • weixin_39543758 weixin_39543758 5月前

    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

    点赞 评论 复制链接分享
  • weixin_39629075 weixin_39629075 5月前

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

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

    点赞 评论 复制链接分享
  • weixin_39543758 weixin_39543758 5月前

    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.

    点赞 评论 复制链接分享
  • weixin_39622891 weixin_39622891 5月前

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

    Any feedback?

    点赞 评论 复制链接分享
  • weixin_39754915 weixin_39754915 5月前


    点赞 评论 复制链接分享