业力/茉莉花超时不运行测试

JavaScript Webpack

神乐

2020-03-24

我正在尝试在通过http://newtriks.com/2013/12/31/automating-react-with-yeoman-and-grunt/生成的项目上从Grunt运行Karma / Jasmine

Karma启动PhantomJS(或Chrome),并且取决于singleRun,它要么超时,要么就坐在那里,什么也不做。我曾尝试进行更改,captureTimeoutbrowserNoActivityTimeout根据有类似问题的人员的解决方案进行了阅读,但这似乎不起作用。

我的相关pacakge版本等:

  • NodeJS的:0.10.25
  • 业力:0.12.16
  • Webpack:1.1.11
  • webpack-dev-server:1.4.1
  • 业力茉莉:0.1.5
  • 的Linux:Ubuntu 14.04

在OS X上发现了同样的问题

我尝试将所有开发依赖项更新到最新版本,但问题仍然存在。

我的控制台输出如下。现在,指向bundle的webpack行是VALID / INVALID令人担忧,但我找不到有关它们含义的任何信息。这是我的控制台输出:

Running "karma:unit" (karma) task
DEBUG [config]: autoWatch set to false, because of singleRun
DEBUG [plugin]: Loading karma-* from /home/ed/workspace/wwb-app/node_modules
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-coffee-preprocessor.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-firefox-launcher.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-html2js-preprocessor.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-jasmine.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-phantomjs-launcher.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-requirejs.
DEBUG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-script-launcher.
DEBG [plugin]: Loading plugin /home/ed/workspace/wwb-app/node_modules/karma-webpack-plugin.
INFO [karma]: Karma v0.12.16 server started at  http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
DEBUG [temp-dir]: Creating temp dir at /tmp/karma-98204612
DEBUG [launcher]: /home/ed/workspace/wwb-app/node_modules/karma-phantomjs-launcher/node_modules/phantomjs/lib/phantom/bin/phantomjs /tmp/karma-98204612/capture.js
Hash: 89285186567c1bc5bb7f
Version: webpack 1.1.11
Time: 2ms
Asset  Size  Chunks       Chunk Names
webpack: bundle is now VALID.
webpack: bundle is now INVALID.
DEBUG [web-server]: serving: /home/ed/workspace/wwb-app/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /home/ed/workspace/wwb-app/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/CjC8pnQq5It2z_kWYB98
DEBUG [karma]: A browser has connected on socket CjC8pnQq5It2z_kWYB98
INFO [PhantomJS 1.9.7 (Linux)]: Connected on socket CjC8pnQq5It2z_kWYB98 with id 98204612
DEBUG [launcher]: PhantomJS (id 98204612) captured in 1.704 secs
WARN [PhantomJS 1.9.7 (Linux)]: Disconnected (1 times), because no message in 30000 ms.

DEBUG [karma]: Run complete, exitting.
DEBUG [launcher]: Disconnecting all browsers
DEBUG [launcher]: Process PhantomJS exited with code 0
DEBUG [temp-dir]: Cleaning temp dir /tmp/karma-98204612
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

这是我的karma.conf.js文件:

'use strict';

module.exports = function (config) {
config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
        'test/helpers/**/*.js',
        'test/spec/components/**/*.js'
    ],
    preprocessors: {
        'test/spec/components/**/*.js': ['webpack']
    },
    webpack: {
        cache: true,
        module: {
            loaders: [{
                test: /\.css$/,
                loader: 'style!css'
            }, {
                test: /\.gif/,
                loader: 'url-loader?limit=10000&minetype=image/gif'
            }, {
                test: /\.jpg/,
                loader: 'url-loader?limit=10000&minetype=image/jpg'
            }, {
                test: /\.png/,
                loader: 'url-loader?limit=10000&minetype=image/png'
            }, {
                test: /\.js$/,
                loader: 'jsx-loader'
            }]
        }
    },
    webpackServer: {
        stats: {
            colors: true
        }
    },
    exclude: [],
    port: 8080,
    logLevel: config.LOG_DEBUG,
    colors: true,
    autoWatch: true,
    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['PhantomJS'],
    reporters: ['progress'],
    captureTimeout: 60000,
    browserNoActivityTimeout: 60000,
    singleRun: true
});
};

第3371篇《业力/茉莉花超时不运行测试》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

8个回答
番长 2020.03.24

这里的OP可能不是这种情况,但是如果您要测试的代码遇到无限循环,则将导致超时断开,就像这样。

LPro 2020.03.24

这就是为什么我遇到此错误,可能会帮助处于类似情况的人的原因。我的主要组件有多个使用不同服务的子组件,其中一个服务进行了HTTP调用,初始化失败,因为我在子组件的ngInit()方法中使用了该服务。为了解决这个问题,我必须在主要组件规格中导入上述服务,并为该服务附加一个模拟程序,此后它开始工作。

Tony凯 2020.03.24

我为自己的环境解决了这个问题。我在全球安装了一堆nodejs软件包。我没有进行回归来确切地确定是什么软件包导致了问题,但是我强烈怀疑在全球范围内安装了业力是原因。

如果您有此问题,请尝试

sudo npm -g remove karma

如果那不起作用,那么我将删除所有全局节点程序包(例如真正的全局程序包,例如yeoman,grunt-cli除外)。然后在本地为您的项目安装。

我还注意到,当您sudo npm -i在OS X上运行时,它将〜/ .npm的所有者更改root,随后的npm -i命令将失败,并出现EACCESS错误。

JinJin 2020.03.24

检查localhost是否正确指向127.0.0.1IP地址,而不是指向不可达的IP,例如,在使用虚拟机的开发环境中可能会发生这种情况。

番长猴子 2020.03.24

另一个可能的解释是RequireJS妨碍了它。如果我在config.frameworks数组中的karma.conf.js中添加“ requirejs”,则会收到此确切错误。这似乎覆盖了本机的require函数,并导致无法执行测试。在我的情况下,触发了describe-block,但是没有触发。

伽罗 2020.03.24

我们在构建服务器上遇到了类似的问题。

将browserNoActivityTimeout增加到一定程度。我们将其提高到60000ms,但是随着单元测试数量的增加,phantomJS无法断开连接的问题又回来了。

我们最终将问题跟踪到了phantomJS可用的RAM中。我们有1100个单元测试,大约需要1m30s来运行,但是phantomJS将无法在60000ms的超时时间内断开连接。

The build node VM RAM was increased from 2GB to 4GB and the 1100 unit tests then took ~45s to run and phantomJS would disconnect with ~5s. A huge improvement.

There are two lessons: 1. PhantomJS is memory hungry, so make sure it has enough RAM to do its thing 2. Profile your code to learn where you can be more efficient with memory usage.

前端古一 2020.03.24

我有同样的问题。从相关的GitHub Issue中,我了解到您可以延长不活动超时时间。

在您的gruntfile或karma配置文件中设置以下Karma配置选项:

browserNoActivityTimeout: 100000

我将其设置为100秒,并且测试成功运行。我不知道是什么原因造成了延迟。

老丝小卤蛋 2020.03.24

我已将我的Karma配置更改为

captureTimeout: 60000, // it was already there
browserDisconnectTimeout : 10000,
browserDisconnectTolerance : 1,
browserNoActivityTimeout : 60000,//by default 10000

我也有200-300个测试,PhantomJS 1.9.8,它只需要大约100 mb的Phantom内存。随着grunt和karma的使用,它们一起使用了大约300mb的内存。

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android