Aurelia/Karma/Istanbul 无法读取 属性 'skip' 和 'decl' 的未定义但生成融洽关系
Aurelia/Karma/Istanbul Cannot read property 'skip' and 'decl' of undefined but generates a rapport
上周我用 Mocha、Sinon 和 Karma 为我的 Aurelia 应用程序编写了很多测试。现在是为代码覆盖设置伊斯坦布尔的时候了。
当 karma 完成他的任务时,伊斯坦布尔将生成覆盖范围并在控制台和 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
HTML 页面
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 ()
这是我的 Karma 配置:
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 },
});
}
我从配置文件中删除了不必要的代码。
我在 Webpack 配置中添加了以下规则:
...
{
test: /\.(ts)/,
options: {
esModules: true,
produceSourceMap: true,
debug: true
},
include: path.resolve(srcDir),
loader:'istanbul-instrumenter-loader'
},
....
所有错误都已解决。
关于 'decl' 的第一个错误来自我代码中的 @inject。通过删除@inject,问题得到解决。
重新安装我的 node.js 后,“TypeError: Cannot read 属性 'skip' of undefined”错误消失了。
上周我用 Mocha、Sinon 和 Karma 为我的 Aurelia 应用程序编写了很多测试。现在是为代码覆盖设置伊斯坦布尔的时候了。 当 karma 完成他的任务时,伊斯坦布尔将生成覆盖范围并在控制台和 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
HTML 页面
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 ()
这是我的 Karma 配置:
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 },
});
}
我从配置文件中删除了不必要的代码。
我在 Webpack 配置中添加了以下规则:
...
{
test: /\.(ts)/,
options: {
esModules: true,
produceSourceMap: true,
debug: true
},
include: path.resolve(srcDir),
loader:'istanbul-instrumenter-loader'
},
....
所有错误都已解决。 关于 'decl' 的第一个错误来自我代码中的 @inject。通过删除@inject,问题得到解决。
重新安装我的 node.js 后,“TypeError: Cannot read 属性 'skip' of undefined”错误消失了。