使用Karma与SystemJS,gulp和TypeScript时出错

Say*_*Pal 5 typescript karma-runner gulp-karma systemjs karma-qunit

我是新的node.js堆栈之类npm,gulp等等.我之前编写了一些JavaScript单元测试用例,现在想Karma用作测试运行器.然而,经过几次尝试后,我现在完全迷失了.

首先,我有以下项目配置:

  • SystemJS 作为模块加载器.
  • 文件夹结构(为简洁起见,省略了一些):

    project
    |
    |--build //contains all gulp tasks
    |
    |--dist //contains the output (*.html, *.js etc.)
    |
    |--jspm_packages 
    |
    |--node_modules
    |
    |--src //contains the source .html, and *.ts
    |
    |--tests //contains unit tests in *.ts. I also have a gulp task to build tests/**/*.ts to *.js in the same folder.
    |
    |--typings //contains type definitions
    |
    |--config.js //contains SystemJS configuration
    |
    |--karma.conf.js
    
    Run Code Online (Sandbox Code Playgroud)
  • 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
        });
    }
    
    Run Code Online (Sandbox Code Playgroud)

但是,每当我这样做karma start,我都有错误Uncaught TypeError: Unexpected anonymous System.register call..无论如何要解决这个问题?

其他尝试:

  1. 根据https://github.com/karma-runner/gulp-karma,试图创建一个gulp任务.但是有同样的问题.
  2. 试图使用karma-systemjs.而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'
                }
            },
            ...
        });
    }
    
    Run Code Online (Sandbox Code Playgroud)

    在这种情况下,我得到了以下错误,虽然我有两个SystemJsBabel安装:

    [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
    
    Run Code Online (Sandbox Code Playgroud)

在这方面的任何帮助都会很棒.