webpack-contrib / istanbul-instrumenter-loader

Istanbul Instrumenter Loader
MIT License
273 stars 65 forks source link

Error: Unable to lookup source #46

Closed JZ-at-TP closed 7 years ago

JZ-at-TP commented 7 years ago

I'm trying to get coverage tests for my vuejs project. My webpack2 rules look like this...

      rules: [{
        test: /\.js$/,
        exclude: /node_modules|vue\/src|vue-router\//,
        loader: 'babel-loader',
        options: {
          presets: [
            ['es2015', { 'modules': false }]
          ],
          plugins: ['transform-runtime']
        }
      }, {
        test: /\.styl$/,
        loaders: ['style-loader', 'css-loader', 'stylus-loader']
      }, {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          postLoaders: {
            js: 'istanbul-instrumenter-loader?esModules=true'
          }
        }
      }, {
        include: /\.json$/,
        loaders: ['json-loader']
      }, {
        enforce: 'post',
        test: /\.js$/,
        exclude: /node_modules|vue\/src|vue-router\/|test\//,
        loader: 'istanbul-instrumenter-loader',
        query: {
          debug: true,
          preserveComments: true,
          esModules: true
        }
      }]
    },

My karma config looks like this.

        {
          frameworks: ['jasmine'],
          singleRun: true,
          colors: true,
          browsers: ['Chrome'],
          phantomjsLauncher: {
            exitOnResourceError: true
          },
          reporters: ['spec', 'coverage-istanbul'],
          files: [
            { pattern: 'test/unit/**/*-spec.js', watched: false }
          ],
          preprocessors: {
            'test/unit/**/*-spec.js': ['webpack']
          },
          webpack: {
            devtool: 'source-map',
            output: {
            },
            module: webpack.module,
            resolve: webpack.resolve
          },
          webpackMiddleware: {
            noInfo: true,
            stats: 'errors-only'
          },
          coverageIstanbulReporter: {
            dir: './build/reports/unit',
            reports: [ 'text-summary', 'html' ],
            fixWebpackSourcePaths: true,
            'report-options': {
              html: {
                verbose: true,
                subdir: 'html'
              }
            }
          }
        },
        specReporter: {
          suppressSkipped: false
        }
      }

The istanbul-instrumenter-loader is used specifically for the javascript section of the .vue files as a postLoader. When I run karma I'm getting a report but its just an error Error: Unable to lookup source: /Users/user/Development/app/src/components/background.vue?094fc1b7(ENOENT: no such file or directory, open '/Users/user/Development/app/src/components/background.vue?094fc1b7'), note the has on the end of the filename. Is there something I'm doing wrong?

divyanthj commented 7 years ago

+1. Same here. The code coverage report shows 100% with 0/0 checked for statements, branches, functions and lines.

mattlewis92 commented 7 years ago

This was fixed in the karma coverage reporter in this PR: https://github.com/mattlewis92/karma-coverage-istanbul-reporter/issues/2