Reputation: 4956
I am trying to use Karma + Jasmine for unit testing my Aurelia (+ Webpack + TypeScript) app. I tried to use the testing boilerplate that came with the skeleton.
On the skeleton project, following npm script runs perfectly:
"test": "cross-env NODE_ENV=test ./node_modules/karma/bin/karma start test/karma.conf.js"
But when I tried the same on my project, it throws error (without further stacktrace):
DEBUG [config]: Loading config C:\Path\to\my\Website\test\karma.conf.js
ERROR [config]: Invalid config file!
It does not provide any other information about why the configuration is invalid.
Below is the karma.conf.js
that came with the skeleton:
"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
});
};
To isolate the issue, I also tried to start generating a new karma.conf.js
at my website root, with karma init
, and I faced exactly the same error with karma start
. Below is the config file, thus generated:
// 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
});
};
I am using the following versions of the npm packages:
"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",
Please suggest how this can be resolved or at least have more (debug) information to investigate.
Update: Got the below stacktrace after rimraf
ing the node_modules
and reinstalling the packages:
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)
Upvotes: 1
Views: 8259
Reputation: 5207
Having had the same issue this morning, I found that changing the ts-node version resolved this issue. I can reproduce this issue without any configuration changes with [email protected], but the entire build works fine with [email protected], so it seems there's a breaking change in that.
Upvotes: 2