繁体   English   中英

将外部javascript注入html脚本标签以获取cobertura代码覆盖率结果

[英]Inject external javascript into html script tag for cobertura code coverage results

类似,我想注入html外部的js文件。

问题背景-我正在使用cobertura为Angular6应用程序生成代码覆盖率。 在我的vsts构建中,我正在发布代码覆盖率结果,但是当逐步执行文件链接时需要触发.js文件时,浏览器出现错误:

Blocked script execution in '<URL>' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.

我认为最好的解决方案是执行一个脚本,将javascript代码直接注入html,而不是从外部链接到html。

因此,例如说html是这样的:

<html>

   <script src="code.js"></script>
...
</html>

然后运行脚本等之后injector.js :像这样node ./injector.js

该html将变为:

<html>

   <script>
      function hello() {
         console.log('hello');
      }
   </script>
</html>

你该怎么做?

还是有解决这个问题的更好方法?

由于您的开发是完全基于的NodeJS。

你可以简单地写一个剧本的NodeJS

  1. 使用水珠模块从覆盖文件夹中取出使用模式的所有HTML文件
  2. 遍历每个生成的报告的HTML和内联CSS和脚本。
  3. 保存
  4. 随后发布的代码覆盖率报告文物。

NPM模块不正是确实与一些优化的内联工作https://www.npmjs.com/package/vsts-coverage-styles

免责声明: 我写了上面提到的简单重复使用的NPM包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM