Inability to set up a test environment with grunts, phantoms and mocha

I am trying to set up a test environment using grunt, phantomjs and mocha using yoman. The problem is that when I started the test task, I received the following warning:

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

But I am calling mocha.run()index.html in my 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 have to miss something. Here are some of my grunt files:

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'   ]);
+4
source share
2 answers

I had the same error message, and then I realized that there really are two bower_components directories in the yeoman setting.

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

git , .gitignore

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

, ...

bower install

[root] [root]/test

+8

mocha.test.options.run = true

0

Source: https://habr.com/ru/post/1524860/


All Articles