mocha-webpack编译无法读取未定义的属性'babel'

时间:2018-06-08 05:27:44

标签: reactjs webpack mocha mocha-webpack

单元测试时Webpack编译错误。我尝试修改测试文件但仍然如此,它应该是webpack配置问题,测试错误组件错误

单元测试时Webpack编译错误。我尝试修改测试文件但仍然如此,它应该是webpack配置问题,测试错误组件错误 webpack.test.config.js

const path = require('path');    
const config = {
  entry: {
    vendor: ["babel-polyfill", "react", "react-dom"],
    app: './index.js'
  },
  resolve: {
    alias: {
      'fonts': path.resolve(__dirname, 'public/fonts/'),
      '@components': path.resolve(__dirname, 'src/components/'),
      '@services': path.resolve(__dirname, 'src/services/'),
      '@routes': path.resolve(__dirname, 'src/routes/'),
      '@utils': path.resolve(__dirname, 'src/utils/'),
      '@less': path.resolve(__dirname, 'src/less/'),
      '@images': path.resolve(__dirname, 'public/images/'),
      '@public': path.resolve(__dirname, 'public/'),
    }
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /node_modules/,
      loader: 'babel-loader',
      query: {
        presets: ['react', 'es2015', 'stage-0']
      }
    }, {
      test: /\.less$/,
      exclude: /node_modules/,
      loader: 'style-loader!css-loader!less-loader'
    }]
  }
};

module.exports = config;

Agent.spec.js

import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import Agent from '@components/agent/index';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

describe('<Agent />', () => {
  it('Agent renderning', function () {
    let app = shallow(<Agent/>);
    expect(app.find('button').exists());
  });
});

错误

 WEBPACK  Failed to compile with 1 error(s)

Error in ./test/unit/specs/Agent.spec.js

   TypeError: Cannot read property 'babel' of undefined

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ unit: `mocha-webpack --recursive test/unit/specs/*.js --webpack-config webpack.test.config.js`
npm ERR! Exit status 1

0 个答案:

没有答案