【问题标题】:Failing to setup a test environment with grunt, phantomjs and mocha无法使用 grunt、phantomjs 和 mocha 设置测试环境
【发布时间】:2014-02-01 17:39:42
【问题描述】:

我正在尝试使用 yeoman 设置一个包含 grunt、phantomjs 和 mocha 的测试环境。问题是在运行测试任务时我收到以下警告:

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

但我在 index.html 文件中调用 mocha.run()。这里是:

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

我认为我的问题出在我的 Gruntfile 中,我一定遗漏了一些东西。这是我的一些 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'   ]);

【问题讨论】:

    标签: gruntjs phantomjs mocha.js yeoman


    【解决方案1】:

    我收到了同样的错误消息,然后我意识到在 yeoman 设置中实际上有两个 bower_components 目录。

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

    当我克隆一个 yo 生成的应用程序的 git repo 时,它具有以下 .gitignore 文件

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

    所以你需要运行两次...

    bower install
    

    在 [root] 中一次,在 [root]/test 中一次

    【讨论】:

      【解决方案2】:

      尝试设置 mocha.test.options.run = true

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多