Karma:使用phantomJS运行时缺少测试

时间:2014-07-02 10:42:07

标签: javascript requirejs jasmine phantomjs karma-runner

在phantomJS环境中运行测试时,我的业力配置存在问题。测试结果输出如下:

  

运行“业力:构建”(业力)任务INFO [业力]:业力v0.12.16服务器   从http:// localhost:9876 / INFO [launcher]开始:启动浏览器   PhantomJS INFO [PhantomJS 1.9.7(Mac OS X)]:连接在套接字上   1PbFcS7IUZXvE6I7cMyv,ID为60460739 ......... PhantomJS 1.9.7(Mac   OS X):执行了0 of SUCCESS(0.881秒/0.022秒)

注意结果:0个测试中有9个成功执行。什么!?

如果我将浏览器更改为chrome,它看起来像这样:

  

运行“业力:构建”(业力)任务INFO [业力]:业力v0.12.16服务器   从http:// localhost:9876 / INFO [launcher]开始:启动浏览器   Chrome INFO [Chrome 35.0.1916(Mac OS X 10.9.3)]:已在套接字上连接   5L19NgN3Bi5lD_XwmVZr,ID为93959653   .................................................. ..............................   .................................................. ..............................   .................................................. ............ Chrome   25.0.1916(Mac OS X 10.9.3):成功222次成功222秒(0.375秒/ 0.352秒)

现在,我发现并执行了所有222个测试。

问题不仅发生在我的Macbook上,也发生在Linux服务器上。使用phantomjs运行时的测试次数会不时变化。有时是0的0,有时是0的120.我在这里看不到一个模式。

我现在有点失落。我已经更新了大多数依赖项:

  • node.js 0.10.29
  • Karma 0.12.16(所有业力插件使用当前版本)
  • grunt-karma 0.8.3
  • grunt 0.4.2
  • phantomJS 1.9.7

茉莉花单元测试和正在测试的应用程序被编写为AMD模块,因此业力与karma-requirejs和karma-jasmine一起运行。

这是我的karma.conf.js:

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine', 'requirejs'],
        files: [
            {pattern: 'test/external-libs/angular-mocks.js', included: false},
            {pattern: 'app/**/*', included: false},
            {pattern: 'test/unit/**/*.js', included: false},
            'test/main-test.js'
        ],
        exclude: [

        ],
        reporters: ['dots'],
        port: 9876,
        colors: false,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ["PhantomJS"],
        captureTimeout: 60000,
        singleRun: false
    });
};

这是在加载所有requireJS依赖项后开始karma测试的main-test.js:

(function (window, require) {
    "use strict";
    var file, requireModules;
    requireModules = [];
    for (file in window.__karma__.files) {
        if (window.__karma__.files.hasOwnProperty(file)) {
            if (file.substring(file.length - 7, file.length) === 'Test.js') {
                requireModules.push(file);
            }
        }
    }

    requireModules.push("jquery");
    requireModules.push("moment");
    requireModules.push("app");
    requireModules.push("mocks");

    require({
        baseUrl:'/base/app/modules',
        paths:{
            'angular':'/base/app/external-libs/angular',
            'jquery':'/base/app/external-libs/jquery',
            'jquery.mobile':'/base/app/external-libs/jquery.mobile.js',
            'adapter':'/base/app/external-libs/jquery-mobile-angular-adapter.js',
            'moment': '/base/app/external-libs/moment.min',
            'add2Home': '/base/app/external-libs/add2home',
            'mocks':'/base/test/external-libs/angular-mocks',
            'signaturePad': '/base/app/external-libs/signature_pad'
        },
        shim:{
            'angular':{ deps:['jquery'], exports:'angular' },
            'mocks':{ deps:['angular'], exports:'mocks' }
        }
    }, requireModules, function () {
        window.__karma__.start();
    }, function (err) {
        var failedModules = err.requireModules;
        console.log("err", err);

        if (failedModules && failedModules[0]) {
            throw new Error("Modul konnte nicht geladen werden: " + failedModules);
        } else {
            throw new Error("Unbekannter Fehler:" + err);
        }
    });
}(window, require));

以下是启用了调试日志记录时运行karma时的输出:

Running "karma:build" (karma) task
DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from /Users/mzrinck/projects/hwa-mobile/node_modules
DEBUG [plugin]: Loading plugin /Users/mzrinck/projects/hwa-mobile/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Users/mzrinck/projects/hwa-mobile/node_modules/karma-coverage.
DEBUG [plugin]: Loading plugin /Users/mzrinck/projects/hwa-mobile/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /Users/mzrinck/projects/hwa-mobile/node_modules/karma-junit-reporter.
DEBUG [plugin]: Loading plugin /Users/mzrinck/projects/hwa-mobile/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /Users/mzrinck/projects/hwa-mobile/node_modules/karma-requirejs.
INFO [karma]: Karma v0.12.16 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /var/folders/cc/76k3g2s94x9556104ps2cxn40000gn/T/karma-64663676
DEBUG [launcher]: /Users/mzrinck/projects/hwa-mobile/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /var/folders/cc/76k3g2s94x9556104ps2cxn40000gn/T/karma-64663676/capture.js
DEBUG [watcher]: Ignored directory "/Users/mzrinck/projects/hwa-mobile/app/css"
[….]
DEBUG [watcher]: Resolved files:
        /Users/mzrinck/projects/hwa-mobile/node_modules/requirejs/require.js
        /Users/mzrinck/projects/hwa-mobile/node_modules/karma-requirejs/lib/adapter.js
[..]
        /Users/mzrinck/projects/hwa-mobile/test/main-test.js
DEBUG [web-server]: serving: /Users/mzrinck/projects/hwa-mobile/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Users/mzrinck/projects/hwa-mobile/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/ytiWxyQedIcvJajRphM8
DEBUG [karma]: A browser has connected on socket ytiWxyQedIcvJajRphM8
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket ytiWxyQedIcvJajRphM8 with id 64663676
DEBUG [launcher]: PhantomJS (id 64663676) captured in 1.26 secs
DEBUG [web-server]: serving: /Users/mzrinck/projects/hwa-mobile/node_modules/karma/static/context.html
DEBUG [web-server]: serving (cached): /Users/mzrinck/projects/hwa-mobile/node_modules/requirejs/require.js
[…]
DEBUG [PhantomJS 1.9.7 (Mac OS X)]: Disconnected during run, waiting 2000ms for reconnecting.
DEBUG [web-server]: upgrade /socket.io/1/websocket/VJFvQl7_d-d3_cm7phM9
DEBUG [karma]: A browser has connected on socket VJFvQl7_d-d3_cm7phM9
DEBUG [PhantomJS 1.9.7 (Mac OS X)]: Reconnected on VJFvQl7_d-d3_cm7phM9.
..........
PhantomJS 1.9.7 (Mac OS X): Executed 10 of 0 SUCCESS (0.889 secs / 0.022 secs)
DEBUG [karma]: Run complete, exitting.
DEBUG [launcher]: Disconnecting all browsers
DEBUG [launcher]: Process PhantomJS exited with code 0
DEBUG [temp-dir]: Cleaning temp dir /var/folders/cc/76k3g2s94x9556104ps2cxn40000gn/T/karma-64663676

0 个答案:

没有答案