[go: nahoru, domu]

Skip to content

Commit

Permalink
Test: Convert test/reporter-html "Display" 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 63707ae commit 511480a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
43 changes: 41 additions & 2 deletions test/main/HtmlReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
this.emit('runStart', { testCounts: { total: 0 } });
this.emit('begin', { modules: [] });
},
_do_mixed_run: function () {
// The first 1.5 test.
_do_mixed_run_half: function () {
this.emit('runStart', { testCounts: { total: 4 } });
this.emit('begin', { modules: [] });

Expand All @@ -44,6 +45,9 @@
result: true,
runtime: 1
});
},
_do_mixed_run_full: function () {
this._do_mixed_run_half();
this.emit('testDone', { testId: '00B', name: 'B', total: 1, passed: 1, failed: 0, runtime: 1 });

this.emit('testStart', { testId: '00C', name: 'C' });
Expand Down Expand Up @@ -79,6 +83,41 @@
}
});

QUnit.test('testresult-display [begin]', function (assert) {
var element = document.createElement('div');
new QUnit.reporters.html(this.MockQUnit, {
element: element,
config: {
urlConfig: []
}
});
this.MockQUnit._do_start_empty();

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');
});

QUnit.test('testresult-display [testStart]', function (assert) {
var element = document.createElement('div');
new QUnit.reporters.html(this.MockQUnit, {
element: element,
config: {
urlConfig: []
}
});
this.MockQUnit._do_mixed_run_half();

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');
});

QUnit.test('appendFilteredTest() [testId]', function (assert) {
var element = document.createElement('div');
new QUnit.reporters.html(this.MockQUnit, {
Expand Down Expand Up @@ -107,7 +146,7 @@ QUnit.test('hidepassed', function (assert) {
urlConfig: ['hidepassed']
}
});
this.MockQUnit._do_mixed_run();
this.MockQUnit._do_mixed_run_full();

// Of the 5 tests, hide 2 passed and 1 skipped, show 2 failed.
var tests = element.querySelector('#qunit-tests');
Expand Down
23 changes: 0 additions & 23 deletions test/reporter-html/reporter-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,6 @@ QUnit.module('HTML Reporter', function () {
assert.true(true, "<script id='qunit-unescaped-asassertionsert'>'assertion';</script>");
});

QUnit.module('Display');

QUnit.test("use 'running' class", function (assert) {
assert.equal(document.querySelectorAll('#qunit-testresult-display.running').length, 1);
});

QUnit.test('running text', function (assert) {
var display = document.getElementById('qunit-testresult');

assert.true(/running text/.test(display.innerHTML), 'test name');
assert.true(/Display/.test(display.innerHTML), 'module name');
});

QUnit.test('run progress', function (assert) {
var display = document.getElementById('qunit-testresult');

var expected = /\d+ \/ \d+ tests completed/;
assert.true(
expected.test(display.innerHTML),
'progress found in displayed text'
);
});

QUnit.module('Duration', {
getPreviousTest: function (assert) {
return document.getElementById('qunit-test-output-' + assert.test.testId)
Expand Down

0 comments on commit 511480a

Please sign in to comment.