2016-11-14 125 views
1

这是我mocha.opts文件:mocha.opts不工作巴贝尔注册

--require babel-polyfill 
--require jsdom-global/register 
--compilers js:babel-register 
--watch 
--recursive 
--bail 
--check-leaks 
--reporter spec 

这是我.babelrc文件,我使用的transpiles根据所提供的目标env预设:

{ 
    "presets":[ 
    "react", 
    [ 
     "env", 
     { 
     "targets":{ 
      "chrome":54, 
      "node":true 
     } 
     } 
    ] 
    ], 
    "plugins":[ 
    "transform-class-properties", 
    ["transform-object-rest-spread", { 
     "useBuiltIns":true 
     } 
    ] 
    ] 
} 

我发现,当我运行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; 
    }); 
}); 

这是错误摩卡抛出:

/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 

回答