【发布时间】:2015-05-12 15:50:23
【问题描述】:
我正在尝试运行 Karma-babel-preprocessor 和一个简单的 ES6 生成器:
//require('babel/polyfill');
describe("how Generators work", function() {
it("will allow generator functions", function() {
/*function * numbers() {
yield 1;
yield 2;
yield 3;
};*/
let numbers = {
[Symbol.iterator]:function*(){
yield 1;
yield 2;
yield 3;
}
}
let sum = 0;
for(n of numbers){
sum += n;
}
expect(sum).toBe(6);
});
});
由此我使用 babel 生成了我的测试文件(ES6 => ES5):
babel src --watch --out-dir tests
然后我运行karma start 我得到错误:
ReferenceError: regeneratorRuntime is not defined”。
karma.conf.js 中的相关位:
// list of files / patterns to load in the browser
files: [
'test-main.js',
{pattern: 'tests/*.js', included: true}
],
// 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: {
'src/*.js': ['babel']
},
'babelPreprocessor': {
options: {
sourceMap: 'inline'
},
filename: function(file) {
return file.originalPath.replace(/\.js$/, '.es5.js');
},
sourceFileName: function(file) {
return file.originalPath;
}
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
我可以使用许多 ES6 特性,包括箭头。只是不要继续使用生成器。
【问题讨论】:
标签: javascript karma-runner babeljs karma-babel-preprocessor