0

我有一个使用 Maven、Karma、PhantomJS 和 Jasmine 在 Windows7 中使用 Cygwin Bash shell 的现有构建。

我现在正试图在指向同一个工作区的 CentOS VM 上运行相同的构建。

当我在 VM 上运行 Karma 时,它会启动 Karma 和 PhantomJS,“因为 10000 毫秒内没有消息”。我尝试增加捕获超时,但这没有任何区别。

我可以做些什么来获得更多诊断信息,这可能会告诉我为什么没有消息从 Karma 发送到 PhantomJS?

在 Windows 上,我使用的是 Karma v0.12.16 和 PhantomJS 1.9.7。在 CentOS 虚拟机上,我使用的是 Karma v0.12.24 和 PhantomJS 1.9.8。

这是我的“karma.config.js”:

module.exports = function(config) {
    'use strict';
  config.set({
basePath: '../../../..',
frameworks: ['jasmine'],
files: [
    "http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js",
    "http://code.jquery.com/jquery-migrate-1.2.1.js",
    "src/main/webapp/js/libs/jquery.coo.kie.js",
    "src/main/webapp/js/libs/jquery.address-1.3.1.js",
    "src/main/webapp/js/libs/modernizr-1.6.min.js",
    "src/main/webapp/js/libs/underscore.js",
    "src/main/webapp/js/mylibs/util.js",
    "src/main/webapp/js/mylibs/controller.js",
    "src/test/webapp/js/init.js",
    "src/main/webapp/js/mylibs/config.js",
    "src/main/webapp/js/mylibs/controller.daily.js",
    "src/main/webapp/js/mylibs/controller.daily.rate-table.js",
    "src/main/webapp/js/mylibs/controller.diagnostic.page.js",
    "src/main/webapp/js/mylibs/controller.realtime.matrix-view.js",
    "src/main/webapp/js/mylibs/controller.realtime.rate-table.js",
    "src/main/webapp/js/mylibs/controller.realtime.subway-map.js",
    "src/main/webapp/js/mylibs/data.daily.js",
    "src/main/webapp/js/mylibs/data.realtime.js",
    "src/main/webapp/js/mylibs/diagnostic.controller.js",
    "src/main/webapp/js/mylibs/html.js",
    "src/main/webapp/js/mylibs/html.daily.js",
    "src/main/webapp/js/mylibs/html.diagnostic.js",
    "src/main/webapp/js/mylibs/html.realtime.js",
    "src/main/webapp/js/mylibs/html.realtime.matrix-view.js",
    "src/main/webapp/js/mylibs/routes.js",
    "src/main/webapp/js/mylibs/uverse.config.js",
    "src/test/webapp/js/data.daily.test.js",

    "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js",
    "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular-resource.js",
    "src/test/webapp/js/libs/angular-mocks.js",
    "src/main/webapp/js/diag/libs/ui-bootstrap-tpls-0.10.0.js",
    "src/main/webapp/js/diag/libs/ng-table.src.js",
    "src/main/webapp/js/diag/constants.js",
    "src/main/webapp/js/diag/diagapp.js",
    "src/main/webapp/js/diag/diagMod.js",
    "src/main/webapp/js/diag/dataSourcesMod.js",
    "src/main/webapp/js/diag/queriesMod.js",
    "src/main/webapp/js/diag/handlersMod.js",
    "src/main/webapp/js/diag/workflowMappingsMod.js",
    "src/main/webapp/js/diag/configurationMod.js",
    "src/main/webapp/js/diag/commonErrorsMod.js",

    "src/test/webapp/js/diag/diagapp.test.js"
    ],
exclude: [
],
plugins:[
     'karma-jasmine',
     'karma-coverage',
     'karma-junit-reporter',
     'karma-phantomjs-launcher',
     'karma-chrome-launcher',
     'karma-firefox-launcher',
     'karma-ie-launcher'
     ],
preprocessors: {
    "src/main/webapp/js/mylibs/*.js": 'coverage',
    "src/main/webapp/js/diag/*.js": 'coverage',
},
coverageReporter: {
    type: "lcov",
    dir: "target/karma-coverage"
},
junitReporter: {
    outputFile: 'target/surefire-reports/TEST-karma.xml'
},
reporters: ['dots', 'junit'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 60000,
singleRun: false
  });
};

这是我正在运行的 Karma 命令行:

karma start /media/sf_Users/<myuid>/workspace2/SunlightGUI/src/test/webapp
  /js/karma.conf.js --browsers PhantomJS --reporters dots,junit,coverage
  --single-run --no-auto-watch --colors false --log-level info
4

1 回答 1

0

使用以下过程:

  • 打开karma.conf.js
  • websocket从运输中移除:

    transports: ['flashsocket', 'xhr-polling', 'jsonp-polling']
    
  • 使用轮询:

    usePolling: true
    
  • 用于require("os").cwd()获取绝对路径

  • 使用变量来存储带有斜线的绝对路径,例如:

    var foo = process.cwd() + "/";
    config.set({
               basePath: foo,
    
  • 为数组中的每条路径加上绝对路径前缀files,例如:

    foo + 'src/test/webapp/js/diag/diagapp.test.js',
    

参考

于 2015-04-15T17:32:06.507 回答