isparta 模块未正确加载,因此无法运行测试用例
Posted
技术标签:
【中文标题】isparta 模块未正确加载,因此无法运行测试用例【英文标题】:isparta module not loading properly so can't run test cases 【发布时间】:2016-04-14 14:40:27 【问题描述】:我的测试过去运行得非常好,但是突然间我在运行测试时遇到了以下错误。请帮忙。我被困在这两天了。
这是一个反应项目。我正在使用 web-pack 和 babel。使用 isparta 进行代码覆盖。
enter cosapMac:dealScore saptarshichatterjee$ karma start ./client/karma.conf.js
10 01 2016 09:43:36.482:DEBUG [config]: autoWatch set to false, because of singleRun
10 01 2016 09:43:36.488:DEBUG [plugin]: Loading plugin karma-browserify.
10 01 2016 09:43:36.924:DEBUG [plugin]: Loading plugin karma-chrome-launcher.
10 01 2016 09:43:36.932:DEBUG [plugin]: Loading plugin karma-jasmine.
10 01 2016 09:43:36.934:DEBUG [plugin]: Loading plugin karma-coverage.
10 01 2016 09:43:37.190:DEBUG [plugin]: Loading plugin isparta-instrumenter-loader.
10 01 2016 09:43:37.927:DEBUG [plugin]: Loading plugin babel-loader.
10 01 2016 09:43:38.310:DEBUG [plugin]: Loading plugin karma-webpack.
10 01 2016 09:43:38.587:DEBUG [plugin]: Loading plugin isparta.
/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:116
var type = module[name][0];
^
TypeError: Cannot read property '0' of undefined
at /usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:116:32
at Array.forEach (native)
at /usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:115:27
at Array.forEach (native)
at new Injector (/usr/local/lib/node_modules/karma/node_modules/di/lib/injector.js:104:11)
at new Server (/usr/local/lib/node_modules/karma/lib/server.js:90:20)
at Object.exports.run (/usr/local/lib/node_modules/karma/lib/cli.js:231:7)
at Object.<anonymous> (/usr/local/lib/node_modules/karma/bin/karma:3:23)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
这是我的 package.json:
"name": "redux-scafford",
"version": "0.1.0",
"description": "combination of redux, react-router and ES7+ support ",
"repository": "",
"author": "MDL <abc@abc.com>",
"src": "src",
"test": "test",
"dist": "dist",
"mainInput": "main",
"mainOutput": "main",
"dependencies":
"belle": "^1.2.2",
"griddle-react": "^0.2.14",
"i18next": "^2.0.1",
"immutable": "^3.7.4",
"jquery": "^2.1.4",
"jsxstyle": "0.0.17",
"lodash": "^3.10.1",
"moment": "^2.10.6",
"radium": "^0.13.7",
"react": "0.13.x",
"react-redux": "^1.0.1",
"react-router": "1.0.0-beta3",
"redux": "^1.0.1",
"redux-thunk": "^0.1.0"
,
"devDependencies":
"autoprefixer-loader": "^2.0.0",
"babel-core": "5.8.23",
"babel-eslint": "^4.0.10",
"babel-loader": "5.3.2",
"babel-runtime": "^5.8.20",
"babelify": "^6.3.0",
"css-loader": "~0.17.0",
"del": "^2.0.1",
"ecstatic": "^0.8.0",
"eslint": "^1.1.0",
"eslint-config-airbnb": "0.0.8",
"eslint-config-airplus": "^1.0.4",
"eslint-loader": "^1.0.0",
"eslint-plugin-react": "^3.2.3",
"express": "^4.13.3",
"gulp": "^3.9.0",
"gulp-load-plugins": "^1.0.0-rc.1",
"gulp-serve": "^1.0.0",
"gulp-size": "^2.0.0",
"http-proxy": "^1.11.1",
"isparta": "^3.5.1",
"isparta-instrumenter-loader": "^0.2.1",
"karma-browserify": "^4.4.0",
"karma-chrome-launcher": "^0.2.0",
"karma-cli": "^0.1.1",
"karma-coverage": "^0.5.2",
"karma-jasmine": "^0.3.6",
"karma-webpack": "^1.7.0",
"raw-loader": "^0.5.1",
"react-hot-loader": "^1.2.8",
"redux-devtools": "~1.0.2",
"run-sequence": "^1.1.2",
"style-loader": "^0.12.4",
"url-loader": "~0.5.6",
"webpack": "~1.12.1",
"webpack-dev-server": "~1.10.1"
这是我的业力配置文件:
const babelify = require('babelify');
var path = require('path');
module.exports = function(config)
config.set(
basePath: '',
frameworks: ['browserify', 'jasmine'],
plugins: [
'karma-browserify',
'karma-chrome-launcher',
'karma-jasmine',
'karma-coverage',
'isparta-instrumenter-loader',
'babel-loader',
'karma-webpack',
'isparta'
], // If you see `cant find plugin errors` npm install -g above plugins.
// start these browsers
browsers: ['Chrome'],
reporters: ['progress', 'coverage'],
preprocessors:
'./src/tests/testsuits/**/*.js': ['webpack'],
,
coverageReporter:
type: 'html',
dir: 'src/tests/coverage'
,
logLevel: config.LOG_BEBUG,
singleRun: true,
webpack:
module:
loaders: [
test: /\.js?$/,
loader: 'babel-loader',
include: path.resolve(__dirname, './src')
],
preLoaders: [
test: /\.js?$/,
exclude: [/node_modules/, /\.spec\.js/],
loader: 'isparta-instrumenter-loader'
, ]
,
webpackServer:
noInfo: true
,
files: [
'./src/tests/testsuits/**/*.js'
]
);
;
【问题讨论】:
我希望堆栈溢出有一个标志说“请解决这个问题,我快疯了”。 您升级了任何依赖项吗? 【参考方案1】:更改了以下内容并且它起作用了。
1) 从业力配置插件列表中删除了v'isparta'。
2) 而不是karma start
我做了./node_modules/karma/bin/karma
开始。
错误是因为如果你只做karma start
你实际上是指全局安装的业力,默认情况下搜索全局空间中的插件模块。而且那个因果报应和全局安装的插件模块已经过时了,它不适用于较新的 isparta
模块。
【讨论】:
以上是关于isparta 模块未正确加载,因此无法运行测试用例的主要内容,如果未能解决你的问题,请参考以下文章
Grunt,Istanbul,Isparta和TypeScript
Python SystemError:父模块''未加载,无法执行相对导入[重复]