我试图使用茉莉花编写Angular服务的单元测试,首先在快速搜索后将“ angularcli”的每个实例都更改为“ @angularcli”,但无法找到模块“ angularcli / plugins / karma”,但仍然存在运行“ ng测试”的问题。这是错误:
20 07 2018 17:07:57.919:ERROR [config]: Error in config file!
{ Error: Cannot find module '@angular-cli/plugins/karma'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:571:15)
at Function.Module._load (internal/modules/cjs/loader.js:497:25)
at Module.require (internal/modules/cjs/loader.js:626:17)
at require (internal/modules/cjs/helpers.js:20:18)
at module.exports (D:\new project\MarsWeb\MarsWeb-FrontEnd\karma.conf.js:13:7)
at Object.parseConfig (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\karma\lib\config.js:396:5)
at new Server (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\karma\lib\server.js:56:20)
at Promise (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\tasks\test.js:45:33)
at new Promise (<anonymous>)
at Class.run (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\tasks\test.js:23:16)
at Class.run (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\commands\test.js:122:25)
at resolve (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\ember-cli\lib\models\command.js:261:20)
at new Promise (<anonymous>)
at Class.validateAndRun (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\ember-cli\lib\models\command.js:240:12)
at Promise.resolve.then.then (D:\new project\MarsWeb\MarsWeb-FrontEnd\node_modules\@angular\cli\ember-cli\lib\cli\cli.js:140:24)
at process._tickCallback (internal/process/next_tick.js:68:7) code: 'MODULE_NOT_FOUND' }
我已更新karma.conf.js以使其与@ angular-cli静止节点一起找不到模块
这是我的Karma.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-cli/plugins/karma')
],
client: {
clearContext: false
},
files: [
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/test.ts': ['@angular-cli']
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
coverage: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
这是来自package.json的开发依赖项
"devDependencies": {
"@angular/cli": "^1.2.5",
"@angular/compiler-cli": "^5.2.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-remap-istanbul": "^0.6.0",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.5.0",
"typescript": "^2.4.2"
}
答案 0 :(得分:2)
您需要在所有情况下将@angular-cli
更改为@angular/cli
。
希望这会有所帮助!