-
Notifications
You must be signed in to change notification settings - Fork 781
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
6 changed files
with
225 additions
and
21 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
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,18 +38,25 @@ 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: [] }); | ||
|
||
this._do_one_test(); | ||
}, | ||
_do_one_test: function () { | ||
this.emit('testStart', { testId: '00A', name: 'A' }); | ||
this.emit('log', { | ||
testId: '00A', | ||
result: true, | ||
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 +99,11 @@ QUnit.module.if('HtmlReporter', typeof document !== 'undefined', { | |
}); | ||
} | ||
}; | ||
}, | ||
afterEach: function () { | ||
if (this.restoreQUnitElement) { | ||
this.restoreQUnitElement.id = 'qunit'; | ||
} | ||
} | ||
}); | ||
|
||
|
@@ -223,6 +235,75 @@ QUnit.test('test-output [trace]', function (assert) { | |
); | ||
}); | ||
|
||
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._do_start_empty(); | ||
this.MockQUnit.emit('error', err); | ||
this.MockQUnit._do_one_test(); | ||
|
||
var testItem = element.querySelector('#qunit-test-output-00A'); | ||
assert.strictEqual( | ||
testItem.textContent, | ||
'A (1)' + 'Rerun' + '0 ms' + | ||
'okay' + '@ 0 ms', | ||
'test item (normal)' | ||
); | ||
|
||
// 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('onError [mid-run]', 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._do_start_with_one(); | ||
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', | ||
'test item (normal)' | ||
); | ||
|
||
// 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('appendFilteredTest()', function (assert) { | ||
var element = document.createElement('div'); | ||
new QUnit.reporters.html(this.MockQUnit, { | ||
|
@@ -322,7 +403,7 @@ QUnit.test('options [urlConfig]', function (assert) { | |
)); | ||
}); | ||
|
||
QUnit.test('disable [via options.element=null]', function (assert) { | ||
QUnit.test('listen [disable via options.element=null]', function (assert) { | ||
this.MockQUnit.on = function (type) { | ||
assert.step('listen on-' + type); | ||
}; | ||
|
@@ -336,7 +417,74 @@ QUnit.test('disable [via options.element=null]', function (assert) { | |
}); | ||
this.MockQUnit._do_mixed_run_full(); | ||
|
||
assert.verifySteps([], 'zero listeners when disabled'); | ||
assert.verifySteps([], 'listeners'); | ||
}); | ||
|
||
QUnit.test('listen [disable via 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-runStart' | ||
], | ||
'listeners' | ||
); | ||
}); | ||
|
||
QUnit.test('listen [enable via options.element]', function (assert) { | ||
this.MockQUnit.on = function (event, fn) { | ||
assert.step('listen on-' + event); | ||
this.on[event] = fn; | ||
}; | ||
|
||
var element = document.createElement('div'); | ||
new QUnit.reporters.html(this.MockQUnit, { | ||
element: element, | ||
config: { | ||
urlConfig: [] | ||
} | ||
}); | ||
|
||
assert.verifySteps( | ||
[ | ||
'listen on-runStart' | ||
], | ||
'listeners after construction' | ||
); | ||
|
||
this.MockQUnit._do_start_empty(); | ||
|
||
assert.verifySteps( | ||
[ | ||
'listen on-begin', | ||
'listen on-testStart', | ||
'listen on-log', | ||
'listen on-testDone', | ||
'listen on-runEnd', | ||
'listen on-error' | ||
], | ||
'listeners after start' | ||
); | ||
}); | ||
|
||
QUnit.test('module selector', function (assert) { | ||
|