Search code examples
javascriptwebpackkarma-runneraureliaistanbul

Aurelia/Karma/Istanbul Cannot read property 'skip' and 'decl' of undefined but generates a rapport


Last week I wrote a lot of tests with Mocha, Sinon and Karma for my Aurelia application. Now is the moment to setup Istanbul for the code coverage. When karma completed his task will Istanbul generate the coverage and throws an error in the console and in one file of HTML rapport.

25 10 2019 09:41:56.600:ERROR [coverage]: TypeError: Cannot read property 'skip' of undefined
    at C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\istanbul\lib\object-utils.js:110:43
    at Array.forEach (<anonymous>)
    at computeSimpleTotals (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\istanbul\lib\object-utils.js:108:28)
    at Object.summarizeFileCoverage (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\istanbul\lib\object-utils.js:215:25)
    at C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\istanbul\lib\report\html.js:558:58
    at Array.forEach (<anonymous>)
    at HtmlReport.writeReport (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\istanbul\lib\report\html.js:557:27)
    at writeReport (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\karma-coverage\lib\reporter.js:68:16)
    at C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\karma-coverage\lib\reporter.js:297:11
    at fs.stat (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\karma\lib\helper.js:148:7)
    at callback (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\*HIDDEN*\node_modules\graceful-fs\polyfills.js:295:20)
    at FSReqWrap.oncomplete (fs.js:153:5)
Karma has exited with 0

The HTML page

Cannot read property 'decl' of undefined
TypeError: Cannot read property 'decl' of undefined
    at Object.keys.forEach.fName (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-reports\lib\html\annotator.js:92:31)
    at Array.forEach ()
    at annotateFunctions (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-reports\lib\html\annotator.js:88:26)
    at Object.annotateSourceCode (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-reports\lib\html\annotator.js:238:9)
    at HtmlReport.onDetail (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-reports\lib\html\index.js:265:27)
    at Visitor.(anonymous function) [as onDetail] (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:34:30)
    at ReportNode.Node.visit (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:114:17)
    at getChildren.forEach.child (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:118:15)
    at Array.forEach ()
    at ReportNode.Node.visit (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:117:24)
    at getChildren.forEach.child (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:118:15)
    at Array.forEach ()
    at ReportNode.Node.visit (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:117:24)
    at Tree.visit (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-lib-report\lib\tree.js:150:20)
    at Object.keys.forEach.name (C:\Projecten\*HIDDEN*\dev\*HIDDEN*\node_modules\istanbul-api\lib\reporter.js:94:18)
    at Array.forEach ()

This is my Karma config:

const path = require('path');

module.exports = function (config) {
    config.set({
        basePath: path.dirname(__dirname),

        frameworks: ['mocha', 'chai', 'sinon', 'karma-typescript'],

        'plugins': [
            require('karma-mocha'),
            require('karma-sinon'),
            require('karma-chai'),
            require('karma-webpack'),
            require('karma-mocha-reporter'), 
            require('karma-chrome-launcher'),
            require('karma-junit-reporter'),
            require('karma-typescript'),
            require('karma-phantomjs-launcher'),
            require('karma-coverage'),
            require('karma-coverage-istanbul-reporter'),
            require('karma-remap-istanbul'),
            require('karma-istanbul-threshold')
        ],

        preprocessors: {
            'test/karma-bundle.js': ['webpack'],
            'ClientApp/**/*.ts': ['webpack', 'coverage']
        },
        webpack: require('../webpack.unit.config')({ env: 'production', prod: false }),

        reporters: ['junit', 'mocha', 'progress', 'coverage', 'coverage-istanbul'],

        coverageIstanbulReporter: {
            reports: ['html'],
            dir: path.resolve(__dirname, 'coverage-karma'),
            includeAllSources: false,
            fixWebpackSourcePaths: false,
            combineBrowserReports: false
        },

        webpackServer: { noInfo: true }, 
    });
}

I removed the unnecessary code from the config file.

I added the following rule to my Webpack config:

...
{
    test: /\.(ts)/,
    options: {
        esModules: true,
        produceSourceMap: true,
        debug: true
    },
    include: path.resolve(srcDir),
    loader:'istanbul-instrumenter-loader'
},
....

Solution

  • all the errors are resolved. The first error about the 'decl' is from a @inject in my code. By removing the @inject the problem was resolved.

    After reinstalling my node.js the 'TypeError: Cannot read property 'skip' of undefined' error was gone.