我正在开始一个新项目(Firefox 插件),我想尝试使用行为驱动开发。我特别喜欢 Jasmine BDD 库。但是,我找不到如何在 Add-On SDK 中使用 Jasmine 等框架的好方法。
一个问题是 Jasmine 需要在全局对象上指定 setTimeout (和类似的)函数,而 Add-On SDK 使用“timers”模块导出这些函数。但假设我调整 Jasmine 以从“计时器”获取这些对象(或将计时器导出的方法添加到全局对象)。
更大的问题是我不知道如何实际运行测试。 SDK 生成了一个测试目录,但是,那里没有窗口或文档对象来允许我查看输出(而且我真的很想看到精美的 HTML 输出)。我想我可以创建一个内容脚本来修改页面,但随后我无法访问(测试)后台脚本。
您以前遇到过这种情况吗?有什么推荐的方法来处理这个问题吗?
谢谢!
托马斯
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
发布评论
评论(1)
您可以使用 添加-on SDK windows API 打开一个新窗口来运行测试。您应该能够使用 下标加载器 并将窗口和文档设置为该下标范围内您想要的任何内容:
更新:进一步的研究表明 browserWindows 实际上是特殊的包装器,不允许您访问内容窗口。您可以尝试从 隐藏框架。这是我能看到的从特权代码访问 HTML 文档的唯一方法。
You can use the Add-on SDK windows API to open a new window to run your tests in. You should be able to load the Jasmine script(s) with the subscript loader and set window and document to whatever you want in the scope of that subscript:
Update: Further research shows that the browserWindows are actually special wrappers that don't give you access to the content window. You might try getting a window/document from a hidden frame. That's the only way I can see to get access to an HTML document from privileged code.