Permalink
Browse files

Add automatic launch of tests

You need a working selenium grid or a selenium sauce account
  • Loading branch information...
1 parent 90ec3b4 commit 47cfb242cbd439de2c66f018c59deda8ae8d2b64 @vvo committed Jan 19, 2013
Showing with 63 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 package.json
  3. +53 −0 tests/functionnal.js
  4. +2 −2 tests/js/helper.js
View
@@ -0,0 +1 @@
+node_modules
View
@@ -6,13 +6,20 @@
"type": "git",
"url": "http://github.com/vvo/lazyload.git"
},
+ "dependencies": {
+ "wd": "0.0.x",
+ "async": "0.1.x"
+ },
"private": true,
"keywords": [
"performance",
"image",
"lazyload",
"webperf"
],
+ "scripts": {
+ "test": "node tests/functionnal.js"
+ },
"author": "Vincent Voyer <vincent.voyer@gmail.com> (http://github.com/vvo)",
"license": "MIT"
}
View
@@ -0,0 +1,53 @@
+var wd = require('wd');
+var async = require('async');
+var assert = require('assert');
+
+var desired = {
+ browserName: 'firefox'
+}
+
+findTests(function(err, tests) {
+ async.forEachSeries(tests, runTest, function(err) {
+ if (err !== null) {
+ assert.fail(err, null, err.message)
+ }
+ })
+});
+
+function findTests(cb) {
+ var fs = require('fs');
+ fs.readdir(__dirname, function(err, files) {
+ files = files.filter(isHtml);
+ files = files.sort();
+ // files = [files[5]]
+ cb(null, files);
+ });
+
+ function isHtml(file) {
+ return /\.html$/.test(file);
+ }
+}
+
+function runTest(file, cb) {
+ var browser = wd.remote();
+
+ async.series([
+ browser.init.bind(browser, desired),
+ browser.get.bind(browser, 'http://192.168.56.1:8080/tests/' + file),
+ // wait for the test to execute before polling
+ wait.bind(null, 1000),
+ browser.waitForCondition.bind(browser, "errorFlag === false && successFlag === true", 1000, 100)
+ ], function(err, results) {
+ browser.quit();
+ if(err !== null) {
+ cb(new Error(file + ' has had an error: ' + err));
+ } else {
+ console.log(file + ' was OK');
+ cb(null);
+ }
+ });
+}
+
+function wait(ms, cb) {
+ setTimeout(cb, ms);
+}
View
@@ -18,7 +18,7 @@ var error = makeRunOnce(function error(msg) {
});
var success = makeRunOnce(function success() {
if (errorFlag) return;
- success = true;
+ successFlag = true;
document.getElementById('debug').className = 'hide';
document.getElementById('result').className = 'success';
});
@@ -59,6 +59,6 @@ function makeRunOnce(fn) {
window.onerror = function() {
window.onload = function() {
- error();
+ error();
}
}

0 comments on commit 47cfb24

Please sign in to comment.