【发布时间】:2019-06-13 14:14:54
【问题描述】:
所以。我试图弄清楚为什么这不起作用。
我正在 src 和 tests 目录中的文件中编写源代码和测试 TypeScript 代码。这些是*.ts 和*.spec.ts 文件。
我使用npx tsc 将源文件和测试文件都转译到目录build。所以这个目录现在包含*.js.、*.spec.js、*.js.map 和*.spec.js.map 文件类型。
我现在如何设置 mocha 和 nyc 来使用它?
我有以下一套。
.nycrc.json
{
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"branches": 0,
"lines": 0,
"functions": 0,
"statements": 0,
"check-coverage": true,
"exclude": [".ignore", "coverage"],
"report-dir": "./coverage/",
"cache": false,
"source-map": true,
"produce-source-map": true
}
tsconfig.json:
{
"compilerOptions": {
"allowJs": true,
"noImplicitAny": false,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"module": "commonjs",
"target": "es2016",
"lib": ["es2016"],
"moduleResolution": "node",
"types": ["mocha", "node"],
"typeRoots": ["node_modules/@types"],
"sourceMap": true,
"outDir": "./build/",
"skipLibCheck": true,
"removeComments": false
},
"include": ["./**/*.ts", "./**/*.js"]
}
错误:
karl@karl-Dell-Precision-M3800:~/dev/escd$ NODE_ENV=test npx nyc --reporter=html --reporter=text mocha "./build/tests/**/*.js"
mappedCoverage.addStatement is not a function
但是,如果我在 .nycrc.json 文件中将 all 设置为 false,那么它不会抱怨。怎么了?
我不想使用ts-node 或类似的东西,我已经转译了这些文件。
【问题讨论】:
-
我在这里给出了另一个帖子的详细示例,它可能是重复的:stackoverflow.com/a/64829161/2538750 这似乎是相同的原因(nyc 没有为 typescript 正确配置。设置可能很棘手。
标签: typescript mocha.js source-maps nyc