Babel + Mocha堆栈跟踪报告错误的行号

当使用Babel 6和Mocha时,堆栈跟踪报告错误的行号。 我很确定这是因为transpiling增加了额外的代码。 这是Babel 6与Babel 5.x的新行为。 有没有人有一个解决scheme,如何解决这个问题时使用摩卡进行unit testing?

这是我的.babelrcconfiguration:

{ "ignore": [ "node_modules", "bower_components" ], "presets": [ "es2015", "react" ], "plugins": [ "transform-react-constant-elements", "syntax-async-functions", "transform-regenerator" ] } 

注意:不pipe我是否需要('babel-polyfill')在我的应用程序的入口点,这是发生。

示例堆栈跟踪如下所示:

 TypeError: Cannot read property 'should' of undefined at _callee2$ (test/unit/index.test.js:217:34) at step (test/unit/index.test.js:27:284) 

Sourcemaps和retainLines:true选项。 这是一个Gulp任务的例子:

 const babel = require('gulp-babel'); const sourcemaps = require('gulp-sourcemaps'); gulp.task('babel', done => gulp.src('src/**/*.es6') .pipe(sourcemaps.init()) .pipe(babel({ presets: ['es2015', 'stage-0'], retainLines: 'true', })) .pipe(sourcemaps.write('.', { sourceRoot: 'src' })) .pipe(gulp.dest('lib'))); 

你也必须拥有

 require('source-map-support').install(); 

在编译的代码的顶部(只是入口点,即package.json中指定的“main”文件)