我们如何在不加载 JSP 的情况下从 Jenkins (Hudson) 运行 JavaScript jasmine 测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7609223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can we run JavaScript jasmine tests from Jenkins (Hudson) without loading a JSP?
提问by finneycanhelp
We have a rich web client. Our controllers and service facades are written in coffeescript (JavaScript) and jquery. In the past they would have been java.
我们有一个丰富的网络客户端。我们的控制器和服务外观是用 coffeescript (JavaScript) 和 jquery 编写的。在过去,它们将是 java。
To run our JavaScript jasmine tests from Jenkins/Hudson, we use java's junit and htmlunit to load a test oriented jsp page which includes the jasmine specs.
为了从 Jenkins/Hudson 运行我们的 JavaScript jasmine 测试,我们使用 java 的 junit 和 htmlunit 来加载一个包含 jasmine 规范的面向测试的 jsp 页面。
When the Htmlunit tries to run, it blows up trying to getPage() probably because of an XML parser class path which is extremely challenging to track down in our world.
当 Htmlunit 尝试运行时,它在尝试 getPage() 时失败了,这可能是因为 XML 解析器类路径在我们的世界中很难追踪。
We just want to be able to run our JavaScript tests from Jenkins and have it report failure if a JavaScript test does not pass. We are just using jsp and htmlunit in order to run JavaScript tests. Can we load the JavaScript tests and javascript code into a JavaScript engine with Jenkins as the thing that kicks it off? If so, how?
我们只是希望能够从 Jenkins 运行我们的 JavaScript 测试,并在 JavaScript 测试未通过时报告失败。我们只是使用 jsp 和 htmlunit 来运行 JavaScript 测试。我们可以将 JavaScript 测试和 javascript 代码加载到 JavaScript 引擎中,并以 Jenkins 作为启动项吗?如果是这样,如何?
回答by Justin Searls
Sounds like you're in a Java environment. My jasmine-maven-pluginmight be a good fit.
听起来像是在 Java 环境中。我的jasmine-maven-plugin可能很合适。
回答by mrooney
Jasmine Reporterswould also be a solution. It has instructions for running headlessly via PhantomJS for example, and it can generate JUnit XML so Jenkins can understand the test results natively, graphing test count, duration, and failure over time.
Jasmine Reporters也将是一个解决方案。例如,它有通过 PhantomJS 无头运行的指令,并且它可以生成 JUnit XML,因此 Jenkins 可以在本地理解测试结果,绘制测试计数、持续时间和失败随时间变化的图表。
Also, the "xvfb-run" wrapper often provided with xvfb is a great help here, so you can do "xvfb-run phantomjs.runner.sh ..." in a truly headless environment.
此外,通常随 xvfb 提供的“xvfb-run”包装器在这里有很大帮助,因此您可以在真正的无头环境中执行“xvfb-run phantomjs.runner.sh ...”。
回答by joonsp
I've previously solved this problem by running the tests with a node.js plugin called jasmine-node
我以前通过使用名为jasmine-node的 node.js 插件运行测试解决了这个问题
This solution of course requires node.js and a few node modules to properly run the jasmine tests. There is no real browser running the tests, but an emulated one using a module called jsdom, which basically creates a headless browser, and more specifically, a DOM, which the tests can interact with.
这个解决方案当然需要 node.js 和一些 node 模块才能正确运行 jasmine 测试。没有运行测试的真实浏览器,而是使用名为 jsdom 的模块模拟的浏览器,它基本上创建了一个无头浏览器,更具体地说,是一个 DOM,测试可以与之交互。
There's node modules for jQuery, underscore and propably other too, so these can be tested too. You can even skip the whole browser emulation if you'd rather run the tests in a browser, though I find it too cumbersome compared to automated Jenkins testing.
有用于 jQuery、下划线和其他可能的节点模块,因此这些也可以进行测试。如果您更愿意在浏览器中运行测试,您甚至可以跳过整个浏览器模拟,尽管与自动化 Jenkins 测试相比,我发现它太麻烦了。
jasmine-node generates jUnit test reports, which Jenkins can interpret just fine.
jasmine-node 生成 jUnit 测试报告,Jenkins 可以很好地解释这些报告。
I just realized there is some jenkins-jasmine-nodeplugin that might ease this process.
我刚刚意识到有一些jenkins-jasmine-node插件可以简化这个过程。
回答by aqm
Grunt is your friend
咕噜是你的朋友
- use grunt http://gruntjs.com/
- with grunt jasimine https://github.com/gruntjs/grunt-contrib-jasmine
- with nodejs http://nodejs.org/
- on jenkins using https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
- 使用 grunt http://gruntjs.com/
- 与咕噜 jasimine https://github.com/gruntjs/grunt-contrib-jasmine
- 使用 nodejs http://nodejs.org/
- 在 jenkins 上使用https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin
got this setup and it's really nice, plus this gives you a place to start making your build server do other nice things such as deployment, unit testing, etc you know, other nice things
得到这个设置,它真的很好,而且这给了你一个地方开始让你的构建服务器做其他好的事情,比如部署、单元测试等,你知道,其他好的事情
回答by Sarel Botha
Can you use selenium? That would actually use a real browser then and get as close to the real environment as possible.
你能用硒吗?那实际上会使用真正的浏览器,并尽可能接近真实环境。