use*_*052 5 typescript ecmascript-6 karma-runner
尝试设置 karma 来对我的 ES6 转译代码进行单元测试。完整的工具链是:Typescript -> ES6 -> Babel -> browserify。
在 Karma 之外,我的这条链工作正常(使用 Gulp)。
通过我的 Karma 设置,我在 Typescript 步骤中遇到错误:
错误 TS2318:找不到全局类型“IterableIterator”。12 03 2016 16:52:09.323:错误 [preprocessor.typescript]:错误 TS2318:找不到全局类型“迭代器”。
错误 TS2318:找不到全局类型“迭代器”。12 03 2016 16:52:09.323:错误 [preprocessor.typescript]:错误 TS2318:找不到全局类型“符号”。`
这是我的 karma.conf
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// frameworks to use
frameworks: ['browserify','jasmine'],
preprocessors: {
'src/**/test.ts' : ['typescript', 'babel', 'browserify'],
'tests/**/tests.spec.js' : ['babel', 'browserify']
},
typescriptPreprocessor: {
options: {
target: 'es6'
}
},
babelPreprocessor: {
options: {
presets: ['es2015'],
sourceMap: 'inline'
}
},
browserify: {
debug:true
},
files: [
'src/**/test.ts',
'tests/**/*.js'
],
// list of files to exclude
exclude: [
],
// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],
// web server port
port: 9876,
plugins: [
'karma-typescript-preprocessor',
'karma-babel-Preprocessor',
'karma-browserify',
'karma-jasmine',
'karma-firefox-launcher',
'karma-chrome-launcher'
],
// enable / disable colors in the output (reporters and logs)
colors: false,
// 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,
browsers: ['Chrome'],
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
Run Code Online (Sandbox Code Playgroud)
这是我的 test.ts 文件:
"use strict"
function thisIsAtest(myParam:string) {
const pi = 3.14;
}
Run Code Online (Sandbox Code Playgroud)
Typescript 新手,我的 google 能力让我失望了):
更新: 所以上面的配置使用了 babel 和 typescript karma预处理器。我仍然无法让该工具链正常工作。但我能够通过让 karma-browserify 直接处理转换来实现我的最终目标。所以我的 browserify 部分现在看起来像这样:
browserify: {
debug: true,
plugin: ['tsify'],
transform: [['babelify', {presets:["es2015"], extensions:[".ts",".js"] }]]
},
Run Code Online (Sandbox Code Playgroud)
请注意变换部分中的双括号——当我最初开始走这条路时,忘记了这些让我绊倒了。
| 归档时间: |
|
| 查看次数: |
1456 次 |
| 最近记录: |