我正在嘗試使用Karma + Jasmine來測試我的Aurelia(+ Webpack + TypeScript)應用程序的單元。我試圖使用the skeleton附帶的測試樣板。Karma ERROR [config]:無效的配置文件
骨架上的項目,下面NPM腳本完美運行:
"test": "cross-env NODE_ENV=test ./node_modules/karma/bin/karma start test/karma.conf.js"
但當我在我的項目一樣,它會拋出錯誤(沒有進一步的堆棧跟蹤):
DEBUG [config]: Loading config C:\Path\to\my\Website\test\karma.conf.js
ERROR [config]: Invalid config file!
它確實不提供關於配置無效的其他信息。
下面是與骨架傳來karma.conf.js
:
"use strict";
const path = require('path');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (e.g. files, exclude)
basePath: __dirname,
/*
* Frameworks to use
*
* available frameworks: https://npmjs.org/browse/keyword/karma-adapter
*/
frameworks: ['jasmine'],
// list of files to exclude
exclude: [ ],
/*
* list of files/patterns to load in the browser
*
* we are building the test environment in ./spec-bundle.js
*/
files: [
{ pattern: 'spec-bundle.js', watched: false },
],
/*
* preprocess matching files before serving them to the browser
* available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
*/
preprocessors: {
'spec-bundle.js': ['coverage', 'webpack', 'sourcemap']
},
webpack: require('../webpack.config'),
coverageReporter: {
reporters: [{
type: 'json',
subdir: '.',
file: 'coverage-final.json'
}]
},
remapIstanbulReporter: {
src: path.join(__dirname, 'coverage/coverage-final.json'),
reports: {
html: path.join(__dirname, 'coverage/')
},
timeoutNotCreated: 1000,
timeoutNoMoreFiles: 1000
},
// Webpack please don't spam the console when running in karma!
webpackServer: { noInfo: true},
/*
* test results reporter to use
*
* possible values: 'dots', 'progress'
* available reporters: https://npmjs.org/browse/keyword/karma-reporter
*/
reporters: [ 'mocha', 'coverage', 'karma-remap-istanbul' ],
// web server port
port: 9876,
// enable/disable colors in the output (reporters and logs)
colors: true,
/*
* level of logging
* possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
*/
logLevel: config.LOG_INFO,
// enable/disable watching file and executing tests whenever any file changes
autoWatch: false,
/*
* start these browsers
* available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
*/
browsers: [
'Chrome',
// TODO: https://www.npmjs.com/package/karma-electron
],
/*
* Continuous Integration mode
* if true, Karma captures browsers, runs the tests and exits
*/
singleRun: true
});
};
來隔離問題,我也試着開始產生在我的網站根目錄的新karma.conf.js
,與karma init
,並且我面臨着完全一樣的錯誤與karma start
。下面是配置文件,由此產生:
// Karma configuration
// Generated on Wed Dec 14 2016 07:50:15 GMT+0100 (W. Europe Standard Time)
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files/patterns to load in the browser
files: [
'./test/**/*Spec.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// web server port
port: 9876,
// enable/disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable/disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
};
我使用NPM包以下版本:
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-mocha-reporter": "^2.2.0",
"karma-remap-istanbul": "^0.2.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"typescript": "2.1.1",
"webpack": "2.1.0-beta.27",
請建議如何可以解決或至少有更多的(調試)信息去弄清楚。
更新:得到了下面的堆棧跟蹤rimraf
後,荷蘭國際集團的node_modules
並重新安裝包:
DEBUG [config]: Loading config C:\Path\to\my\Website\test\karma.conf.js
ERROR [config]: Invalid config file!
TSError: ⨯ Unable to compile TypeScript
Cannot find type definition file for 'dir1'. (2688)
Cannot find type definition file for 'dir2'. (2688)
Cannot find type definition file for 'dir3'. (2688)
Cannot find type definition file for 'lang1'. (2688)
Cannot find type definition file for 'dir4'. (2688)
Cannot find type definition file for 'lang2'. (2688)
Cannot find type definition file for 'maps'. (2688)
Cannot find type definition file for 'valueConverters'. (2688)
Cannot find type definition file for 'views'. (2688)
at getOutput (C:\Path\to\my\Website\node_modules\ts-node\src\index.ts:312:17)
at C:\Path\to\my\Website\node_modules\ts-node\src\index.ts:343:18
at Object.compile (C:\Path\to\my\Website\node_modules\ts-node\src\index.ts:476:19)
at Module.m._compile (C:\Path\to\my\Website\node_modules\ts-node\src\index.ts:406:44)
at Module._extensions..js (module.js:579:10)
at Object.require.extensions.(anonymous function) [as .js] (C:\Path\to\my\Website\node_modules\ts-node\src\index.ts:409:12)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.parseConfig (C:\Path\to\my\Website\node_modules\karma\lib\config.js:342:22)
at new Server (C:\Path\to\my\Website\node_modules\karma\lib\server.js:56:20)
at Object.exports.run (C:\Path\to\my\Website\node_modules\karma\lib\cli.js:280:7)
at Object.<anonymous> (C:\Path\to\my\Website\node_modules\karma\bin\karma:3:23)
at Module._compile (module.js:570:32)
無效的配置文件通常指出文件無效。似乎是從輸出中缺少的東西... –
@PWKad是否有任何輸出的詳細日誌,因爲這是我所有的控制檯上。 –