-
Notifications
You must be signed in to change notification settings - Fork 780
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML Reporter: Add support for displaying early errors
- Loading branch information
Showing
5 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>window-onerror-early</title> | ||
<link rel="stylesheet" href="../src/core/qunit.css"> | ||
<script src="../qunit/qunit.js"></script> | ||
<script> | ||
QUnit.begin(function () { | ||
// eslint-disable-next-line no-undef | ||
beginBoom(); | ||
}); | ||
|
||
// eslint-disable-next-line no-undef | ||
outerBoom(); | ||
</script> | ||
<script> | ||
QUnit.test('example', function (assert) { | ||
assert.true(true); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,8 @@ QUnit.module.if('HtmlReporter', typeof document !== 'undefined', { | |
this.emit('runStart', { testCounts: { total: 0 } }); | ||
this.emit('begin', { modules: [] }); | ||
}, | ||
// The first 1.5 test. | ||
_do_mixed_run_half: function () { | ||
// The first 1 test. | ||
_do_start_with_one: function () { | ||
this.emit('runStart', { testCounts: { total: 4 } }); | ||
this.emit('begin', { modules: [] }); | ||
|
||
|
@@ -50,6 +50,10 @@ QUnit.module.if('HtmlReporter', typeof document !== 'undefined', { | |
runtime: 0 | ||
}); | ||
this.emit('testDone', { testId: '00A', name: 'A', total: 1, passed: 1, failed: 0, runtime: 0 }); | ||
}, | ||
// The first 1.5 test. | ||
_do_mixed_run_half: function () { | ||
this._do_start_with_one(); | ||
|
||
this.emit('testStart', { testId: '00B', name: 'B' }); | ||
this.emit('log', { | ||
|
@@ -92,6 +96,11 @@ QUnit.module.if('HtmlReporter', typeof document !== 'undefined', { | |
}); | ||
} | ||
}; | ||
}, | ||
afterEach: function () { | ||
if (this.restoreQUnitElement) { | ||
this.restoreQUnitElement.id = 'qunit'; | ||
} | ||
} | ||
}); | ||
|
||
|
@@ -223,6 +232,72 @@ QUnit.test('test-output [trace]', function (assert) { | |
); | ||
}); | ||
|
||
QUnit.test('onError [mid-run]', function (assert) { | ||
var element = document.createElement('div'); | ||
new QUnit.reporters.html(this.MockQUnit, { | ||
element: element, | ||
config: { | ||
urlConfig: [] | ||
} | ||
}); | ||
this.MockQUnit._do_start_with_one(); | ||
var err = new Error('boo'); | ||
err.stack = '[email protected]\[email protected]\[email protected]'; | ||
this.MockQUnit.emit('error', err); | ||
|
||
var testItem = element.querySelector('#qunit-test-output-00A'); | ||
assert.strictEqual( | ||
testItem.textContent, | ||
'A (1)' + 'Rerun' + '0 ms' + | ||
'okay' + '@ 0 ms', | ||
'last test item (unchanged)' | ||
); | ||
|
||
// last child | ||
var errorItem = element.querySelector('#qunit-tests > li:last-child'); | ||
assert.strictEqual(errorItem.id, '', 'error item, ID'); | ||
assert.strictEqual( | ||
errorItem.textContent, | ||
'global failure' + | ||
'Error: boo' + | ||
'Source: [email protected]\[email protected]\[email protected]', | ||
'error item, text' | ||
); | ||
}); | ||
|
||
QUnit.test('onError [early]', function (assert) { | ||
var element = document.createElement('div'); | ||
new QUnit.reporters.html(this.MockQUnit, { | ||
element: element, | ||
config: { | ||
urlConfig: [] | ||
} | ||
}); | ||
var err = new Error('boo'); | ||
err.stack = '[email protected]\[email protected]\[email protected]'; | ||
this.MockQUnit.emit('error', err); | ||
this.MockQUnit._do_start_with_one(); | ||
|
||
var testItem = element.querySelector('#qunit-test-output-00A'); | ||
assert.strictEqual( | ||
testItem.textContent, | ||
'A (1)' + 'Rerun' + '0 ms' + | ||
'okay' + '@ 0 ms', | ||
'last test item (unchanged)' | ||
); | ||
|
||
// first child | ||
var errorItem = element.querySelector('#qunit-tests > li:first-child'); | ||
assert.strictEqual(errorItem.id, '', 'error item, ID'); | ||
assert.strictEqual( | ||
errorItem.textContent, | ||
'global failure' + | ||
'Error: boo' + | ||
'Source: [email protected]\[email protected]\[email protected]', | ||
'error item, text' | ||
); | ||
}); | ||
|
||
QUnit.test('appendFilteredTest()', function (assert) { | ||
var element = document.createElement('div'); | ||
new QUnit.reporters.html(this.MockQUnit, { | ||
|
@@ -336,7 +411,38 @@ QUnit.test('disable [via options.element=null]', function (assert) { | |
}); | ||
this.MockQUnit._do_mixed_run_full(); | ||
|
||
assert.verifySteps([], 'zero listeners when disabled'); | ||
assert.verifySteps([], 'zero listeners'); | ||
}); | ||
|
||
QUnit.test('disable [via default options and no qunit element]', function (assert) { | ||
// Temporarily hide the global #qunit element | ||
var globalElement = document.querySelector('#qunit'); | ||
if (globalElement) { | ||
globalElement.id = 'not-qunit'; | ||
this.restoreQUnitElement = globalElement; | ||
} | ||
|
||
this.MockQUnit.on = function (type) { | ||
assert.step('listen on-' + type); | ||
}; | ||
this.MockQUnit.emit = function () {}; | ||
|
||
new QUnit.reporters.html(this.MockQUnit, { | ||
config: { | ||
urlConfig: [] | ||
} | ||
}); | ||
this.MockQUnit._do_mixed_run_full(); | ||
|
||
var newElement = document.querySelector('#qunit'); | ||
assert.strictEqual(newElement, null, 'no automatic element created'); | ||
|
||
assert.verifySteps( | ||
[ | ||
'listen on-error', | ||
'listen on-runStart' | ||
], | ||
'listeners limited to early one-off events'); | ||
}); | ||
|
||
QUnit.test('module selector', function (assert) { | ||
|