我有用ES6编写的Node代码,可以通过发出mocha --harmony进行测试。
测试很好-一切正常。

现在,我想将coverage和istanbul添加到混合中,但是在遇到的第一个箭头函数上,我不断出错:

No coverage information was collected, exit without writing coverage information
c:\Users\Guy\Code\alpha-dev\tests\helpers.js:12
    setTimeout(() => {
                ^
SyntaxError: Unexpected token )
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Module._extensions..js (module.js:478:10)
    at Object.Module._extensions..js (c:\Users\Guy\Code\alpha-dev\node_modules\istanbul\lib\hook.js:101:13)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

这是我尝试过的:
  • 安装了 Istanbul 尔和谐(来自git://github.com/gotwarlost/istanbul.git#harmony)作为我的开发依赖项。
  • 运行以下命令:"./node_modules/.bin/istanbul" cover "./node_modules/mocha/bin/_mocha" -- --harmony tests -R spec
  • Istanbul 尔和_mocha的标志组合

  • 如何运行istanbul来涵盖使用ES6功能编写的测试?我想念什么?

    最佳答案

    2016年七月
    这是带有有效的“npm cover”命令的package.json文件的相关部分,该命令对es6模块代码(即es6 importexport),babel 6,istanbul-1.0-alpha.2有用。
    我发布此消息是因为我不得不花几个小时来解决其他人的github问题线程(现在找不到)的解决方案。似乎有很多“解决方案”不再解决覆盖问题或无法轻易适应其他devDependencies堆栈。 YMMV。
    package.json脚本

     "scripts": {
        "clean": "rm -rf ./build ./doc ; mkdir ./build",
        "build": "node_modules/.bin/babel build src/index.js -o build/index.js",
        "doc": "node_modules/.bin/esdoc -c esdoc.json",
        "lint": "node_modules/.bin/eslint src/index.js",
        "lint-test": "node_modules/.bin/eslint test/index.js",
        "test": "node_modules/.bin/mocha --compilers js:babel-core/register --reporter spec --slow 50 --timeout 60000",
        "cover": "node_modules/.bin/istanbul cover node_modules/.bin/_mocha -- -u exports --compilers js:babel-register --timeout 60000",
        "go": "npm run clean && npm run lint && npm run lint-test && npm run test && npm run build"
      },
    
    package.json devDependencies
     "devDependencies": {
        "babel": "^6.5.2",
        "babel-cli": "^6.10.1",
        "babel-core": "^6.10.4",
        "babel-preset-es2015": "^6.9.0",
        "coveralls": "^2.11.9",
        "esdoc": "^0.4.7",
        "eslint": "^3.0.1",
        "istanbul": "^1.0.0-alpha.2",
        "mocha": "^2.5.3",
        "should": "^8.3.1"
      },
    
    .babelrc
    {
      "presets": ["es2015"]
    }
    
    .travis.yml
    language: node_js
    
    node_js:
      - 6
    
    install:
      - npm install
    
    script:
      - npm run lint
      - npm run lint-test
      - npm run cover
    
    after_script:
      - "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js"
    

    10-08 11:19