2016-05-18 2 views
1

Я использовал requirejs в Карме для загрузки модулей, она отлично работала. Когда я меняю requirejs на webpack, карма не запускает тестовые кейсы. Я использую mocha, sinon, chai как моя тестовая структура.Карма не запускает тестовые кейсы

├── src 
| ├── js 
|  └── a.js 
├── test 
| ├── spec 
|  └── test_a.js 

Вот мой karma.conf.js:

var webpackConfig = require("../webpack.config"); 

module.exports = function(config) { 
    config.set({ 
     basePath: '../', 

     frameworks: ['mocha', 'chai', 'sinon'], 

     files: [ 
      'test/**/test_*.js' 
     ], 

     preprocessors: { 
     'test/**/test_*.js': ['webpack'] 
     }, 

     webpack: webpackConfig, 

     proxies: { 
      '/data/': '/base/test/data/' 
     }, 

     exclude: [], 

     client: { 
      mocha: { 
       reporter: 'html', 
       ui: 'bdd' 
      } 
     }, 

     reporters: ['progress'], 

     port: 9876, 

     colors: true, 

     logLevel: config.LOG_DEBUG, 

     autoWatch: false, 

     browsers: ['PhantomJS', 'Chrome'], 

     singleRun: false, 

     concurrency: Infinity 
    }) 
} 

И мой webpack.config.js является:

var webpack = require('webpack'); 
var path = require('path'); 

module.exports = { 
    context: path.join(__dirname, 'src'), 

    entry: { 
     bundle1: './initializer.js' 
    }, 

    output: { 
     path: path.join(__dirname, 'src'), 
     filename: '[name].js' 
    }, 

    resolve: { 
     extensions: ['', '.js'], 
     modulesDirectories: ["./src", "node_modules"] 
    }, 

    devtool: 'inline-source-map', 

    module: { 
     loaders: [] 
    } 
} 

Мои test_a.js является:

require([ 
    'jquery', 
    'src/js/a' 
], function($, A) { // $ and A load successfully 

    describe('A', function() { 
     beforeEach(function() { 
      //**** 
     }); 

     afterEach(function() { 
      //**** 
     }); 

     describe('#on()', function() { // will come to this line 
      it('should ....', function() { //will come to this line too 
       assert.ok(1 > 0, "A is working"); // never run into the function 
      }); 
     }); 
    } 

}

Когда я бегу karma, сообщение об ошибке, как это: enter image description here

ответ

0

После изменения require к define в моем тестовом файле, он работает. Кажется, webpack будет использовать require для загрузки модуля Commonjs по умолчанию.

Смежные вопросы