[英]mocha.opts not working with babel-register
This is my mocha.opts
file: 这是我的
mocha.opts
文件:
--require babel-polyfill
--require jsdom-global/register
--compilers js:babel-register
--watch
--recursive
--bail
--check-leaks
--reporter spec
This is my .babelrc
file, I am using the env
preset which transpiles based on the targets provided: 这是我的
.babelrc
文件,我使用的env
预设根据提供的目标进行转换:
{
"presets":[
"react",
[
"env",
{
"targets":{
"chrome":54,
"node":true
}
}
]
],
"plugins":[
"transform-class-properties",
["transform-object-rest-spread", {
"useBuiltIns":true
}
]
]
}
I find that when I run mocha
, node objects violently to the use of import
which works correctly in my code: 我发现当我运行
mocha
,节点对象猛烈地使用import
在我的代码中正常工作:
/* eslint-env node, mocha*/
import chai, { expect } from 'chai';
import { shallow, mount } from 'enzyme';
import chaiEnzyme from 'chai-enzyme';
chai.use(chaiEnzyme());
describe('EllipsisText', function(){
it('exists', function() {
expect(EllipsisText).to.exist;
});
});
This is the error that mocha throws: 这是mocha抛出的错误:
/home/vamsi/Do/css-in-js-test/test/EllipsisText.js:2
import chai, { expect } from 'chai';
^^^^^^
SyntaxError: Unexpected token import
at Object.exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:513:28)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at /home/vamsi/.nvm/v6.2.0/lib/node_modules/mocha/lib/mocha.js:220:27
at Array.forEach (native)
at Mocha.loadFiles (/home/vamsi/.nvm/v6.2.0/lib/node_modules/mocha/lib/mocha.js:217:14)
at Mocha.run (/home/vamsi/.nvm/v6.2.0/lib/node_modules/mocha/lib/mocha.js:469:10)
at Object.<anonymous> (/home/vamsi/.nvm/v6.2.0/lib/node_modules/mocha/bin/_mocha:404:18)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:449:3
When using babel, mocha needs to be run like this: 当使用babel时,mocha需要像这样运行:
mocha --compilers js:babel-core/register
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.