简体   繁体   English

业力-如何指向源地图进行打字稿覆盖

[英]Karma - How to point to a source map for typescript coverage

I like to generate a coverage report for my typescript source files with karma-coverage. 我想使用业力覆盖为我的打字稿源文件生成一份覆盖率报告。 My unit tests are written in javascript and I'm using the Jasmine Test framework. 我的单元测试是用javascript编写的,并且我使用的是Jasmine Test框架。

My folder structure looks like this: 我的文件夹结构如下所示:

node_modules/
app/
  app.js
  app.js.map
  app.ts
  components/
  controllers/
      SampleController.ts
  directives/
  filters/
  services/

unittests/
  karma.conf.js
  components/
  controllers/
      SampleControllerTest.js
  directives/
  filters/
  services/

My karma.conf.js 我的karma.conf.js

module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],
    plugins: [
          'karma-jasmine',
          'karma-ng-html2js-preprocessor',
          'karma-coverage',
          'karma-phantomjs-launcher',
          'karma-sourcemap-loader'

      ],
    preprocessors: {
        '../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ],

            // source files, that you wanna generate coverage for
            // do not include tests or libraries
            // (these files will be instrumented by Istanbul)
        '../app/app.js' : ['sourcemap', 'coverage' ],

    },
    reporters: ['progress', 'coverage'],

    // web server port
    port: 9876,

    coverageReporter: {
          type : 'html',
          dir : 'coverage/'
      },
    // and some other stuff
  });
};

Currently my coverage report delivers sufficient metrics but not related to the single typescript files but the app.js. 目前,我的覆盖率报告提供了足够的指标,但与单个打字稿文件无关,但与app.js无关。

I suppose that I either messed up something with the preprocessor config or that I need to specify the source map. 我想我要么弄乱了预处理程序配置,要么需要指定源映射。

Anny hints? 安妮提示?

Using karma-istanbul-remap does the trick for me. 使用karma-istanbul-remap对我有用。

karma.conf.js: karma.conf.js:

module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],
    plugins: [
          'karma-jasmine',
          'karma-ng-html2js-preprocessor',
          'karma-coverage',
          'karma-phantomjs-launcher',
          'karma-remap-istanbul'

      ],
    preprocessors: {
        '../app/directives/controls/**/*Template.html' : [ 'ng-html2js' ],

            // source files, that you wanna generate coverage for
            // do not include tests or libraries
            // (these files will be instrumented by Istanbul)
        '../app/app.js' : ['coverage' ],

    },
    reporters: ['progress', 'coverage', 'karma-remap-istanbul'],

    // web server port
    port: 9876,

    coverageReporter: {
        type : 'json',
        subdir : '.',
        dir : 'coverage/',
        file : 'coverage.json'
    },
    remapIstanbulReporter: {
          src: 'coverage/coverage.json',
          reports: {
              lcovonly: 'coverage/lcov.info',
              html: 'coverage/html/report'
          },
          timeoutNotCreated: 5000, // default value
          timeoutNoMoreFiles: 1000 // default value
    },
    // and some other stuff
  });
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Aurelia和Typescript使业力覆盖? - How to get karma-coverage working with Aurelia and typescript? vue 2,打字稿,摩卡和业力的代码覆盖率 - Code coverage with vue 2, typescript, mocha and karma 如何配置karma所以打字稿源文件是可调试的 - How to configure karma so typescript source files would be debuggable 带有 karma 的覆盖率报告以及 javascript 和 typescript src 文件的混合 - Coverage reports with karma and a mix of javascript and typescript src files 获取预转换源代码的Karma代码覆盖率 - Getting Karma code coverage for pre-transpilation source code karma-remap-istanbul 正在生成源旁边的覆盖率 html - karma-remap-istanbul is generating the coverage htmls next to source 如何知道因果报应和webpack在项目中的覆盖范围? - How to know the coverage in project with karma and webpack? 如何使用新的babel-plugin -__ coverage__向业力添加覆盖率报告 - How to add coverage report to karma with new babel-plugin-__coverage__ 找不到源 map 用于 + Karma + Jasmine + JavaScript - Could not find source map for + Karma + Jasmine + JavaScript 如何指向打字稿文件而不​​是 javascript 文件 karma runner webstorm - Howto point to typescript file instead of javascript file karma runner webstorm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM