[英]nyc runtime coverage with cucumber
我试图覆盖我用 Cucumber/TS 编写的 e2e 测试,但我的测试报告永远无法映射回我的源文件。
该报告只是一个目录列表,单击单个 *.ts 文件会产生一个堆栈跟踪( ***
'd out my user/repo name):
Unable to lookup source: /Users/***/dev/git/***/dist/webpack:/src/gql/index.ts(ENOENT: no such file or directory, open '/Users/***/dev/git/***/dist/webpack:/src/gql/index.ts')
Error: Unable to lookup source: /Users/***/dev/git/***/dist/webpack:/src/gql/index.ts(ENOENT: no such file or directory, open '/Users/***/dev/git/***/dist/webpack:/src/gql/index.ts')
我正在尝试做的事情:
我的设置如下,
v9.4.0
^4.23.0,
~3.1.6
配置:
{
"compilerOptions": {
"rootDir": "./src",
"module": "commonjs",
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"noEmitOnError": true,
"declaration": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"lib": ["esnext"],
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"noImplicitAny": true,
"typeRoots": ["./typings", "./node_modules/@types"],
"experimentalDecorators": true
},
"exclude": ["node_modules", "dist"]
}
webpack.config.js :
module.exports = {
entry: ['./src/index.ts'],
target: 'node',
mode: process.env.NODE_ENV === 'dev' ? 'development' : 'production',
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder,
devtool: 'inline-source-map',
module: {
rules: [
{
test: /.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
modules: [path.resolve(__dirname, 'src'), 'node_modules']
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js'
}
}
package.json (相关部分):
"scripts": {
"start-coverage": "NODE_ENV=test nyc node --reporter=lcov dist/index.js",
...
},
"nyc": {
"all": true,
"require": "ts-node/register",
"instrument": true,
"report-dir": "./coverage",
"temp-dir": "./temp",
"source-map": true,
"produce-source-map": false
},
问题再次在于上面显示的堆栈跟踪无法映射单个文件。 我尝试了许多配置组合,但总是在这里结束。
remap-istanbul
吗?发现问题。 这是 webpack 的一个错误,已在https://github.com/SitePen/remap-istanbul/issues/68中修复。
解决方案是在 webpack 中,您需要添加选项: devtoolModuleFilenameTemplate
。 输出部分如下所示:
output: {
path: path.join(__dirname, 'dist'),
filename: 'index.js',
devtoolModuleFilenameTemplate: '[resource-path]'}
仅使用devtool: 'source-map'
,就是这样! 我们甚至不需要package.json
的nyc
配置,也不需要tsconfig.json
任何修改,除了sourceMaps:true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.