nyc运行时覆盖黄瓜

问题描述 投票:1回答:1

我试图覆盖我用黄瓜/ 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')

我正在尝试做什么:

  1. 使用TypeScript源图运行已检测的应用程序
  2. 针对此应用程序在外部运行我的测试
  3. 停止申请并生成原始TS代码的覆盖报告

我的设置如下,

  • 因为:kuzxsw点
  • webpack:v9.4.0
  • 打字稿:^4.23.0,

tsconfig:

~3.1.6

webpack.config.js:

{
    "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"]
}

package.json(相关部分):

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'
  }
}

问题再次出现在上面显示的堆栈跟踪无法映射单个文件。我尝试了很多配置组合,总是在这里结束。

  • 谁知道什么可能是错的?
  • 我应该使用"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 }, 吗?
typescript istanbul nyc
1个回答
1
投票

发现了这个问题。这是在remap-istanbul中修复的webpack的错误。

解决方案是在webpack中,您需要添加选项:https://github.com/SitePen/remap-istanbul/issues/68。输出部分如下所示:

devtoolModuleFilenameTemplate

在webpack.config.js中只有output: { path: path.join(__dirname, 'dist'), filename: 'index.js', devtoolModuleFilenameTemplate: '[resource-path]'} ,就是这样!我们甚至不需要在devtool: 'source-map'中使用nyc配置,也不需要在package.json中对tsconfig.json进行任何修改。

© www.soinside.com 2019 - 2024. All rights reserved.