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

时间:2016-10-23 23:03:35

标签: phantomjs mocha

我尝试使用带有requirejs的grunt-mocha,但是我收到了这个错误:

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

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

这是我的档案。

测试/浏览器/ runner.html:

<!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:(到目前为止,我尝试了多个版本,这是最新版本,但仍然超时)

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');
    });

});

测试/ SRC / test.component.js:

define(function(require) {
    describe('Component', function() {
        it('test', function() {
            console.log('testing...');
        });
    });
});

Gruntfile.js

module.exports = function(grunt) {

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

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

输出是这样的:

$ 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.

所以我很确定没有语法错误,它应该有效。我可能只是一个大脑放屁:)

任何想法都会非常感激。 谢谢你们

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题 - 我用grunt-mocha-test插件解决了这个问题。我将grunt文件中的任务命名更改为mochaTest,并将grunt-mocha-test安装为:

npm install grunt-mocha-test --save-dev

现在它正在运作。

相关问题