node-x11/test-runner.js
Santiago Gimeno 9b8cef815b A couple of fixes in xtest extension
- Return directly in case of error retrieving the extension.
- QueryVersion should be GetVersion and fix its format.
- Add a test for GetVersion.
- Modify test-runner.js so it uses async library to add dynamically the test
  files to be used.
2012-11-26 16:51:56 +01:00

89 lines
2.3 KiB
JavaScript

var x11 = require('./lib/x11');
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
var util = require('util');
var async = require('async');
var mocha = new Mocha({
timeout : 80000
});
// To be able to perform the tests we need the server:
// 1 - to support the dpms extension.
// 2 - dpms version is 1.1.
// 3 - to be dpms capable.
var run_dpms_test = function(cb) {
var client = x11.createClient(function(dpy) {
var display = dpy;
var X = display.client;
X.require('dpms', function(ext) {
if (!util.isError(ext)) {
dpms = ext;
dpms.GetVersion(undefined, undefined, function(err, version) {
if (!err && version[0] === 1 && version[1] === 1) {
dpms.Capable(function(err, capable) {
if (!err && capable[0] == 1) cb(true);
else cb(false);
});
} else {
cb(false);
}
});
} else {
cb(false);
}
});
});
client.on('error', function() {
cb(false);
});
};
var run_xtest_test = function(cb) {
var client = x11.createClient(function(dpy) {
var display = dpy;
var X = display.client;
X.require('dpms', function(ext) {
if (!util.isError(ext)) cb(true);
else cb(false);
});
});
client.on('error', function() {
cb(false);
});
};
// Add all files from test root directory
async.forEach(
fs.readdirSync('./test'),
function(file, cb) {
if (file === 'dpms.js') {
run_dpms_test(function(run) {
if (run) {
mocha.addFile(path.join('./test', file));
}
cb();
});
} else if (file === 'xtest.js') {
run_xtest_test(function(run) {
if (run) {
mocha.addFile(path.join('./test', file));
}
cb();
});
} else {
mocha.addFile(path.join('./test', file));
cb();
}
},
function(err) {
mocha.run(function() {
process.exit();
});
}
);