1

I'm starting a new project (Firefox add-on) and I'd like to try using behavior-driven development. I particularly like the Jasmine BDD library. However, I can't find a good way how to use a framework such as Jasmine in the Add-On SDK.

One problem is that Jasmine needs setTimeout (and similar) functions to be specified on the global object, whereas Add-On SDK exports those using "timers" module. But let's say I tweak Jasmine to get those object from "timers" (or add the the methods exported by timers to the global object).

The bigger problem is that I don't know how to actually run the tests. There is a test directory generated by the SDK, however, there's no window or document object there to allow me to see the output (and I'd really like to see the fancy HTML output). I guess I could create a content script that would modify the page, but then I can't access (test) the background script.

Have you ever faced this before? Is there any recommended way how to deal with that?

Thanks! Tomas

4

1 に答える 1

0

アドオンSDKウィンドウAPIを使用して、テストを実行するための新しいウィンドウを開くことができます。下付き文字ローダーを使用してJasmineスクリプトをロードし、ウィンドウとドキュメントをその添え字:

var windows = require("windows").browserWindows;

windows.open({
  url: "about:blank",
  onOpen: function(window) {
    var script;
      var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
        getService(Ci.mozIJSSubScriptLoader);
      scriptLoader.loadSubScript(subscriptSpec, script);
      script["window"] = window;
      script["document"] = window.document;
      // ... run your tests here by calling script.someFunc() ...
   }
});

更新:さらなる調査によると、browserWindowsは実際には、コンテンツウィンドウへのアクセスを許可しない特別なラッパーです。非表示のフレームからウィンドウ/ドキュメントを取得してみてください。これが、特権コードからHTMLドキュメントにアクセスするために私が見ることができる唯一の方法です。

于 2011-09-13T17:31:33.253 に答える