Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha tests with Yeoman and PhantomJS

I'm using Yeoman to scaffold my project. It comes with several handy things, including a PhantomJS-based test runner.

My problem is that while my tests run correctly in the browser, they time out while trying to run them with PhantomJS in the CLI.

Here's how my test index.html looks like:

<!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>

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

Now, when I do yeoman test, I get this:

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.

As I said, yeoman server:test shows my assertions correctly in the browser.

I'm using Yeoman 0.9.6 and PhantomJS 1.7.0. Any help is appreciated.

like image 779
Alex Ciminian Avatar asked Jan 08 '13 16:01

Alex Ciminian


2 Answers

I solved that same warning by double-checking the path to mocha in test/index.html

<link rel="stylesheet" href="lib/mocha/mocha.css">
</head>
<body>
  <div id="mocha"></div>
  <script src="lib/mocha/mocha.js"></script>
like image 57
maxbeatty Avatar answered Oct 31 '22 09:10

maxbeatty


What is your mocha config In Gruntfile. Do you have something like:

mocha: {
  all: ['http://localhost:3501/index.html']
},
like image 22
sleeper Avatar answered Oct 31 '22 09:10

sleeper