将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