Code Coverage for Typescript using karma-jasmine and istanbul

前端 未结 3 1612
名媛妹妹
名媛妹妹 2021-02-07 05:44

I am trying to get the Code Coverage for my typescript Code in karma framework using Istanbul in karma.conf typescript files are included and by karma typescript-preprocessor we

3条回答
  •  旧时难觅i
    2021-02-07 06:21

    We are using instanbul-remap for our project and it works quite nicely. To create our coverage reports, we run the following shell script:

    #!/bin/bash
    
    PROJECT_PATH="$(dirname $0)/../"
    
    cd $PROJECT_PATH
    echo Creating coverage reports for `pwd`
    
    if [ ! -d "target/dist" ]; then
      echo
      echo "target/dist directory not found. Must compile source with \`npm install\` before running tests."
      echo
      exit 1;
    fi
    
    COVERAGE_DIR=target/coverage-raw
    REMAP_DIR=target/coverage-ts
    
    mkdir -p $COVERAGE_DIR
    mkdir -p $REMAP_DIR
    
    # run coverage on unit tests only
    echo Creating coverage reports for unit tests
    node_modules/.bin/istanbul cover --dir $COVERAGE_DIR nodeunit `find target/dist/test/ -name *.test.js` > /dev/null
    
    # re-map the coverage report so that typescript sources are shown
    echo Remapping coverage reports for typescript
    node_modules/.bin/remap-istanbul -i $COVERAGE_DIR/coverage.json -o $REMAP_DIR -t html
    
    echo Coverage report located at $REMAP_DIR/index.html
    

    Our project uses nodeunit as a test harness as it is a node application. However, I would expect that a similar approach would work for karma.

提交回复
热议问题