Fails QUnit.test() after a timeout of 5 seconds.
Summary of changes: 1. Fails QUnit.test() it doesn't return within 5 seconds. Timing dependent tests should use fake timers instead. 2. Adds an option to disable the timeout when debugging failed tests locally. 3. Logs the current test to the console to ease debugging. NOTRY=true Trybots failing on tests that has already been deleted. Review URL: https://codereview.chromium.org/1638753003 Cr-Commit-Position: refs/heads/master@{#371890}
This commit is contained in:
third_party/qunit
3
third_party/qunit/README.chromium
vendored
3
third_party/qunit/README.chromium
vendored
@@ -31,4 +31,5 @@ testing.
|
||||
Local Modifications:
|
||||
No Modifications is made to src/qunit.js.
|
||||
src/browser_test_harness.js is added to enable running the QUnit test suite on
|
||||
try bots using the chromium browser test infrastructure.
|
||||
try bots using the chromium browser test infrastructure. It also automatically
|
||||
fails a test case if it doesn't return within a timeout of 5 seconds.
|
||||
|
74
third_party/qunit/src/browser_test_harness.js
vendored
74
third_party/qunit/src/browser_test_harness.js
vendored
@@ -16,6 +16,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var TEST_TIMEOUT_IN_MS = 5000;
|
||||
|
||||
var TestReporter = function() {
|
||||
this.errorMessage_ = '';
|
||||
this.failedTestsCount_ = 0;
|
||||
@@ -23,11 +25,25 @@ var TestReporter = function() {
|
||||
};
|
||||
|
||||
TestReporter.prototype.init = function(qunit) {
|
||||
qunit.testStart(this.onTestStart_.bind(this));
|
||||
qunit.testDone(this.onTestDone_.bind(this));
|
||||
qunit.log(this.onAssertion_.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{ module:string, name: string }} details
|
||||
*/
|
||||
TestReporter.prototype.onTestStart_ = function(details) {
|
||||
console.log('[===============]');
|
||||
console.log('[------RUN------] ' + details.module + '.' + details.name);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {{ module:string, name: string }} details
|
||||
*/
|
||||
TestReporter.prototype.onTestDone_ = function(details) {
|
||||
console.log('[---COMPLETED---] ' + details.module + '.' + details.name);
|
||||
console.log('[===============]');
|
||||
if (this.failedAssertions_.length > 0) {
|
||||
this.errorMessage_ += ' ' + details.module + '.' + details.name + '\n';
|
||||
this.errorMessage_ += this.failedAssertions_.map(
|
||||
@@ -94,4 +110,62 @@ if (automationController) {
|
||||
exports.browserTestHarness = testHarness;
|
||||
}
|
||||
|
||||
var qunitTest = QUnit.test;
|
||||
var reasonTimeout = {};
|
||||
|
||||
/**
|
||||
* Returns a promise that resolves after |delay| along with a timerId
|
||||
* for cancellation.
|
||||
*
|
||||
* @return {promise: !Promise, timerId: number}
|
||||
*/
|
||||
BrowserTestHarness.timeout = function(delay) {
|
||||
var timerId = 0;
|
||||
var promise = new Promise(function(resolve) {
|
||||
timerId = window.setTimeout(function() {
|
||||
resolve();
|
||||
}, delay);
|
||||
});
|
||||
return {
|
||||
timerId: timerId,
|
||||
promise: promise
|
||||
};
|
||||
};
|
||||
|
||||
QUnit.config.urlConfig.push({
|
||||
id: "disableTestTimeout",
|
||||
label: "disable test timeout",
|
||||
tooltip: "Check this when debugging locally to disable test timeout.",
|
||||
});
|
||||
|
||||
/**
|
||||
* Forces the test to fail after |TEST_TIMEOUT_IN_MS|.
|
||||
*
|
||||
* @param {function(QUnit.Assert)} testCallback
|
||||
*/
|
||||
BrowserTestHarness.test = function(testCallback) {
|
||||
return function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var timeout = BrowserTestHarness.timeout(TEST_TIMEOUT_IN_MS);
|
||||
|
||||
var testPromise = Promise.resolve(testCallback.apply(this, args))
|
||||
.then(function() {
|
||||
window.clearTimeout(timeout.timerId);
|
||||
});
|
||||
|
||||
var asserts = args[0];
|
||||
var timeoutPromise = timeout.promise.then(function(){
|
||||
asserts.ok(false, 'Test timed out after ' + TEST_TIMEOUT_IN_MS + ' ms')
|
||||
})
|
||||
|
||||
return Promise.race([testPromise, timeoutPromise]);
|
||||
};
|
||||
};
|
||||
|
||||
if (!QUnit.urlParams.disableTestTimeout) {
|
||||
QUnit.test = function(name, expected, testCallback, async) {
|
||||
qunitTest(name, expected, BrowserTestHarness.test(testCallback), async);
|
||||
};
|
||||
}
|
||||
|
||||
})(window.QUnit, window.domAutomationController, window);
|
Reference in New Issue
Block a user