未捕获的ReferenceError:系统未定义-Karma-Angular2

时间:2018-08-16 19:52:39

标签: javascript node.js angular karma-jasmine

我正在进行业力测试并出现错误。我正在学习一个教程,所以我不知道它们是什么意思或如何解决它们。错误如下:

Chrome 68.0.3440(Windows 8.1.0.0)错误 未捕获到的ReferenceError:karma-systemjs.config.js:1中未定义系统

Chrome 68.0.3440(Windows 8.1.0.0):执行0的0错误(1.4秒/ 0秒) Chrome 68.0.3440(Windows 8.1.0.0)错误 未捕获的ReferenceError:系统未在karma-test-runner.js:15上定义

Chrome 68.0.3440(Windows 8.1.0.0):执行0的0错误(1.603秒/ 0秒) 16 08 2018 14:55:55.463:WARN [启动器]:Firefox在60000毫秒内未捕获,导致死亡。 16 08 2018 14:55:57.470:WARN [启动器]:Firefox在2000毫秒内没有被杀死,发送了SIGKILL。 16 08 2018 14:55:59.473:WARN [启动器]:Firefox在2000 ms未被SIGKILL杀死,继续。 npm ERR!测试失败。有关更多详细信息,请参见上文。

enter image description here

karma-system.config.js

  System.config({
  baseURL: 'base',
  transpiler: 'typescript',
  typescriptOptions: {emitDecoratorMetadata: true},
  map: {
//    'app' : 'app',
    'rxjs': 'node_modules/rxjs',

    '@angular/common'                  : 'ng:common/bundles/common.umd.js',
    '@angular/compiler'                : 'ng:compiler/bundles/compiler.umd.js',
    '@angular/core'                    : 'ng:core/bundles/core.umd.js',
    '@angular/forms'                   : 'ng:forms/bundles/forms.umd.js',
    '@angular/http'                    : 'ng:http/bundles/http.umd.js',
    '@angular/platform-browser'        : 'ng:platform-browser/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'ng:platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
    '@angular/router'                  : 'ng:router/bundles/router.umd.js',

    '@angular/common/testing'                  : 'ng:common/bundles/common-testing.umd.js',
    '@angular/compiler/testing'                : 'ng:compiler/bundles/compiler-testing.umd.js',
    '@angular/core/testing'                    : 'ng:core/bundles/core-testing.umd.js',
    '@angular/router/testing'                   : 'ng:router/bundles/router-testing.umd.js',
    '@angular/http/testing'                    : 'ng:http/bundles/http-testing.umd.js',
    '@angular/platform-browser/testing'        : 'ng:platform-browser/bundles/platform-browser-testing.umd.js',
    '@angular/platform-browser-dynamic/testing': 'ng:platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
  },
  paths: {
    'ng:': 'node_modules/@angular/'
  },
  packages: {
    'app' : {main: 'main', defaultExtension: 'ts'},
    'rxjs': {main: 'index'}
  }
});



/*
System.config({
  baseURL: 'base',
  transpiler: 'typescript',
  typescriptOptions: {emitDecoratorMetadata: true},
  map: {
    '@angular': 'node_modules/@angular',
    'rxjs': 'node_modules/rxjs'
  },
  meta: {
    '@angular/*': {'format': 'cjs'}
  },
  packages: {
    'app'                              : {main: 'main', defaultExtension: 'ts'},
    'rxjs'                             : {main: 'Rx'},
    '@angular/core'                    : {main: 'index'},
    '@angular/common'                  : {main: 'index'},
    '@angular/compiler'                : {main: 'index'},
    '@angular/forms'                   : {main: 'index'},
    '@angular/http'                    : {main: 'index'},
    '@angular/platform-browser'        : {main: 'index'},
    '@angular/platform-browser-dynamic': {main: 'index'},
    '@angular/router'                  : {main: 'index'}
  }
});
*/

karma-test-runner.js

Error.stackTraceLimit = Infinity;

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

__karma__.loaded = function () {};

function resolveTestFiles() {
  return Object.keys(window.__karma__.files)
      .filter(function (path) { return /\.spec\.ts$/.test(path); })
      .map(function (moduleName) { return System.import(moduleName); });
}

Promise.
  all([
    System.import('@angular/core/testing'),
    System.import('@angular/platform-browser-dynamic/testing')
  ]).
  then(function (modules) {
    var testing = modules[0];
    var browser = modules[1];

    testing.TestBed.initTestEnvironment(
        browser.BrowserDynamicTestingModule,
        browser.platformBrowserDynamicTesting());
  }).
  then(function () { return Promise.all(resolveTestFiles()); }).
  then(function () { __karma__.start(); },
       function (error) { __karma__.error(error.stack || error); });

0 个答案:

没有答案