1

ここでノードモジュール「mocha-phantomjs」を正常にインストールしました。次のテストケースを書きました。

test1.js

describe("DOM Tests", function () {
    var el = document.createElement("div");
    el.id = "myDiv";
    el.innerHTML = "Hi there!";
    el.style.background = "#ccc";
    document.body.appendChild(el);
    var myEl = document.getElementById('myDiv');
    it("is in the DOM", function () {
        expect(myEl).to.equal(null);
    });
    it("is a child of the body", function () {
        expect(myEl.parentElement).to.equal(document.body);
    });
    it("has the right text", function () {
        expect(myEl.innerHTML).to.equal("Hi there!");
    });
    it("has the right background", function () {
        expect(myEl.style.background).to.equal("rgb(204, 204, 204)");
    });
});

TestCase.html

<html>
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="mocha.css" />
  </head>
  <body>
    <div id="mocha"></div>
    <script src="mocha.js"></script>
    <script src="chai.js"></script>
    <script>
      mocha.ui('bdd');
      mocha.reporter('html');
      expect = chai.expect;
    </script>
    <script src="test1.js"></script>
    <script>
      if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
      else { mocha.run(); }
    </script>
  </body>
</html>

jsファイル内でタイプミスをしても、まったく出力されません。

ここでの要点は、自動化された dom および js テストをヘッドレス サーバーで使用し、それを Jenkins と統合する必要があることです。TAP レポートを使用することは問題ないと思いました。他の提案は大歓迎です。

編集

Phantomjs のバージョンを更新したところ、次のようになりました。

TypeError: 'undefined' is not a function (evaluating 'mocha.ui('bdd')')

  file:///home/seventeenlive/site/tests/TestRunner2.html:11
ReferenceError: Can't find variable: describe

  file:///home/seventeenlive/site/tests/test1.js:20
ReferenceError: Can't find variable: process

  mocha-phantomjs/core_extensions.js:21
  mocha-phantomjs/core_extensions.js:82
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():2
  phantomjs://webpage.evaluate():8
  phantomjs://webpage.evaluate():8
ReferenceError: Can't find variable: process

  phantomjs://webpage.evaluate():3
  phantomjs://webpage.evaluate():17
  phantomjs://webpage.evaluate():17
Failed to start mocha.
4

2 に答える 2