简体   繁体   English

SystemJS + Karma + TypeScript - 未运行测试

[英]SystemJS + Karma + TypeScript - Not running test

I am trying to run some unit tests for few days now without success. 我试图在几天内运行一些单元测试但没有成功。 My application is written in typescript (the unit tests are written in typescript as well). 我的应用程序是用typescript编写的(单元测试也是用typescript编写的)。 Here is my karma configuration file: 这是我的业力配置文件:

module.exports = function (config) {
  config.set({

    basePath: "../../../../",

    frameworks: [
      "jasmine",
      "systemjs"
    ],

    browsers: ['PhantomJS'],

    singleRun: true,
    reporters: ['progress'],

    systemjs: {
      config: {
        paths: {
          systemjs: "src/main/webapp/static/js/engage/lib/bower/system.js/dist/system.src.js",
          typescript: "build/node_modules/typescript/lib/typescript.js"
        },
        transpiler: "typescript"
      },

      // testFileSuffix: ".spec.ts"
    },

    files: [
      'src/main/webapp/static/js/engage/dist/vendor/vendor.min.js',
      'src/main/webapp/static/js/engage/lib/bower/system.js/dist/system-polyfills.src.js',
      'src/main/webapp/static/js/engage/lib/bower/angular-mocks/angular-mocks.js',
      {pattern: "src/main/webapp/static/js/engage/app/**/*.spec.ts", served: true, included: false}
    ]
  });
};

When I run karma start I get the following error: 当我运行karma start我收到以下错误:

05 09 2016 21:39:45.543:INFO [karma]: Karma v1.2.0 server started at http://localhost:9876/
05 09 2016 21:39:45.546:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
05 09 2016 21:39:45.558:INFO [launcher]: Starting browser PhantomJS
05 09 2016 21:39:47.631:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket /#c-ZoxCczyYymPDAtAAAA with id 8911412
05 09 2016 21:39:47.650:WARN [web-server]: 404: /base/src/main/webapp/static/js/engage/lib/bower/system.js/dist/system-polyfills.js
PhantomJS 1.9.8 (Mac OS X 0.0.0) ERROR
  You need to include some adapter that implements __karma__.start method!

If I change the browser property to Chrome, I get the following error: 如果我将浏览器属性更改为Chrome,则会收到以下错误:

Chrome 52.0.2743 (Mac OS X 10.11.6) ERROR
  Error: ReferenceError: jasmineRequire is not defined
            at eval (build/node_modules/karma-jasmine/lib/boot.js:14:32)
            at eval (build/node_modules/karma-jasmine/lib/boot.js:41:2)
        Evaluating build/node_modules/karma-jasmine/lib/boot.js
        Error loading build/node_modules/karma-jasmine/lib/boot.js

Here is my package.json relevant dependencies: 这是我的package.json相关依赖项:

"phantomjs": "^1.9.11",
"karma-systemjs": "^0.14.0",
"karma-jasmine": "^1.0.2",
"karma-chrome-launcher": "^0.1.5",
"jasmine-core": "^2.5.0"

Any help would be appreciated! 任何帮助,将不胜感激!

  1. I would try to include systemjs as first framework as it is written in documentation 我会尝试将systemjs包含在第一个框架中,因为它是在文档中编写的
  2. Compile your typescript before loading it with systemjs and don't use systemjs typescript compile. 在使用systemjs加载之前编译你的打字稿,不要使用systemjs typescript compile。 That will decrease complexity of your karma tests which makes them more solid 这将降低你的业力测试的复杂性,使他们更加坚实
  3. Try changing included to true for your spec files, that helped me with some issues. 尝试将spec包含更改为true,这有助于解决一些问题。 But I'm not sure about that 但我不确定
  4. leave your basePath at ./ as this als just makes trouble 将你的basePath留在./,因为这只会带来麻烦
  5. Check the path to your system.js as it throws a 404 error 检查system.js的路径,因为它会抛出404错误

My configuration for system.js looks like this 我对system.js的配置如下所示

systemjs: {
    configFile: 'dev/systemjs.config.js',
    config: {
        map: {
            'systemjs':          'node_modules/systemjs/dist/system.js',
            'system-polyfills':  'node_modules/systemjs/dist/system-polyfills.js',
            'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js'
        }
    }
}

Maybe also some of the configuration snippets from this questions might help: Angular 2 + Karma + karma-jspm + karma-coverage + typescript report phantomJS failure 也许这个问题的一些配置片段可能会有所帮助: Angular 2 + Karma + karma-jspm + karma-coverage + typescript报告phantomJS失败

Try to add the plugins option to the karma config 尝试将插件选项添加到karma配置中

plugins: [
  'karma-jasmine',
  'karma-chrome-launcher'
],

Use the last node.js 6.5 and update your dependencies to the latest version 使用最后一个node.js 6.5并将依赖项更新为最新版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM