我如何 "add a served file as a dependency" 在我的 Karma 配置中为 Angular 2 项目?

How do I "add a served file as a dependency" in my Karma configuration for an Angular 2 project?

我正在尝试通过实施官方 Angular 2 更改日志中指示的更改来更新 Angular 2 项目。

(如果您想了解详细信息,我完全完成了使用 Angular 2 版本 2.0.0-beta.13 构建的教程,现在想将其转换为当前最新的 Angular,即版本 2.0.0-rc.6。教程本身可以在 Youtube and the final code can be found on GitHub 上找到。)

我卡在了以下步骤:change log for Angular 2 version 2.0.0-beta.16 说明如下:

You will also need to add the dependency 'node_modules/zone.js/dist/fake-async-test.js' as a served file in your Karma or other test configuration.

我不确定我是否完全理解这意味着什么,而且我没有看到一个明显的实现方法。此项目的 karma.conf.js 文件如下:

// Karma configuration

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

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['browserify', 'source-map-support', 'jasmine'],


    // list of files / patterns to load in the browser
    files: [
      'test/init.js',
      'src/**/*.spec.js'
    ],


    // list of files to exclude
    exclude: [
    ],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'test/init.js': ['browserify'],
      'src/**/*.spec.js': ['browserify']
    },


    browserify: {
      debug: true,
      transform: ['babelify']
    },

    specReporter: {
        maxLogLines: 5,
        suppressErrorSummary: true,
        suppressFailed: false,
        suppressPassed: false,
        suppressSkipped: true,
        showSpecTiming: true
      },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['spec'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultanous
    concurrency: Infinity
  })
};

我怀疑解决方案将涉及对上述 karma.conf.js 文件的更改,但也可能通过命令行 npm install ... 或者更有可能通过修改package.json 中的依赖项。我不知道这是否相关,但教程的原始版本(即 Ang2-beta.13)package.jsonzone.js ^0.6.6 列为依赖项,而最新的 Angular2 的更改日志(rc.6) 在其对等依赖更新中列出 zone.js ^0.6.17

我在哪里看过?好吧,我没有在这个预先存在的配置文件中看到一个明显的地方来放置这个新的依赖项,所以我怀疑它可能涉及这个项目以前不需要的配置 属性。 questions asked by karma init seem too basic to be relevant. I have looked over the complete list of karma configuration options and don't see an obvious place for this (and that page doesn't even contain the words "dependency" or "served"). I have also looked over the official Karma documentation for files and plugins 和两者都没有提供明显的解决方案。

那么,我该如何执行更改日志的要求,即我如何 "add the dependency 'node_modules/zone.js/dist/fake-async-test.js' as a served file in [my] Karma ... configuration"?

原来答案很可能嵌入在change log for version rc.6. There, they state the following under "Breaking Changes": "testing config: due to zone.js peer-dependency upgrade, the order in which various zone specs are loaded has changed. Please see this example Karma config." That example karma config中显示如下:

config.set({
  files: [
    ...,
    // Reflect and Zone.js
    'node_modules/reflect-metadata/Reflect.js',
    'node_modules/zone.js/dist/zone.js',
    'node_modules/zone.js/dist/long-stack-trace-zone.js',
    'node_modules/zone.js/dist/proxy.js',
    'node_modules/zone.js/dist/sync-test.js',
    'node_modules/zone.js/dist/jasmine-patch.js',
    'node_modules/zone.js/dist/async-test.js',
    'node_modules/zone.js/dist/fake-async-test.js',
    ...
  ],
  ...
});

我还不知道依赖项列表中有多少是相关的,但至少它显示了包含 fake-async-test.js.

的语法

这可能是对我的具体问题的最佳回答。然而,更一般地说,来自 rc.6 版本更改日志的链接示例 karma 配置文件可能会帮助我完成整个项目更新。