8

我正在努力让所有人都相处nyc ava融洽。babel我遇到了一个问题,其中 async / await 分支显示为未涵盖,所以这是有效的,我在集成babel-plugin-istanbul插件以进行测试时遇到了麻烦。

我在项目中有两个文件,src/index.js并且src/test.js.

{
    "name": "example",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "ava",
        "coverage": "NODE_ENV=test nyc npm run test",
        "report": "nyc report --reporter=html",
        "report:open": "open ./coverage/index.html",
        "cover": "npm run coverage && npm run report && npm run report:open"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencies": {
        "babel-runtime": "^6.26.0",
        "bluebird": "^3.5.0",
        "lodash": "^4.17.4"
    },
    "devDependencies": {
        "ava": "^0.22.0",
        "babel-cli": "^6.26.0",
        "babel-plugin-istanbul": "^4.1.4",
        "babel-plugin-transform-runtime": "^6.23.0",
        "babel-preset-env": "^1.6.0",
        "babel-register": "^6.26.0",
        "nyc": "^11.2.1",
        "sinon": "^3.2.1",
        "testdouble": "^3.2.4"
    },
    "babel": {
        "presets": ["env"],
        "plugins": ["transform-runtime"],
        "env": {
            "test": {
                "plugins": ["istanbul"]
            }
        }
    },
    "ava": {
        "require": ["babel-register"],
        "babel": "inherit"
    },
    "nyc": {
        "sourceMap": false,
        "instrument": false
    }
}

这是正在运行的:

> example@1.0.0 coverage /Users/me/Desktop/example
> NODE_ENV=test nyc npm run test


> example@1.0.0 test /Users/me/Desktop/example
> ava


  11 passed
----------|----------|----------|----------|----------|----------------|
File      |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files |  Unknown |  Unknown |  Unknown |  Unknown |                |
----------|----------|----------|----------|----------|----------------|

> example@1.0.0 report /Users/me/Desktop/example
> nyc report --reporter=html


> example@1.0.0 report:open /Users/em/Desktop/example
> open ./coverage/index.html

为什么没有src/index.js出现在报道中?

4

1 回答 1

0

尝试移动test.js到某个测试文件夹下test/test.js

于 2019-04-03T07:07:36.860 回答