Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #432 - Using a setTimeout stub can stop test suite from continuing #433

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gruntfile.js
Expand Up @@ -11,7 +11,8 @@ grunt.initConfig({
qunit: [
"test/index.html",
"test/async.html",
"test/logs.html"
"test/logs.html",
"test/setTimeout.html"
]
},
jshint: {
Expand Down
7 changes: 4 additions & 3 deletions qunit/qunit.js
Expand Up @@ -20,6 +20,7 @@ var QUnit,
hasOwn = Object.prototype.hasOwnProperty,
// Keep a local reference to Date (GH-283)
Date = window.Date,
setTimeout = window.setTimeout,
defined = {
setTimeout: typeof window.setTimeout !== "undefined",
sessionStorage: (function() {
Expand Down Expand Up @@ -466,7 +467,7 @@ QUnit = {
}
// A slight delay, to avoid any current callbacks
if ( defined.setTimeout ) {
window.setTimeout(function() {
setTimeout(function() {
if ( config.semaphore > 0 ) {
return;
}
Expand All @@ -489,7 +490,7 @@ QUnit = {

if ( config.testTimeout && defined.setTimeout ) {
clearTimeout( config.timeout );
config.timeout = window.setTimeout(function() {
config.timeout = setTimeout(function() {
QUnit.ok( false, "Test timed out" );
config.semaphore = 1;
QUnit.start();
Expand Down Expand Up @@ -1445,7 +1446,7 @@ function process( last ) {
if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) {
config.queue.shift()();
} else {
window.setTimeout( next, 13 );
setTimeout( next, 13 );
break;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/setTimeout.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>QUnit Fake setTimeout Test Suite</title>
<link rel="stylesheet" href="../qunit/qunit.css">
<script src="test.js"></script>
<script src="deepEqual.js"></script>
</head>
<body>
<div id="qunit"></div>
<script src="../qunit/qunit.js"></script>
<script src="setTimeout.js"></script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also needs swarminject.js.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 65d27d2.

</body>
</html>
15 changes: 15 additions & 0 deletions test/setTimeout.js
@@ -0,0 +1,15 @@
QUnit.config.updateRate = 1;

module("Module that mucks with time", {
setup: function() {
this.setTimeout = window.setTimeout;
window.setTimeout = function() {};
},

teardown: function() {
window.setTimeout = this.setTimeout;
}
});

test("just a test", function() { ok(true); });
test("just a test", function() { ok(true); });