Skip to content

Commit

Permalink
Test: Convert remaining test/reporter-html/ to test/main/HtmlReporter.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jul 3, 2024
1 parent 511480a commit 2f89950
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 126 deletions.
1 change: 0 additions & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<script src="main/test.js"></script>
<script src="main/utilities.js"></script>

<script src="reporter-html/reporter-html.js"></script>
<script src="reporter-html/unhandled-rejection.js"></script>
</head>
<body>
Expand Down
147 changes: 147 additions & 0 deletions test/main/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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: '[email protected]\[email protected]\[email protected]',
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: [email protected]\[email protected]\[email protected]' +
'Source: @foo.test.js',
'test output'
);
});

QUnit.test('appendFilteredTest() [testId]', function (assert) {
Expand Down Expand Up @@ -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: "<script id='oops-module'>window.oops='module';</script>" }
]
});
this.MockQUnit.emit('testStart', {
testId: '00A',
module: "<script id='oops-module'>window.oops='module';</script>",
name: "<script id='oops-test'>window.oops='test';</script>"
});
this.MockQUnit.emit('log', {
testId: '00A',
message: "<script id='oops-assertion'>window.oops='assertion-pass';</script>",
result: true,
runtime: 0
});
this.MockQUnit.emit('log', {
testId: '00A',
message: "<script id='oops-assertion'>window.oops='assertion-fail';</script>",
result: false,
actual: false,
expected: true,
runtime: 1
});
this.MockQUnit.emit('testDone', {
testId: '00A',
module: "<script id='oops-module'>window.oops='module';</script>",
name: "<script id='oops-test'>window.oops='test';</script>",
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('<script');
var scriptTags = scriptTagPos !== -1 ? element.innerHTML.slice(scriptTagPos, scriptTagPos + 20) : '';
assert.strictEqual(scriptTags, '', 'escape script tags');

assert.strictEqual(window.oops, undefined, 'prevent eval');

var testOutput = element.querySelector('#qunit-test-output-00A');
assert.strictEqual(
testOutput.textContent,
"<script id='oops-module'>window.oops='module';</script>: <script id='oops-test'>window.oops='test';</script> (1, 1, 2)" +
'Rerun' +
'1 ms' +
"<script id='oops-assertion'>window.oops='assertion-pass';</script>@ 0 ms" +
"<script id='oops-assertion'>window.oops='assertion-fail';</script>@ 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');
});
125 changes: 0 additions & 125 deletions test/reporter-html/reporter-html.js

This file was deleted.

0 comments on commit 2f89950

Please sign in to comment.