在没有服务器的情况下在Phantom.js中运行Jasmine测试套件

aza*_*gru 5 javascript jasmine phantomjs

我试图让Phantom.js运行一套用Jasmine编写的JavaScript测试.以下是重现我正在做的事情的步骤:

  • 获取最新版本的Jasmine框架的最新独立版本(zip存档)

  • 存档包含几个javascript文件的示例规范以及SpecRunner.html可以在浏览器中运行这些规范的文件

  • 安装phantom.js并从phantom.js项目的示例文件夹下载jasmine 2 runner

  • 尝试SpecRunner.html使用phantom.js 运行:

    phantomjs ./phantom/run-jasmine2.js ./jasmine/SpecRunner.html

(在哪里./phantom/run-jasmine2.js是phantom.js的jasmine2 runner的路径,并且./jasmine/SpecRunner.html是jasmine文件夹中带有示例规范的spec运行器的路径)

我收到以下错误

TypeError: null is not an object (evaluating 'document.body.querySelector('.description').innerText')

Blocked a frame with origin "file://" from accessing a frame with origin "null".  The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "about". Protocols must match.
Run Code Online (Sandbox Code Playgroud)

因此,Phantom似乎不满意将规范转换器直接作为磁盘中的文件提供给它,而不是作为本地服务器(localhost:8080/SpecRunner.html)提供的文件.您是否可以建议一种方法让Phantom能够使用spec转轮文件而不需要启动服务器?如果可能的话,也没有Karma.

Jam*_*son 0

这里有一个很好的例子,展示了您可以使用的Karma、PhantomJS、Jasmine 设置,更多有关 Karma 的文档可以在https://karma-runner.github.io上找到。