首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >grunt- Mocha : PhantomJS超时,可能是由于缺少Mocha run()调用

grunt- Mocha : PhantomJS超时,可能是由于缺少Mocha run()调用
EN

Stack Overflow用户
提问于 2016-10-23 23:03:35
回答 1查看 707关注 0票数 2

我试过使用grunt-mocha和requirejs,但是我得到了以下错误:

代码语言:javascript
复制
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

如果我尝试在mochajs.org上使用最简单的示例--它可以工作,但出于某些原因,它不适用于需求。

这是我的档案。

test/browser/runner.html:

代码语言:javascript
复制
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Browser test</title>
    <link rel="stylesheet" media="all" href="./../../bower_components/mocha/mocha.css">
</head>
<body>

    <div id="mocha"></div>

    <script data-main="runner.js" src="./../../bower_components/requirejs/require.js"></script>
</body>
</html>

test/browser/runner.js: (到目前为止,我尝试了多个版本,这是最近的版本,但仍然超时)

代码语言:javascript
复制
requirejs.config({
    baseUrl: './../../',
    paths: {
        'jquery': 'bower_components/jquery/dist/jquery',
        'chai': 'bower_components/chai/chai',
        'mocha': 'bower_components/mocha/mocha'
    },
    shim: {}
});

define(function(require) {

    require('chai');
    require('mocha');

    mocha.setup('bdd');

    require([
        'test/src/test.component'
    ], function() {
        console.log('component success');
        mocha.run();
        console.log('mocha should be running');
    }, function() {
        console.log('component error');
    });

});

test/src/test.component.js:

代码语言:javascript
复制
define(function(require) {
    describe('Component', function() {
        it('test', function() {
            console.log('testing...');
        });
    });
});

Gruntfile.js

代码语言:javascript
复制
module.exports = function(grunt) {

    grunt.initConfig({
        mocha: {
            options: {
                reporter: 'Spec',
                log: true,
                run: true
            },
            src: ['./test/**/*.html']
        }
    });

    grunt.loadNpmTasks('grunt-mocha');
};

产出如下:

代码语言:javascript
复制
$ grunt mocha
Running "mocha:src" (mocha) task
Testing: ./test/browser/runner.html
component success
mocha should be running
testing...

Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.

Aborted due to warnings.

所以我很确定没有句法上的错误,而且应该能用。我可能只是在放屁:)

任何想法都将不胜感激。谢谢各位

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-06 10:54:24

我也有同样的问题--我用grunt-mocha-test插件解决了这个问题。我将grunt文件中的任务命名更改为mochaTest,并通过以下方式安装了grunt-mocha-test

代码语言:javascript
复制
npm install grunt-mocha-test --save-dev

现在起作用了。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40208690

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档