Cannot run Mocha with CoffeeScript

前端 未结 6 1435
感动是毒
感动是毒 2020-12-14 00:02

Makefile - Content:

REPORTER = dot

all: build

build:
    @./node_modules/coffee-script/bin/coffee \\
        -c \\
        -o lib src

clean:
    rm -rf li         


        
相关标签:
6条回答
  • 2020-12-14 00:46

    Apparently, a change in Mocha made in April 2018 (softly) deprecated the --compilers option. In the command line you now get:

    (node:27864) DeprecationWarning: "--compilers" will be removed in a future version of Mocha; see https://git.io/vdcSr for more info

    Like the link says, this can easily be fixed by just not using --compilers and using this new (simplified) mocha.opts options:

    --require coffeescript/register
    
    test/*.coffee
    

    The last line is needed to make Mocha understand it should now use *.coffee files as test files. This seems not to be covered with the --require option.

    0 讨论(0)
  • 2020-12-14 00:46

    I needed two changes to my mocha args to get this to work:

    --require coffee-script/register
    --compilers coffee:coffee-script/register
    
    0 讨论(0)
  • 2020-12-14 00:57

    As of Mocha 1.0:

    coffee-script is no longer supported out of the box. CS and similar transpilers may be used by mapping the file extensions (for use with --watch) and the module name. For example --compilers coffee:coffee-script with CoffeeScript 1.6- or --compilers coffee:coffee-script/register with CoffeeScript 1.7+.

    (Quoting http://visionmedia.github.io/mocha/#compilers-option) So, you need to add the line

    --compilers coffee:coffee-script/register
    

    or, for CS <= 1.6.x,

    --compilers coffee:coffee-script
    

    to your mocha.opts file.

    0 讨论(0)
  • 2020-12-14 01:02

    From CoffeeScript 1.7 onwards, the option should be:

    --compilers coffee:coffee-script/register
    

    An issue was filed on Mocha's github site.

    0 讨论(0)
  • 2020-12-14 01:02

    with the latest update of mocha the the require statement must written in package.json file as

      "mocha":{
        "require":"coffeescript",
        "reporter":"spec"
      },
    
    0 讨论(0)
  • 2020-12-14 01:07

    mocha --require coffeescript/register

    Source: https://github.com/mochajs/mocha/wiki/compilers-deprecation

    0 讨论(0)
提交回复
热议问题