Skip to content

Commit

Permalink
Merge pull request #179 from Krinkle/fix-timeout
Browse files Browse the repository at this point in the history
Restore page timeout handling and `fail.timeout` event
  • Loading branch information
vladikoff committed Jun 28, 2021
2 parents f558142 + 5ba6324 commit 188a29a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
17 changes: 17 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ module.exports = function(grunt) {
if (/test\/qunit[45]\.html/.test(stdout) &&
/passed: [12]/.test(stdout)) {
cb();
} else if (/test\/qunit_page_timeout\.html/.test(stdout) &&
/Chrome timed out/.test(stdout)) {
cb();
} else {
cb(false);
}
Expand All @@ -108,11 +111,25 @@ module.exports = function(grunt) {
},
seed: {
command: 'grunt qunit:seed --seed="7x9"'
},
pageTimeout: {
command: 'grunt qunit:failPageTimeout --with-failpagetimeout'
}
}

});

// Only register this failing task for the shell task that expects the failure
if (grunt.option('with-failpagetimeout')) {
grunt.config.set('qunit.failPageTimeout', {
options: {
urls: [
'http://localhost:9000/test/qunit_page_timeout.html'
]
}
});
}

// Build a mapping of url success counters.
var successes = {};
var currentUrl;
Expand Down
14 changes: 14 additions & 0 deletions chrome/bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@
}(function(QUnit) {
'use strict';

var lastMessage = performance.now();

// Don't re-order tests.
QUnit.config.reorder = false;

// Send messages to the Node process
function sendMessage() {
self.__grunt_contrib_qunit__.apply(self, [].slice.call(arguments));
lastMessage = performance.now();
}

if (self.__grunt_contrib_qunit_timeout__) {
setTimeout(function checkTimeout() {
if ((performance.now() - lastMessage) > self.__grunt_contrib_qunit_timeout__) {
sendMessage('fail.timeout');
} else {
// Keep checking
setTimeout(checkTimeout, 1000);
}
}, 1000);
}

// These methods connect QUnit to Headless Chrome.
Expand Down
4 changes: 3 additions & 1 deletion tasks/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ module.exports = function(grunt) {

// Read the content of the specified bridge files
var bridgeFiles = Array.isArray(options.inject) ? options.inject : [options.inject];
var bridgContents = [];
var bridgContents = [
"__grunt_contrib_qunit_timeout__ = " + JSON.stringify( options.timeout ) + ";"
];

for (var i = 0; i < bridgeFiles.length; i++) {
try {
Expand Down
14 changes: 14 additions & 0 deletions test/qunit_page_timeout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Suite</title>
<link rel="stylesheet" href="../node_modules/qunit/qunit/qunit.css" media="screen">
<script src="../node_modules/qunit/qunit/qunit.js"></script>
<script src="qunit_page_timeout.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>
7 changes: 7 additions & 0 deletions test/qunit_page_timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
QUnit.module('grunt-contrib-qunit timeout');

QUnit.test('last forever', function(assert) {
var done = assert.async();

assert.ok( true );
});

0 comments on commit 188a29a

Please sign in to comment.