如何有效地使用 Jasmine 测试通过 Jammit 打包的 javascript 资源?
我有一个 Rails 应用程序,它使用 Jammit 组合 javascript 资源,并且我想使用 Jasmine 用于对我的 javascript 进行 BDD 式测试。我想知道是否有人对从 Jasmine 内部访问 Jammit 生成的“包”有什么建议?
问题是 Jasmine 是通过在磁盘上定义要测试的 JS 文件列表来配置的,然后它将这些文件包含在自己的测试运行器页面中,该测试运行器页面在浏览器中加载并运行。
在使用 Jammit 打包之前,我可以引用 jasmine.yml 配置文件中的每个单独的 JS 文件...但是,Jammit 已经在为我处理文件之间的依赖关系,更重要的是,我还需要访问Jammit 生成的已编译的 javascript 模板。
我还可以手动运行 Jammit 首先生成已编译的资产,然后运行 Jasmine,但最终我必须在每次测试运行之前手动重新生成资产以测试更改,这会严重限制快速测试 -驱动型工作流程。
我想知道是否可以通过某种方式:
- 从 Jasmine 的机架服务器内安装 Jammit 控制器,以便它可以提供 Jasmine 的软件包?这基本上与 Jammit 在 Rails 开发环境中所做的工作方式相同。
- 在执行测试之前,以某种方式挂钩 Jasmine 来打包每个页面加载的资源?这会比较慢,但会节省我一步并确保事情是最新的。
有什么建议吗?我刚刚开始做这件事,所以我可能会做错事。任何建议将不胜感激。 :-)
谢谢! -约翰
I have a rails app that is combining javascript assets using Jammit, and I'd like to use Jasmine for BDD-style testing of my javascript. I'm wondering if anyone has any advice on accessing the Jammit-generated 'pacakges' from within Jasmine?
The issue is that Jasmine is configured by defining a list of JS files on disk to test, and it then includes those files within its own test runner page which is loaded and run in a browser.
I could reference each of the individual JS files inside of the jasmine.yml config file before they're packaged with Jammit... however, Jammit is already dealing with dependencies between files for me, and, more importantly, I also need access to the compiled javascript templates that Jammit produces.
I could also manually run Jammit to generate the compiled assets first and then run Jasmine, but I'd wind up having to re-generate the assets by hand before each test run in order to test changes, which would seriously cramp a fast test-driven type workflow.
I'm wondering if I could somehow:
- Mount the Jammit controller from within Jasmine's rack server so it could serve out the packages from Jasmine? This would basically work the same way as Jammit already does from within Rails' development env.
- Hook into Jasmine somehow to package the assets on every page load before the tests are executed? This would be slower, but would save me a step and ensure things were up to date.
Any suggestions? I'm just getting started with this, so I could be going about it all wrong. Any advice would be greatly appreciated. :-)
Thanks!
-John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您正在寻找的神奇组合:
这是一个可以帮助您入门的 Guardfile 示例:
Here's the magic combo you're looking for:
Here's an example Guardfile to get you started:
我想出了一个好的解决方案:在 jasmine 启动时强制 Jammit 重新加载和打包。为此,您需要编辑 jasmine_config.rb 文件:
我在这里写了一篇更详细的文章:http://www.rebeccamiller-webster.com/2011/05/jammit-jasmine-bdd/
I've come up with an OK solution: force Jammit to reload and package when jasmine starts. To do this, you need to edit the jasmine_config.rb file:
I wrote a bit more detailed post about it here: http://www.rebeccamiller-webster.com/2011/05/jammit-jasmine-bdd/