将Karma与SystemJS、gulp和TypeScript一起使用时出错
我不熟悉将Karma与SystemJS、gulp和TypeScript一起使用时出错,typescript,karma-runner,systemjs,gulp-karma,karma-qunit,Typescript,Karma Runner,Systemjs,Gulp Karma,Karma Qunit,我不熟悉node.js堆栈,比如npm,gulp等等。我以前写过一些JavaScript单元测试用例,现在想使用Karma作为测试运行者。然而,经过几次尝试,我现在完全迷路了 首先,我有以下项目配置: SystemJS作为模块加载器 文件夹结构(为了简洁起见,省略了一些): karma.conf.js // Karma configuration module.exports = function (config) { config.set({ ba
node.js
堆栈,比如npm
,gulp
等等。我以前写过一些JavaScript单元测试用例,现在想使用Karma
作为测试运行者。然而,经过几次尝试,我现在完全迷路了
首先,我有以下项目配置:
作为模块加载器SystemJS
- 文件夹结构(为了简洁起见,省略了一些):
karma.conf.js
// Karma configuration module.exports = function (config) { config.set({ basePath: '', frameworks: [ 'qunit'], files: [ 'jspm_packages/system.js', //'config.js', 'dist/custom/*.js' //, //'tests/**/*.js' ], exclude: [ ], preprocessors: { }, reporters: ['progress'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false, concurrency: Infinity }); }
karma start
时,我都会出现错误未捕获类型错误:意外的匿名System.register调用。
。有没有办法解决这个问题
其他尝试:
karma.conf.js
则不同,如下所示:
// Karma configuration
module.exports = function (config) {
config.set({
...
frameworks: [ 'systemjs', 'qunit'],
plugins: ['karma-systemjs', 'karma-chrome-launcher', 'karma-firefox-launcher'],
systemjs: {
configFile: 'config.js',
serveFiles: ['jspm_packages/**/*.js'],
config: {
transpiler: 'babel'
}
},
...
});
}
在本例中,我得到了以下错误,尽管我同时安装了SystemJs
和Babel
:
[WARNING] Looking up paths with require.resolve() is deprecated.
Please add "systemjs" to your SystemJS config paths.
Cannot find "systemjs".
Did you forget to install it ?
npm install systemjs --save-dev
[WARNING] Looking up paths with require.resolve() is deprecated.
Please add "babel" to your SystemJS config paths.
Cannot find "babel-core".
Did you forget to install it ?
npm install babel-core --save-dev
这方面的任何帮助都将非常有用。也许可以尝试将
systemjs
添加到第一个Karma配置文件中的frameworks
属性中。如果这不起作用,那么将第二个karma conf文件中的systemjs
属性添加到第一个文件中。暂时排除插件
属性。@GenYDeveloper感谢您的评论。这似乎有效,因为它会删除SystemJS
错误。另外,现在Karma完全忽略了测试用例,没有运行任何测试用例。控制台上的消息是0个错误中的0个执行。有什么原因吗?您是否取消了对files
属性上的test files数组值的注释?是的,我已经取消了注释,目前只测试了一个模块的单元测试:tests/custom/MyTargetModule.js
。不幸的是,我自己从来没有遇到过这个问题,也不知道解决方案。我现在很忙,但我有时间的时候会去看看。
[WARNING] Looking up paths with require.resolve() is deprecated.
Please add "systemjs" to your SystemJS config paths.
Cannot find "systemjs".
Did you forget to install it ?
npm install systemjs --save-dev
[WARNING] Looking up paths with require.resolve() is deprecated.
Please add "babel" to your SystemJS config paths.
Cannot find "babel-core".
Did you forget to install it ?
npm install babel-core --save-dev