2016-12-14 6 views
0

Я пытаюсь использовать Karma + Jasmine для модульного тестирования моего приложения Aurelia (+ Webpack + TypeScript). Я попытался использовать тестовый шаблон, который пришел с the skeleton.Karma ERROR [config]: Invalid config file

О проекте каркасного после NPM скрипт работает отлично:

"test": "cross-env NODE_ENV=test ./node_modules/karma/bin/karma start test/karma.conf.js" 

Но когда я попробовал то же самое на мой проект, он бросает ошибку (без дополнительной StackTrace):

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 
    }); 
}; 

Я использую следующие версии пакетов НПМ:

"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", 

Пожалуйста, подсказывают, как это можно решить или, по крайней мере, имеют более (отладка) информация исследовать.

Обновление: Получил ниже StackTrace после 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], поэтому, похоже, в этом есть существенное изменение.