如何在 chutzpah 生成 html 代码覆盖率时使引用路径相对
How to Make reference paths relative when chutzpah generate html harness for code coverage
我正在使用 chutzpah 将我的 javascript 单元测试与 TFS 2015 集成,并且完成得很完美。
但是当启用代码覆盖时,我收到与文件路径相关的错误
例如
Error: Blanket.js encountered a cross origin request error while
instrumenting the source files. This is likely caused by the source
files being referenced locally (using the file:// protocol).
因为当 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 使参考路径相对于 link 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"
},
...
]
}
目前,Chutzpah 无法创建相对路径。但是,我目前正在进行一项更改,使其 运行 具有嵌入式 Web 服务器,这将使像 Blanket 这样的工具工作得更加顺畅。
我正在使用 chutzpah 将我的 javascript 单元测试与 TFS 2015 集成,并且完成得很完美。
但是当启用代码覆盖时,我收到与文件路径相关的错误
例如
Error: Blanket.js encountered a cross origin request error while instrumenting the source files. This is likely caused by the source files being referenced locally (using the file:// protocol).
因为当 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 使参考路径相对于 link 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"
},
...
]
}
目前,Chutzpah 无法创建相对路径。但是,我目前正在进行一项更改,使其 运行 具有嵌入式 Web 服务器,这将使像 Blanket 这样的工具工作得更加顺畅。