mirror of
https://github.com/less/less.js.git
synced 2026-04-09 03:00:20 -04:00
Improvements to browser tests that don't raise a false negative when switching branches
This commit is contained in:
@@ -2,12 +2,17 @@ var path = require('path'),
|
||||
fs = require('fs'),
|
||||
sys = require('util');
|
||||
|
||||
var readDirFilesSync = function(dir, regex, callback) {
|
||||
fs.readdirSync(dir).forEach(function (file) {
|
||||
if (! regex.test(file)) { return; }
|
||||
callback(file);
|
||||
});
|
||||
}
|
||||
|
||||
var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
|
||||
var output = '<html><head>\n';
|
||||
|
||||
fs.readdirSync(path.join("test", dir, 'less', dir2 || "")).forEach(function (file) {
|
||||
if (! /\.less/.test(file)) { return; }
|
||||
|
||||
readDirFilesSync(path.join("test", dir, 'less', dir2 || ""), /\.less$/, function (file) {
|
||||
var name = path.basename(file, '.less'),
|
||||
id = (dir ? dir + '-' : "") + 'less-' + (dir2 ? dir2 + "-" : "") + name;
|
||||
|
||||
@@ -22,6 +27,15 @@ var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
|
||||
fs.writeFileSync(path.join('test/browser', 'test-runner-'+testSuiteName+'.htm'), output);
|
||||
};
|
||||
|
||||
var removeFiles = function(dir, regex) {
|
||||
readDirFilesSync(dir, regex, function(file) {
|
||||
fs.unlinkSync(path.join(dir, file), function() {
|
||||
console.log("Failed to delete " + file);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
removeFiles("test/browser", /test-runner-[a-zA-Z-]*\.htm$/);
|
||||
createTestRunnerPage("", /javascript|urls/, "main");
|
||||
createTestRunnerPage("", null, "legacy", "legacy");
|
||||
createTestRunnerPage("", /javascript/, "errors", "errors");
|
||||
|
||||
@@ -40,8 +40,9 @@ if (!listening) {
|
||||
* it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
|
||||
* as a callback function.
|
||||
* @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used.
|
||||
* @param timeOutErrorMessage the error message if time out occurs
|
||||
*/
|
||||
function waitFor(testFx, onReady, timeOutMillis) {
|
||||
function waitFor(testFx, onReady, timeOutMillis, timeOutErrorMessage) {
|
||||
var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 10001, //< Default Max Timeout is 10s
|
||||
start = new Date().getTime(),
|
||||
condition = false,
|
||||
@@ -52,11 +53,10 @@ function waitFor(testFx, onReady, timeOutMillis) {
|
||||
} else {
|
||||
if(!condition) {
|
||||
// If condition still not fulfilled (timeout but condition is 'false')
|
||||
console.log("'waitFor()' timeout");
|
||||
console.log(timeOutErrorMessage || "'waitFor()' timeout");
|
||||
phantom.exit(1);
|
||||
} else {
|
||||
// Condition fulfilled (timeout and/or condition is 'true')
|
||||
//console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms.");
|
||||
typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
|
||||
clearInterval(interval); //< Stop this interval
|
||||
}
|
||||
@@ -104,7 +104,9 @@ function testPage(url) {
|
||||
}
|
||||
});
|
||||
testFinished(exitCode);
|
||||
});
|
||||
},
|
||||
10000, // 10 second timeout
|
||||
"Test failed waiting for jasmine results on page: " + url);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user