【问题标题】:QUnit and Sinon.js under continous integration持续集成下的 QUnit 和 Sinon.js
【发布时间】:2013-05-03 07:14:36
【问题描述】:

我正在使用原生运行良好的 QUnit+Sinon.js。 当我尝试将其构建到持续集成过程中时,出现了问题。 我正在使用 js-test-driver 框架,以便能够在持续集成环境中运行它。 过去我在没有 Sinon.js 的情况下使用它,这没有任何问题。 但是在我包含了 Sinon.js 插件之后,它就完全不起作用了。 当我尝试运行我的测试时,它说:

D:/my/project/url/contentTest.js:60: TypeError: qTest is not a function
Total 0 tests (Passed: 0 Fails: 0 Errors: 0)(0.00 ms)

我的 js-test-driver 配置:

server: http://localhost:9879

load:  
  # QUnit related files
  - qunit/lib/equiv.js
  - qunit/lib/QUnitAdapter.js
  - qunit/plugin/sinon-1.6.0.js
  - qunit/plugin/sinon-qunit-1.0.0.js

  # Dependencies
  - external/jquery/1.7.2/jquery.min.js

  # Files under test
  - content.js

  # Tests
  - contentTest.js

有趣的是有一个运行良好的 QUnit index.html 文件(当我打开这个 html 时,每个测试都通过了):

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>my tests</title>
  <link rel="stylesheet" href="./qunit/lib/qunit-1.11.0.css">
</head>
<body>
  <div id="qunit"></div>
  <div id="qunit-fixture"></div>

  <!-- core -->
  <script src="./qunit/lib/qunit-1.11.0.js"></script>
  <script src="./qunit/plugin/sinon-1.6.0.js"></script>
  <script src="./qunit/plugin/sinon-qunit-1.0.0.js"></script>

  <!-- dependencies -->  
  <script src="./external/jquery/1.7.2/jquery.min.js"></script>

  <!-- under test  -->
  <script src="./content.js"></script>

  <!-- tests -->
  <script src="./contentTest.js"></script>
</body>
</html>

看来js-test-driver和Sinon.js有冲突。如果我删除所有相关的 Sinon.js 测试和包含的 sinon 插件,那么它可以工作。 如果我只是删除与 sinon 相关的测试,它仍然会失败。 如果我不删除 sinon.js 而是删除所有测试并使用“ok(true)”断言创建一个 emty 测试,那么它仍然会失败并显示相同的错误消息 (contentTest.js:60: TypeError: qTest is not a函数),但是我的测试文件仅包含 10 行(当我的文件仅包含 10 行时,它怎么可能在第 60 行出现错误?)。

提前感谢大家的帮助!

【问题讨论】:

    标签: continuous-integration qunit sinon js-test-driver


    【解决方案1】:

    不是一个解决方案,而是一种获取更多信息的方法:您可以从 shell 本地运行 js-test-driver 脚本吗?它会产生类似的错误细节吗?至少,这将为您提供更多信息和更短的反馈循环。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-21
      • 2010-12-06
      • 2011-11-14
      • 2019-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多