2016-12-14 83 views
0

我正在尝试使用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) 
+0

无效的配置文件通常指出文件无效。似乎是从输出中缺少的东西... –

+0

@PWKad是否有任何输出的详细日志,因为这是我所有的控制台上。 –

回答

1

今天上午有过同样的问题,我发现改变解决了这个问题的TS-节点版本。我可以在[email protected]没有任何配置更改的情况下重现此问题,但是整个构建可以在[email protected]上正常工作,所以看起来有一个突破性的变化。