diff --git a/README.rst b/README.rst index 0346b2ee..a50c064f 100644 --- a/README.rst +++ b/README.rst @@ -12,7 +12,7 @@ HTML report for the test results. :alt: PyPI .. image:: https://img.shields.io/conda/vn/conda-forge/pytest-html.svg :target: https://anaconda.org/conda-forge/pytest-html - :alt: Conda Forge + :alt: Conda Forge .. image:: https://img.shields.io/travis/pytest-dev/pytest-html.svg :target: https://travis-ci.org/pytest-dev/pytest-html/ :alt: Travis @@ -240,6 +240,14 @@ additional HTML and log output with a notice that the log is empty: del data[:] data.append(html.div('No log output captured.', class_='empty log')) +Display options +--------------- + +By default, all rows in the **Results** table will be expanded except those that have :code:`Passed`. + +This behavior can be customized with a query parameter: :code:`?collapsed=Passed,XFailed,Skipped`. + + Screenshots ----------- diff --git a/pytest_html/resources/main.js b/pytest_html/resources/main.js index 9d69f521..dfd0ae19 100644 --- a/pytest_html/resources/main.js +++ b/pytest_html/resources/main.js @@ -78,9 +78,10 @@ function add_collapse() { // Add show/hide link to each result find_all('.col-result').forEach(function(elem) { + var collapsed = get_query_parameter('collapsed') || 'Passed'; var extras = elem.parentNode.nextElementSibling; var expandcollapse = document.createElement("span"); - if (elem.innerHTML === 'Passed') { + if (collapsed.includes(elem.innerHTML)) { extras.classList.add("collapsed"); expandcollapse.classList.add("expander"); } else { @@ -98,6 +99,11 @@ function add_collapse() { }) } +function get_query_parameter(name) { + var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search); + return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); +} + function init () { reset_sort_headers(); diff --git a/testing/test.js b/testing/test.js index 49ebf526..a3496c9d 100644 --- a/testing/test.js +++ b/testing/test.js @@ -2,6 +2,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ + if (!String.prototype.includes) { + String.prototype.includes = function() {'use strict'; + return String.prototype.indexOf.apply(this, arguments) !== -1; + }; + } + QUnit.module( 'module', { beforeEach: function( assert ) { init();