Skip to content

Commit 017bb2c

Browse files
committed
Improvements to browser tests that don't raise a false negative when switching branches
1 parent 46e1613 commit 017bb2c

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

test/browser-test-prepare.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ var path = require('path'),
22
fs = require('fs'),
33
sys = require('util');
44

5+
var readDirFilesSync = function(dir, regex, callback) {
6+
fs.readdirSync(dir).forEach(function (file) {
7+
if (! regex.test(file)) { return; }
8+
callback(file);
9+
});
10+
}
11+
512
var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
613
var output = '<html><head>\n';
714

8-
fs.readdirSync(path.join("test", dir, 'less', dir2 || "")).forEach(function (file) {
9-
if (! /\.less/.test(file)) { return; }
10-
15+
readDirFilesSync(path.join("test", dir, 'less', dir2 || ""), /\.less$/, function (file) {
1116
var name = path.basename(file, '.less'),
1217
id = (dir ? dir + '-' : "") + 'less-' + (dir2 ? dir2 + "-" : "") + name;
1318

@@ -22,6 +27,15 @@ var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
2227
fs.writeFileSync(path.join('test/browser', 'test-runner-'+testSuiteName+'.htm'), output);
2328
};
2429

30+
var removeFiles = function(dir, regex) {
31+
readDirFilesSync(dir, regex, function(file) {
32+
fs.unlinkSync(path.join(dir, file), function() {
33+
console.log("Failed to delete " + file);
34+
});
35+
});
36+
}
37+
38+
removeFiles("test/browser", /test-runner-[a-zA-Z-]*\.htm$/);
2539
createTestRunnerPage("", /javascript|urls/, "main");
2640
createTestRunnerPage("", null, "legacy", "legacy");
2741
createTestRunnerPage("", /javascript/, "errors", "errors");

test/browser/phantom-runner.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ if (!listening) {
4040
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
4141
* as a callback function.
4242
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
43+
* @param timeOutErrorMessage the error message if time out occurs
4344
*/
44-
function waitFor(testFx, onReady, timeOutMillis) {
45+
function waitFor(testFx, onReady, timeOutMillis, timeOutErrorMessage) {
4546
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 10001, //< Default Max Timeout is 10s
4647
start = new Date().getTime(),
4748
condition = false,
@@ -52,11 +53,10 @@ function waitFor(testFx, onReady, timeOutMillis) {
5253
} else {
5354
if(!condition) {
5455
// If condition still not fulfilled (timeout but condition is 'false')
55-
console.log("'waitFor()' timeout");
56+
console.log(timeOutErrorMessage || "'waitFor()' timeout");
5657
phantom.exit(1);
5758
} else {
5859
// Condition fulfilled (timeout and/or condition is 'true')
59-
//console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
6060
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
6161
clearInterval(interval); //< Stop this interval
6262
}
@@ -104,7 +104,9 @@ function testPage(url) {
104104
}
105105
});
106106
testFinished(exitCode);
107-
});
107+
},
108+
10000, // 10 second timeout
109+
"Test failed waiting for jasmine results on page: " + url);
108110
}
109111
});
110112
}

0 commit comments

Comments
 (0)