Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failing to setup a test environment with grunt, phantomjs and mocha

I'm trying to setup a test environment with grunt, phantomjs and mocha using yeoman. The problem is when run the test task I got the following warning:

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

But I'm calling mocha.run() in my index.html file. Here it is:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Mocha Spec Runner</title>
    <link rel="stylesheet" href="bower_components/mocha/mocha.css">
</head>
<body>
    <div id="mocha"></div>
    <script src="bower_components/mocha/mocha.js"></script>
    <script>mocha.setup('bdd')</script>
    <script src="bower_components/chai/chai.js"></script>
    <script>
        var assert = chai.assert;
        var expect = chai.expect;
        var should = chai.should();
    </script>

    <!-- include source files here... -->

    <!-- include spec files here... -->
    <script src="spec/test.js"></script>

    <script>
      mocha.run();
    </script>
</body>
</html>

I think my problem is inside my Gruntfile, I must be missing something. Here's some of my Gruntfile:

connect: {
      test: {
        options: {
          port: 9001,
          base: [
            '.tmp',
            'test',
            '<%= yeoman.app %>'
          ]
        }
      },
...


mocha: {
  test: {
    src: ['test/*.html'],
    options: {
      urls: [ 'http://localhost:9001/test/index.html' ]
    }
  }
}

...

grunt.registerTask('test', [
  'clean:server',
  'concurrent:test',
  'autoprefixer',
  'connect:test',
  'mocha'   ]);
like image 981
Bernardo Avatar asked Feb 14 '23 22:02

Bernardo


1 Answers

I had the same error message and then I realised there are actually two bower_components directories in a yeoman setup.

$> ls -la
...
bower_components
...
test/bower_components

When I cloned a git repo of a yo generated app it has the following .gitignore file

node_modules
dist
.tmp
.sass-cache
bower_components
test/bower_components

So you need to run this twice...

bower install

Once in [root] and once in [root]/test

like image 147
Kevin Monk Avatar answered Apr 26 '23 20:04

Kevin Monk