运行javascript测试套件并收集覆盖率信息。
js_test_tool的Python项目详细描述
运行javascript测试套件并收集覆盖率信息。
安装
cd js-test-tool
python setup.py install
开始
- 创建描述测试套件的文件。
js-test-tool init js_test.yml
这将创建一个yaml文件(js_test.yml),看起来像:
---# Name of the test suite, used to construct# the URL from which pages are served.## For example, if the suite name is "test_suite",# then:## * /suite/test_suite# serves the test suite runner page# * /suite/test_suite/include/*# serves dependencies (src, spec, lib, and fixtures)## Test suite names must be URL-encodable and unique# among suite descriptions passed to js-test-tooltest_suite_name:test_suite# Currently, the only supported test runner is Jasmine# See http://pivotal.github.io/jasmine/# for the Jasmine documentation.test_runner:jasmine# Path prepended to source files in the coverage report (optional)# For example, if the source path# is "src/source.js" (relative to this YAML file)# and the prepend path is "base/dir"# then the coverage report will show# "base/dir/src/source.js"prepend_path:base/path# Paths to library JavaScript files (optional)lib_paths:-path/to/lib# Paths to source JavaScript filessrc_paths:-path/to/src# Paths to spec (test) JavaScript filesspec_paths:-path/to/spec# Paths to fixture files (optional)# The fixture path will be set automatically when using jasmine-jquery.# (https://github.com/velesin/jasmine-jquery)## You can then access fixtures using paths relative to# the test suite description:## loadFixtures('path/to/fixture/fixture.html');#fixture_paths:-path/to/fixture# Regular expressions used to exclude *.js files from# appearing in the test runner page.# Some test runners (like the jasmine runner) include files by default,# which means that they are loaded using a <script> tag in the test# runner page. When loading many files, this can be slow, so# exclude any files you don't need.# Note that not all runners behave the same way: for example, the# jasmine_requirejs runner does not include files using <script> tags# by default, and so will ignore this directive.exclude_from_page:-path/to/lib/exclude/.*# Regular expression used to guarantee that a *.js file# is included in the test runner page.# If a file name matches both `exclude_from_page` and# `include_in_page`, the file WILL be included.# You can use this to exclude all files in a directory,# but make an exception for particular files.include_in_page:-path/to/lib/exclude/exception_.*\.js
- 所有路径都是相对指定的 到yaml文件的位置。
- 递归搜索目录路径。
- javascript文件按指定顺序加载。
- 路径不能包含上一级引用。例如,path/to/dir可以, 但是../path/to/dir不是。 如果需要访问测试套件目录上方目录中的文件, 使用符号链接。
- 运行测试套件。
js-test-tool run js_test.yml --use-firefox
这将向控制台输出一个报告,显示哪些测试通过或失败。
开发模式
js-test-tool有一种特殊的模式用于编写和调试测试:
js-test-tool dev js_test.yml
这将在dev模式下启动js-test-tool:
- 测试将在默认浏览器中运行。
- 该工具将一直运行,直到您使用Ctrl-C终止它。
- 测试结果将直接显示在浏览器中。
超时
如果测试运行时间过长,则测试运行程序将超时。 默认超时为5分钟,但可以覆盖此值:
js-test-tool run js_test.yml --use-chrome --timeout-sec 10
上面的命令将超时设置为10秒。
覆盖范围
要收集javascript覆盖率:
- 下载并解压缩JSCover
- 设置环境变量JSCOVER_JAR:
exportJSCOVER_JAR=~/jscover/target/dist/JSCover-all.jar
- 运行js-test-tool,覆盖范围:
js-test-tool run js_test.yml --use-phantomjs --coverage-xml=js_coverage.xml --coverage-html=js_coverage.html
这将创建两种格式的覆盖率报告:
- cobertura xml
- HTML
xunit报告
js-test-tool可以生成xunit样式的xml报告以供使用 像詹金斯这样的ci系统。
js-test-tool run js_test.yml --use-firefox --xunit-report report.xml
将生成名为report.xml的报告。
多个浏览器
使用命令行选项,可以在 多个浏览器:
js-test-tool run js_test.yml --use-chrome --use-phantomjs
将在chrome和phantomjs中运行测试,如果 浏览器已安装。
该工具目前支持以下浏览器:
- 铬
- 幻影
- 火狐
覆盖率信息是跨浏览器组合的:一行是 如果在any浏览器下执行,则视为已覆盖。
多个测试套件
您可以按顺序运行测试套件:
js-test-tool run test_1.yml test_2.yml --use-firefox
如果收集覆盖范围,则覆盖范围报告 将包含包含的所有文件的信息 在每个测试套件中。
许可证
此存储库中的代码在agpl的版本3下获得许可,除非 另有说明。
有关详细信息,请参见LICENSE.txt。
如何贡献
我们非常欢迎您的贡献。最简单的方法是分开回购,然后 从你的叉子上做一个拉动请求。当你第一次提出请求时 可能会被要求签署出资人协议。
报告安全问题
请不要公开报告安全问题。请发电子邮件security@edx.org
邮件列表和IRC频道
您可以在edx-code Google Group或 edx-codeirc频道在freenode上。