how to pass compiler options to mocha

后端 未结 3 771
执笔经年
执笔经年 2021-02-13 06:23

I run a mocha command to run my tests

$ ./node_modules/.bin/mocha --compilers coffee:coffee-script -R spec

I wish to pass additional options t

3条回答
  •  抹茶落季
    2021-02-13 07:00

    The --compiler option doesn't support this, but you can write a script which activates the compiler with your options, then use mocha's --require option to activate your registration script. For example, create a file at the root of the project called babelhook.js:

    // This file is required in mocha.opts
    // The only purpose of this file is to ensure
    // the babel transpiler is activated prior to any
    // test code, and using the same babel options
    
    require("babel-register")({
      experimental: true
    });
    

    Then add this to mocha.opts:

    --require babelhook
    

    And that's it. Mocha will require babelhook.js before any tests.

提交回复
热议问题