我使用Typescript在Ionic 2中创建了一个项目。
当我尝试在Karma的帮助下对Ionic 2项目进行单元测试时,运行npm test命令时出现以下错误:
Missing 'angularCli.config' entry in Karma config
Error: Missing 'angularCli.config' entry in Karma config
at init (D:\MyApp\node_modules\angular-cli\plugins\karma.js:8:11)
at Array.invoke (D:\MyApp\node_modules\di\lib\injector.js:75:15)
at Injector.get (D:\MyApp\node_modules\di\lib\injector.js:48:43)
at D:\MyApp\node_modules\karma\lib\server.js:138:20
at Array.forEach (native)
at Server._start (D:\MyApp\node_modules\karma\lib\server.js:137:21)
at Injector.invoke (D:\MyApp\node_modules\di\lib\injector.js:75:15)
at Server.start (D:\MyApp\node_modules\karma\lib\server.js:102:18)
at D:\MyApp\node_modules\angular-cli\tasks\test.js:33:25
at Class.run (D:\MyApp\node_modules\angular-cli\tasks\test.js:15:16)
at Class.run (D:\MyApp\node_modules\angular-cli\commands\test.js:31:25)
at Class.<anonymous> (D:\MyApp\node_modules\angular-cli\angular-cli\lib\models\command.js:152:17)
at process._tickCallback (internal/process/next_tick.js:103:7)
npm ERR! Test failed. See above for more details.
karma.conf.js文件:
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-remap-istanbul'),
require('karma-mocha-reporter'),
require('angular-cli/plugins/karma')
],
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['angular-cli']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: [
'mocha', 'karma-remap-istanbul'
],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
angular-cli.json文件:
{
"project": {
"version": "1.0.0-beta.16",
"name": "myapp"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": "assets",
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.test.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css"
],
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false
}
}
问题是什么?