10

プロジェクトの足場としてYeomanを使用しています。PhantomJSベースのテスト ランナーなど、いくつかの便利な機能が付属しています。

私の問題は、私のテストはブラウザーで正しく実行されますが、CLI で PhantomJS を使用してテストを実行しようとするとタイムアウトすることです。

私のテストは次のindex.htmlようになります。

<!doctype html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>Mocha Spec Runner</title>
  <link rel="stylesheet" href="lib/mocha/mocha.css">
</head>
<body>
  <div id="mocha"></div>
  <script src="lib/mocha/mocha.js"></script>
  <!-- assertion framework -->
  <script src="lib/chai.js"></script>

  <!-- include source files here... -->
  <script data-main="scripts/main" src="scripts/vendor/require.js"></script>

  <script>
    mocha.setup({ui: 'bdd', ignoreLeaks: true});
    expect = chai.expect;
    should = chai.should();
    require(['../spec/map.spec'], function () {
      setTimeout(function () {
        require(['../runner/mocha']);
      }, 100);
    });
  </script> 

</body>
</html>

ここにありmap.spec.jsます:

require(['map'], function (Map) {
  describe('Choropleth Map Generator', function() {
    describe('Configure the map', function () {
      it("should enforce mandatory parameters in the configuration", function () {
        var config = {title: 'test configuration'};
        var map = new Map(config);
        (function () {
          map.getConfig();
        }).should.throw(Error);
      });
    });
  });
});

今、私がするときyeoman test、私はこれを取得します:

Running "server:phantom" (server) task

Starting static web server on port 3501

[...]

Running "mocha:all" (mocha) task
Testing index.html
<WARN> PhantomJS timed out, possibly due to a missing Mocha run() call. Use --force to continue. </WARN>

Aborted due to warnings.

私が言ったようyeoman server:testに、ブラウザで私のアサーションを正しく表示します。

私は Yeoman 0.9.6 と PhantomJS 1.7.0 を使用しています。どんな助けでも大歓迎です。

4

2 に答える 2

4

へのパスを再確認することで、同じ警告を解決しmochaましたtest/index.html

<link rel="stylesheet" href="lib/mocha/mocha.css">
</head>
<body>
  <div id="mocha"></div>
  <script src="lib/mocha/mocha.js"></script>
于 2013-01-11T00:07:38.113 に答える
3

Gruntfile のモカ設定は何ですか。次のようなものがありますか?

mocha: {
  all: ['http://localhost:3501/index.html']
},
于 2013-01-10T04:58:44.737 に答える