簡體   English   中英

Karma沒有運行測試用例

[英]Karma not run test cases

我在Karma中使用requirejs來加載模塊,它運行正常。 當我將requirejs更改為webpack ,業力不會運行測試用例。 我用mochasinonchai作為我的測試框架。

├── 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 ,錯誤信息是這樣的: 在此輸入圖像描述

在我的測試文件中更改requiredefine后,它現在正在工作。 似乎webpack將使用require來加載Commonjs模塊作為默認值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM