Подтвердить что ты не робот

Тесты Mocha с Yeoman и PhantomJS

Я использую Yeoman, чтобы поднять мой проект. Он поставляется с несколькими удобными вещами, включая PhantomJS тестовый бегун.

Моя проблема заключается в том, что, хотя мои тесты корректно выполняются в браузере, они тайминг при попытке запустить их с помощью PhantomJS в CLI.

Вот как выглядит мой тест 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. Любая помощь приветствуется.

4b9b3361

Ответ 1

Какова ваша конфигурация мокко в файле Grunt. У вас есть что-то вроде:

mocha: {
  all: ['http://localhost:3501/index.html']
},

Ответ 2

Я решил это же предупреждение, дважды проверив путь к 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>