我正在尝试运行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);
});
});
Run Code Online (Sandbox Code Playgroud)
从这里我用babel生成了我的测试文件(ES6 => ES5):
babel src --watch --out-dir tests
然后我跑了karma start我得到错误:
ReferenceError:未定义"regeneratorRuntime".
karma.conf.js中的相关位:
// list of files / patterns to load in the browser
files: [ …Run Code Online (Sandbox Code Playgroud) 打字稿项目,使用打字稿mocha测试.项目应该从Typescript转换到ES6,然后通过Babel转换成几个可发送的捆绑包.
我想通过Karma(最终是BrowserStack)在浏览器中运行所有测试,而不是将由babel生成的相同转换版本.
我有karma-typescript + mocha工作,但仅限于es2017兼容的浏览器.问题是插入两者之间的babel.
我想我已经尝试了我能想到的一切,但是:
some/some.js文件时它会失败,这似乎只存在于业力记忆中.还有上述所有以及更多的变化,其中没有一个起作用.
karma-babel-preprocessor我认为这应该是一个正确的方法,所以我发布了一个项目,我目前的状态:https://github.com/anpur/karma-typescript-babelify.
这是我的一部分karma.conf.js:
frameworks: ['mocha', 'karma-typescript'],
preprocessors: {
'src/*.ts': ['karma-typescript', 'babel'],
},
babelPreprocessor: {
options: {
presets: [
[ 'es2015' ]
]
}
},
karmaTypescriptConfig: {
compilerOptions: {
sourceMap: true,
target: 'es6'
},
bundlerOptions: {
addNodeGlobals: true,
sourceMap: true
},
tsconfig: './tsconfig.json'
},
Run Code Online (Sandbox Code Playgroud)
Karma能够在这个设置中进行转换 …
babel typescript karma-runner karma-babel-preprocessor karma-typescript