From 2f8995051f9f78eda5c369294ca947eaf8283660 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Wed, 3 Jul 2024 20:29:31 +0100 Subject: [PATCH] Test: Convert remaining test/reporter-html/ to test/main/HtmlReporter.js --- test/index.html | 1 - test/main/HtmlReporter.js | 147 ++++++++++++++++++++++++++++ test/reporter-html/reporter-html.js | 125 ----------------------- 3 files changed, 147 insertions(+), 126 deletions(-) delete mode 100644 test/reporter-html/reporter-html.js diff --git a/test/index.html b/test/index.html index fb4cca50d..2c0c5ad4b 100644 --- a/test/index.html +++ b/test/index.html @@ -27,7 +27,6 @@ - diff --git a/test/main/HtmlReporter.js b/test/main/HtmlReporter.js index 6afae17e8..6291a6d14 100644 --- a/test/main/HtmlReporter.js +++ b/test/main/HtmlReporter.js @@ -96,6 +96,7 @@ QUnit.test('testresult-display [begin]', function (assert) { var testresult = element.querySelector('#qunit-testresult'); assert.equal(testresult.className, 'result', 'testresult class'); assert.equal(testresult.textContent, 'Running...\u00A0Abort', 'testresult text'); + var display = element.querySelector('#qunit-testresult-display'); assert.equal(display.className, '', 'display class'); assert.equal(display.textContent, 'Running...\u00A0', 'display text'); @@ -113,9 +114,65 @@ QUnit.test('testresult-display [testStart]', function (assert) { var testresult = element.querySelector('#qunit-testresult'); assert.equal(testresult.className, 'result', 'testresult class'); + var display = element.querySelector('#qunit-testresult-display'); assert.equal(display.className, 'running', 'display class'); assert.equal(display.textContent, '1 / 4 tests completed.Running: B', 'display text'); + + var testOutput = element.querySelector('#qunit-test-output-00A'); + assert.equal( + testOutput.textContent, + 'A (1)' + 'Rerun' + '0 ms' + 'okay' + '@ 0 ms', + 'test output: name, count, duration, assert message, and assert runtime offset' + ); +}); + +QUnit.test('test-output trace', function (assert) { + var element = document.createElement('div'); + new QUnit.reporters.html(this.MockQUnit, { + element: element, + config: { + urlConfig: [] + } + }); + + this.MockQUnit.emit('runStart', { testCounts: { total: 1 } }); + this.MockQUnit.emit('begin', { modules: [] }); + this.MockQUnit.emit('testStart', { testId: '00A', name: 'A' }); + this.MockQUnit.emit('log', { + testId: '00A', + message: 'boo', + result: false, + actual: false, + expected: true, + source: 'bar@example.js\nfoo@example.js\n@foo.test.js', + runtime: 1 + }); + this.MockQUnit.emit('testDone', { + testId: '00A', + name: 'A', + source: '@foo.test.js', + total: 1, + passed: 1, + failed: 0, + runtime: 2 + }); + this.MockQUnit.emit('runEnd', { + testCounts: { total: 1, passed: 0, failed: 1, skipped: 0, todo: 0 }, + status: 'failed', + runtime: 2 + }); + + var testOutput = element.querySelector('#qunit-test-output-00A'); + assert.strictEqual( + testOutput.textContent, + 'A (1)' + 'Rerun' + '2 ms' + 'boo' + '@ 1 ms' + + 'Expected: true' + + 'Result: false' + + 'Source: bar@example.js\nfoo@example.js\n@foo.test.js' + + 'Source: @foo.test.js', + 'test output' + ); }); QUnit.test('appendFilteredTest() [testId]', function (assert) { @@ -174,3 +231,93 @@ QUnit.test('filter', function (assert) { assert.strictEqual(node.nodeName, 'INPUT'); assert.strictEqual(node.value, '!/Foo|bar/'); }); + +QUnit.test('module selector', function (assert) { + var element = document.createElement('div'); + new QUnit.reporters.html(this.MockQUnit, { + element: element, + config: { + urlConfig: [] + } + }); + this.MockQUnit._do_start_empty(); + + var node = element.querySelector('#qunit-modulefilter-search'); + assert.strictEqual(node.autocomplete, 'off', 'disables autocomplete'); +}); + +QUnit.test('overall escaping', function (assert) { + var element = document.createElement('div'); + new QUnit.reporters.html(this.MockQUnit, { + element: element, + config: { + urlConfig: [] + } + }); + + this.MockQUnit.emit('runStart', { testCounts: { total: 1 } }); + this.MockQUnit.emit('begin', { + modules: [ + { moduleId: 'FF1', name: "" } + ] + }); + this.MockQUnit.emit('testStart', { + testId: '00A', + module: "", + name: "" + }); + this.MockQUnit.emit('log', { + testId: '00A', + message: "", + result: true, + runtime: 0 + }); + this.MockQUnit.emit('log', { + testId: '00A', + message: "", + result: false, + actual: false, + expected: true, + runtime: 1 + }); + this.MockQUnit.emit('testDone', { + testId: '00A', + module: "", + name: "", + total: 2, + passed: 1, + failed: 1, + runtime: 1 + }); + this.MockQUnit.emit('runEnd', { + testCounts: { total: 1, passed: 0, failed: 1, skipped: 0, todo: 0 }, + status: 'failed', + runtime: 2 + }); + + var scriptTagPos = element.innerHTML.indexOf('window.oops='module';: (1, 1, 2)" + + 'Rerun' + + '1 ms' + + "@ 0 ms" + + "@ 1 ms" + + 'Expected: true' + + 'Result: false', + 'formatting of test output' + ); + + var oopsModule = element.querySelector('#oops-module') || document.querySelector('#oops-module'); + var oopsTest = element.querySelector('#oops-test') || document.querySelector('#oops-test'); + var oopsAssertion = element.querySelector('#oops-assertion') || document.querySelector('#oops-assertion'); + assert.strictEqual(oopsModule, null, 'escape module name'); + assert.strictEqual(oopsTest, null, 'escape test name'); + assert.strictEqual(oopsAssertion, null, 'escape assertion message'); +}); diff --git a/test/reporter-html/reporter-html.js b/test/reporter-html/reporter-html.js deleted file mode 100644 index b4cf95aa0..000000000 --- a/test/reporter-html/reporter-html.js +++ /dev/null @@ -1,125 +0,0 @@ -/* eslint-env browser */ - -// The following tests need to run on their respective order -QUnit.config.reorder = false; - -QUnit.module('HTML Reporter', function () { - QUnit.module("", { - beforeEach: function () { - }, - afterEach: function (assert) { - // We can't use ok(false) inside script tags since some browsers - // don't evaluate script tags inserted through innerHTML after domready. - // Counting them before/after doesn't cover everything either as qunit-modulefilter - // is created before any test is ran. So use ids instead. - if (document.getElementById('qunit-unescaped-module')) { - // This can either be from in #qunit-modulefilter or #qunit-testresult - assert.true(false, 'Unescaped module name'); - } - if (document.getElementById('qunit-unescaped-test')) { - assert.true(false, 'Unescaped test name'); - } - if (document.getElementById('qunit-unescaped-assertion')) { - assert.true(false, 'Unescaped test name'); - } - } - }); - - QUnit.test("", function (assert) { - assert.true(true, ""); - }); - - QUnit.module('Duration', { - getPreviousTest: function (assert) { - return document.getElementById('qunit-test-output-' + assert.test.testId) - .previousSibling; - }, - filterClass: function (elements) { - var i; - for (i = 0; i < elements.length; i++) { - if (/(^| )runtime( |$)/.test(elements[i].className)) { - return elements[i]; - } - } - }, - afterEach: function (assert) { - var done; - if (this.delayNextSetup) { - this.delayNextSetup = false; - done = assert.async(); - setTimeout(function () { - done(); - }, 101); - } - } - }); - - QUnit.test('setup', function (assert) { - assert.expect(0); - this.delayNextSetup = true; - }); - - QUnit.test('basics', function (assert) { - assert.expect(1); - var previous = this.getPreviousTest(assert); - var runtime = this.filterClass(previous.getElementsByTagName('span')).innerHTML; - - assert.true(/^\d+ ms$/.test(runtime), 'Runtime reported in ms: ' + runtime); - }); - - QUnit.test('values', function (assert) { - assert.expect(2); - - var basics = this.getPreviousTest(assert); - var setup = basics.previousSibling; - - basics = this.filterClass(basics.getElementsByTagName('span')).innerHTML; - setup = this.filterClass(setup.getElementsByTagName('span')).innerHTML; - - assert.true(parseInt(basics, 10) < 100, - 'Fast runtime for trivial test: ' + basics - ); - assert.true(parseInt(setup, 10) > 100, - 'Runtime includes beforeEach: ' + setup - ); - }); - - QUnit.module('Stack trace'); - - QUnit.test('setup', function (assert) { - assert.expect(0); - }); - - QUnit.test('logs location', function (assert) { - var previous = document.getElementById('qunit-test-output-' + assert.test.testId) - .previousSibling; - var source = previous.lastChild; - var err = new Error(); - - // Verify QUnit supported stack trace - if (!err.stack) { - // eslint-disable-next-line qunit/no-conditional-assertions - assert.false( - /(^| )qunit-source( |$)/.test(source.className), - "Don't add source information on unsupported environments" - ); - - // eslint-disable-next-line qunit/no-early-return - return; - } - - assert.true(/(^| )qunit-source( |$)/.test(source.className), 'Source element exists'); - assert.equal(source.firstChild.innerHTML, 'Source: '); - - // The file test/reporter-html/reporter-html.js is a direct reference to this test file - assert.true(/\/test\/reporter-html\/reporter-html\.js:\d+/.test(source.innerHTML), - 'Source references to the current file and line number' - ); - }); - - QUnit.test('disables autocomplete on module filter', function (assert) { - var moduleFilterSearch = document.getElementById('qunit-modulefilter-search'); - - assert.equal(moduleFilterSearch.autocomplete, 'off'); - }); -});