diff --git a/.gitignore b/.gitignore index 7892b7d..7cf62bc 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ local.properties ### YouCompleteMe - VIM plugin .ycm_extra_conf.py + +##Tests JS +node_modules/ diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..19e5cf8 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,9 @@ +module.exports = function(grunt) { + grunt.initConfig({ + qunit: { + src: 'testing/js_test_report.html' + } + }); + grunt.loadNpmTasks('grunt-contrib-qunit'); + grunt.registerTask('test', 'qunit:src'); +}; diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..3c1140b --- /dev/null +++ b/circle.yml @@ -0,0 +1,11 @@ +## Customize dependencies +dependencies: + override: + - npm install -g grunt-cli + - npm install grunt + - npm install grunt-contrib-qunit + +## Customize test commands +test: + override: + - grunt test diff --git a/pytest_html/plugin.py b/pytest_html/plugin.py index 922c3ef..4977888 100644 --- a/pytest_html/plugin.py +++ b/pytest_html/plugin.py @@ -382,7 +382,8 @@ class HTMLReport(object): html.script(raw(main_js)), html.p('Report generated on {0} at {1}'.format( generated.strftime('%d-%b-%Y'), - generated.strftime('%H:%M:%S')))) + generated.strftime('%H:%M:%S'))), + onLoad='init()') if session.config._environment: environment = set(session.config._environment) diff --git a/pytest_html/resources/main.js b/pytest_html/resources/main.js index 64d325e..394b81e 100644 --- a/pytest_html/resources/main.js +++ b/pytest_html/resources/main.js @@ -97,7 +97,8 @@ function add_collapse() { }); }) } -addEventListener("DOMContentLoaded", function() { + +function init () { reset_sort_headers(); add_collapse(); @@ -113,7 +114,7 @@ addEventListener("DOMContentLoaded", function() { }, false) }); -}); +}; function sort_table(clicked, key_func) { var rows = find_all('.results-table-row'); @@ -207,8 +208,7 @@ function is_all_rows_hidden(value) { function filter_table(elem) { var outcome_att = "data-test-result"; var outcome = elem.getAttribute(outcome_att); - class_outcome = outcome + " results-table-row"; - var outcome_rows = document.getElementsByClassName(class_outcome); + var outcome_rows = find_all("." + outcome); for(var i = 0; i < outcome_rows.length; i++){ outcome_rows[i].hidden = !elem.checked; @@ -216,6 +216,5 @@ function filter_table(elem) { var rows = find_all('.results-table-row').filter(is_all_rows_hidden); var all_rows_hidden = rows.length == 0 ? true : false; - var not_found_message = document.getElementById("not-found-message"); - not_found_message.hidden = !all_rows_hidden; + find("#not-found-message").hidden = !all_rows_hidden; } diff --git a/testing/js_test_report.html b/testing/js_test_report.html new file mode 100644 index 0000000..2daebe6 --- /dev/null +++ b/testing/js_test_report.html @@ -0,0 +1,62 @@ + + + + + + QUnit Pytest-HTML + + + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ResultTestDurationLinks
Rerunrerun.py::test_rexample1.00
+
@pytest.mark.flaky(reruns=5)
def test_example():
import random
> assert random.choice([True, False])
E assert False
E + where False = <bound method Random.choice of <random.Random object at 0x7fe80b85f420>>([True, False])
E + where <bound method Random.choice of <random.Random object at 0x7fe80b85f420>> = <module 'random' from '/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/random.pyc'>.choice

rerun.py:6: AssertionError
Passedrerun.py::test_example0.00
+
No log output captured.
+
Passedrerun.py::test_example0.00
+
No log output captured.
+
+
+ + diff --git a/testing/test.js b/testing/test.js new file mode 100644 index 0000000..49ebf52 --- /dev/null +++ b/testing/test.js @@ -0,0 +1,112 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + + QUnit.module( 'module', { + beforeEach: function( assert ) { + init(); + } + }); + + QUnit.test('sort_column', function(assert){ + function sort_column_test(col_re, first_element_then, first_element_now) { + assert.equal(find_all('.results-table-row')[0].className, first_element_then); + var row_sort = find(col_re); + sort_column(row_sort); + assert.equal(find_all('.results-table-row')[0].className, first_element_now); + } + //result + sort_column_test('[col=result]', + 'rerun results-table-row', 'passed results-table-row'); + sort_column_test('[col=result]', + 'passed results-table-row', 'rerun results-table-row'); + + //name + sort_column_test('[col=name]', + 'rerun results-table-row', 'passed results-table-row'); + sort_column_test('[col=name]', + 'passed results-table-row', 'rerun results-table-row'); + + //numeric + sort_column_test('[col=duration]', + 'rerun results-table-row', 'passed results-table-row'); + sort_column_test('[col=duration]', + 'passed results-table-row', 'rerun results-table-row'); + }); + +QUnit.test('filter_table', function(assert){ + function filter_table_test(outcome, checked) { + var filter_input = document.createElement('input'); + filter_input.setAttribute('data-test-result', outcome); + filter_input.checked = checked; + filter_table(filter_input); + + var outcomes = find_all('.' + outcome); + for(var i = 0; i < outcomes.length; i++) { + assert.equal(outcomes[i].hidden, !checked); + } + } + assert.equal(find('#not-found-message').hidden, true); + + filter_table_test('rerun', false); + filter_table_test('passed', false); + assert.equal(find('#not-found-message').hidden, false); + + filter_table_test('rerun', true); + assert.equal(find('#not-found-message').hidden, true); + + filter_table_test('passed', true); + +}); + +QUnit.test('show_hide_extras', function(assert) { + function show_extras_test(element){ + assert.equal(element.parentNode.nextElementSibling.className, 'collapsed'); + show_extras(element); + assert.notEqual(element.parentNode.nextElementSibling.className, 'collapsed'); + } + + function hide_extras_test(element){ + assert.notEqual(element.parentNode.nextElementSibling.className, 'collapsed'); + hide_extras(element); + assert.equal(element.parentNode.nextElementSibling.className, 'collapsed'); + } + //Passed results have log collapsed by default + show_extras_test(find('.passed').firstElementChild.firstElementChild); + hide_extras_test(find('.passed').firstElementChild.firstElementChild); + + hide_extras_test(find('.rerun').firstElementChild.firstElementChild); + show_extras_test(find('.rerun').firstElementChild.firstElementChild); +}); + +QUnit.test('show_hide_all_extras', function(assert) { + function show_all_extras_test(){ + show_all_extras(); + var extras = find_all('.extra'); + for (var i = 0; i < extras.length; i++) { + assert.notEqual(extras[i].parentNode.className, 'collapsed'); + } + } + + function hide_all_extras_test(){ + hide_all_extras(); + var extras = find_all('.extra'); + for (var i = 0; i < extras.length; i++) { + assert.equal(extras[i].parentNode.className, 'collapsed'); + } + } + + show_all_extras_test(); + hide_all_extras_test(); +}); + +QUnit.test('find', function (assert) { + assert.notEqual(find('#results-table-head'), null); + assert.notEqual(find('table#results-table'), null); + assert.equal(find('.not-in-table'), null); +}); + +QUnit.test('find_all', function(assert) { + assert.equal(find_all('.sortable').length, 3); + assert.equal(find_all('.not-in-table').length, 0); +}); diff --git a/test_pytest_html.py b/testing/test_pytest_html.py similarity index 100% rename from test_pytest_html.py rename to testing/test_pytest_html.py