azure-pipelines-tasks: Code Coverage view not rendering linked css / js files in artifact
I’m creating a javascript test coverage report using the karma-coverage plugin. It generates an HTML coverage report based on the Istanbul and a Cobertura report file.
I’m using the output directory for the html report as the report directory in the “Publish Code Coverage Results” task.
My build artifact then contains the full contents of the html folder, as well as the Cobertura report.
Build Artifact:
When I navigate to the Code Coverage page for the build, I see the results of my tests, and I’m able to navigate through the results, I just don’t have any of the styling or scripts that are associated with the report.
Results:
Expected:
When I navigate to the coverage page in chrome, I get the following console error:
Blocked script execution in 'https://MYPROJECTHERE.visualstudio.com/_apis/Containers/321454/Code%20Coverage%20Report_2015/index.html' because the document's frame is sandboxed and the 'allow-scripts' permission is not set.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 19
- Comments: 34 (2 by maintainers)
Commits related to this issue
- Improve test coverage report on Azure Pipelines (#49) The reports are rendered without CSS on Azure Pipelines, see this issue: [Microsoft/azure-pipelines-tasks#3027](https://github.com/Microsoft/azur... — committed to Azure/react-appinsights by pviotti 5 years ago
- Improve test coverage report on Azure Pipelines (#49) The reports are rendered without CSS on Azure Pipelines, see this issue: [Microsoft/azure-pipelines-tasks#3027](https://github.com/Microsoft/azur... — committed to Azure/react-appinsights by pviotti 5 years ago
Any updates on this?
Why is the issue closed? It is currently not working.
In the meantime, here is a little script that inlines the external CSS into the HTML pages generated by the coverage reporter. I run it as a post processing step in the build after the coverage has been collected.
https://gist.github.com/kohlikohl/ef77c751cfd3b731923ca74fec9443d5
Direct link to a relevant User Voice item: https://visualstudio.uservoice.com/forums/330519-visual-studio-team-services/suggestions/15926806-code-coverage-report-on-build-should-not-strip-sty
@nigurr any news about bringing styles back?
@nigurr We would also be interested in this feature.
I’ve got a Python 3.6 script that my team successfully uses for embedding CSS in code coverage reports. It depends on beautiful soup library for parsing HTML.
@brownbl1, I’ve just managed to use @kohlikohl’s gist successfully. It’s currently my workaround to this issue. I’ve told the file to execute after my Jest unit tests, which produces the Istanbul code coverage HTML reports.
The results after uploading via the Publish Code Coverage Results task in VSTS. I suppose it might be behaving differently for you if you’re on TFS or On Prem using an older version…
I’m also watching this. Without the CSS working, the viewer doesn’t make much sense to us.
We’re also seeing this still. Would love to have scripts and css working.
This is great and worked well for me. Except the encoding had to be set on the output otherwise I ended up with encoding issues on the nbsp generated by coverage
with open(html_file, 'w', encoding="UTF8") as f:
and just to make it easier for anyone else here is my yaml
IIRC, this limitation is by design to avoid various security issues. If you want to avoid duplicating the resources, then creating a custom extension may be a better option. However, if it’s a large amount of resources repeatedly copied then it may be an indicator that ADO is being used for something beyond ADO’s intent. I’ve seen much of such misuse at work, and it makes for problems down the road if the approach is not quickly changed to be done in a more measured way.
I followed this and it seemed to work really well 🥇 https://davidsekar.com/aspnetcore/code-coverage-html-reports-are-missing-styles-in-vsts
In Chrome the javascript files are also blocked. Blocked script execution in ‘https://xxxx.visualstudio.com/xxxxx-e44870bd4e9b/_apis/test/CodeCoverage/browse/2095227/Code Coverage Report_114/index.html’ because the document’s frame is sandboxed and the ‘allow-scripts’ permission is not set.
Using karma-coverage-istanbul-reporter https://github.com/mattlewis92/karma-coverage-istanbul-reporter