【发布时间】:2016-07-20 07:20:07
【问题描述】:
我正在使用 chutzpah 将我的 javascript 单元测试与 TFS 2015 集成,并且做得很完美。
但是当启用代码覆盖时,我得到了与文件路径相关的错误
例如
错误:Blanket.js 遇到跨源请求错误,而 检测源文件。这很可能是由来源引起的 本地引用的文件(使用 file:// 协议)。
因为当 chutzpah 为每个测试文件生成 html 文件时,引用路径不是相对的:
<script type="text/javascript" src="file:///C:/_work/7b9b5f73/MyProject/packages/Chutzpah.4.2.3/tools/TestFiles/chutzpah_boot.js"></script>
我研究了如何配置 chutzpah 设置以使路径相对,最匹配的答案是 Customizable HTML harness generation,它说明了如何覆盖整个模板而不是覆盖默认模板中的占位符。
那么有什么方法可以配置 chutzpah 以使引用路径相对于能够将客户端代码覆盖结果与 tfs 链接。
我的 chutzpah.json 文件如下所示:
{
"Framework": "mocha",
"TestHarnessLocationMode": "SettingsFileAdjacent",
"RootReferencePathMode": "SettingsFileDirectory",
"EnableCodeCoverage": "true",
"CodeCoverageExcludes": [
"bower_components\\*",
"node_modules\\*"
],
"References": [
{
"Path": "node_modules/mocha/mocha.js"
},
{
"Path": "node_modules/chai/chai.js"
},
{
"Path": "node_modules/sinon-chai/lib/sinon-chai.js"
},
{
"Path": "src/client/app/mochaConstrutor.js"
},
{
"Path": "bower_components/jquery/dist/jquery.js"
},
{
"Path": "bower_components/angular/angular.js"
},
{
"Path": "bower_components/angular-sanitize/angular-sanitize.js"
},
{
"Path": "bower_components/bootstrap/dist/js/bootstrap.js"
},
{
"Path": "bower_components/extras.angular.plus/ngplus-overlay.js"
},
{
"Path": "bower_components/moment/moment.js"
},
{
"Path": "bower_components/angular-ui-router/release/angular-ui-router.js"
},
{
"Path": "bower_components/toastr/toastr.js"
},
{
"Path": "bower_components/angular-animate/angular-animate.js"
},
{
"Path": "bower_components/angular-bootstrap/ui-bootstrap-tpls.js"
},
{
"Path": "bower_components/angular-mocks/angular-mocks.js"
},
{
"Path": "bower_components/sinon/index.js"
},
{
"Path": "bower_components/bardjs/dist/bard.js"
},
{
"Path": "bower_components/bardjs/dist/bard-ngRouteTester.js"
},
...
],
"Tests": [
{
"Path": "src/client/app/admin/admin.controller.spec.js"
},
{
"Path": "src/client/app/admin/admin.route.spec.js"
},
...
]
}
【问题讨论】:
标签: javascript unit-testing tfs code-coverage chutzpah