2016-05-18 158 views
1

我在Karma使用requirejs來加載模塊,它工作正常。當我將requirejs更改爲webpack時,業力不運行測試用例。我使用mocha,sinon,chai作爲我的測試框架。Karma不運行測試用例

├── 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

在我的測試文件中更改requiredefine後,它現在的工作。 看起來webpack將使用require作爲默認加載Commonjs模塊。

相關問題