我正在尝试更新一个Angular 2项目,实现Angular 2官方变更日志中所示的更改。
(如果你想知道细节,我已经完成了一个用Angular 2 2.0.0-beta构建的教程。现在想把它转换成最新的Angular版本,即2.0.0-rc.6。教程本身可以在Youtube上找到,最终的代码可以在GitHub上找到。
我卡在了下面的步骤:Angular 2 2.0.0-beta版本的变更日志。
你还需要在你的Karma或其他测试配置中添加依赖项'node_modules/zone.js/dist/fake-async-test.js'作为服务文件。
我不确定我完全理解这是什么意思,我没有看到一个明显的方法来实现它。这个项目的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 ...
安装npm包,或者更有可能通过修改package.json
中的依赖项。我不知道这是否相关,但教程的原始(即Ang2-beta.13) package.json
将zone.js ^0.6.6
列为依赖项,而最新的Angular2 (rc.6)的更改日志将zone.js ^0.6.17
列为其对等依赖项更新。
我在哪里找过?好吧,我在这个预先存在的配置文件中没有看到这个新依赖项的明显位置,所以我怀疑它可能涉及到这个项目以前不需要的配置属性。karma init
提出的问题似乎太基本了,不相关。我已经查看了karma配置选项的完整列表,并没有看到一个明显的位置(该页面甚至没有包含"依赖"或"服务"这个词)。我也看了官方的Karma文档中的文件和插件,都没有提供一个明显的解决方案。
那么,我如何做更改日志要求,即我如何"添加依赖'node_modules/zone.js/dist/fake-async-test.js'作为服务文件在[我的]Karma…配置"?
结果证明答案可能嵌入在版本rc.6的更改日志中。测试配置:由于zone.js对等依赖升级,不同区域规范加载的顺序发生了变化。请查看这个示例Karma配置。"该karma配置示例显示如下:
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
的语法。
这可能是对我这个问题最好的回答了。但是,更一般地说,链接的示例karma配置文件来自版本rc的更改日志。