mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
Only execute dpms test when we can
- Add test-runner.js to be able to execute the dpms when these
conditions are complied:
1 - DPMS extension is supported.
2 - DPMS version is 1.1.
3 - DPMS is capable.
This commit is contained in:
parent
c0dccec8bc
commit
e6796ab192
3 changed files with 60 additions and 13 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
"should": "*"
|
"should": "*"
|
||||||
}
|
}
|
||||||
, "scripts": {
|
, "scripts": {
|
||||||
"test": "mocha -t 80000",
|
"test": "node test-runner.js",
|
||||||
"prepublish" : "npm prune"
|
"prepublish" : "npm prune"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
58
test-runner.js
Normal file
58
test-runner.js
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
var x11 = require('./lib/x11');
|
||||||
|
var Mocha = require('mocha');
|
||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add all files from test root directory
|
||||||
|
fs.readdirSync('./test').forEach(function(file) {
|
||||||
|
if (file === 'dpms.js') {
|
||||||
|
run_dpms_test(function(run) {
|
||||||
|
if (run) {
|
||||||
|
mocha.addFile(path.join('./test', file));
|
||||||
|
}
|
||||||
|
|
||||||
|
mocha.run(function(){
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
mocha.addFile(path.join('./test', file));
|
||||||
|
}
|
||||||
|
});
|
||||||
13
test/dpms.js
13
test/dpms.js
|
|
@ -11,23 +11,12 @@ describe('DPMS extension', function() {
|
||||||
var client = x11.createClient(function(dpy) {
|
var client = x11.createClient(function(dpy) {
|
||||||
display = dpy;
|
display = dpy;
|
||||||
X = display.client;
|
X = display.client;
|
||||||
// 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.
|
|
||||||
X.require('dpms', function(ext) {
|
X.require('dpms', function(ext) {
|
||||||
if (util.isError(ext)) {
|
if (util.isError(ext)) {
|
||||||
done(ext);
|
done(ext);
|
||||||
} else {
|
} else {
|
||||||
dpms = ext;
|
dpms = ext;
|
||||||
dpms.GetVersion(undefined, undefined, function(err, version) {
|
done();
|
||||||
if (err) return done(err);
|
|
||||||
version.should.eql([1, 1]);
|
|
||||||
dpms.Capable(function(err, capable) {
|
|
||||||
if (!err) capable.should.eql([1]);
|
|
||||||
done(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue