我试过使用grunt-mocha和requirejs,但是我得到了以下错误:
Warning: PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue.如果我尝试在mochajs.org上使用最简单的示例--它可以工作,但出于某些原因,它不适用于需求。
这是我的档案。
test/browser/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');
});
});test/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.所以我很确定没有句法上的错误,而且应该能用。我可能只是在放屁:)
任何想法都将不胜感激。谢谢各位
发布于 2017-07-06 10:54:24
我也有同样的问题--我用grunt-mocha-test插件解决了这个问题。我将grunt文件中的任务命名更改为mochaTest,并通过以下方式安装了grunt-mocha-test:
npm install grunt-mocha-test --save-dev现在起作用了。
https://stackoverflow.com/questions/40208690
复制相似问题