-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtests.js
More file actions
72 lines (62 loc) · 2.36 KB
/
Copy pathtests.js
File metadata and controls
72 lines (62 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*global console,require,module,setTimeout,clearTimeout*/
var Promise = require('bluebird');
var nreplClient = require('../src/nrepl-client');
var nreplServer = Promise.promisifyAll(require('../src/nrepl-server'));
var exec = require("child_process").exec;
var serverOpts = {port: 7889, verbose: true, startTimeout: 20*1000},
timeoutDelay = 10*1000,
timeoutProc, client, server;
function createTimeout(test) {
return timeoutProc = setTimeout(function() {
test.ok(false, 'timeout');
test.done();
}, timeoutDelay);
}
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
var tests = {
setUp: function (callback) {
nreplServer.startAsync(serverOpts).then(function (serverState) {
server = serverState;
client = Promise.promisifyAll(nreplClient.connect({
port: serverState.port,
verbose: true
}));
console.log("client connecting");
return client.onceAsync('connect');
}).then(function () {
console.log("client connected");
callback();
});
},
tearDown: function (callback) {
// exec("bash -c 'ps aux | grep \":port 7889\" | grep -v grep | awk \"{ print $2 }\" | xargs kill -9'");
if (!client) {
console.error("client undefined in tearDown?!");
callback(); return;
}
client.once('close', function() {
clearTimeout(timeoutProc);
nreplServer.stop(server, callback);
});
client.end();
},
testEval: function (test) {
createTimeout(test);
client.evalAsync('(+ 3 4)').then(function(messages) {
test.equal(messages[0].value, '7');
test.deepEqual(messages[1].status, ['done']);
return client.evalAsync('(throw (RuntimeException. "foo"))');
}).then(function (messages) {
test.equal(messages.length, 3);
test.equal(messages[0].ex, 'class java.lang.RuntimeException');
test.deepEqual(messages[0].status, ['eval-error']);
test.ok(/^RuntimeException foo/.test(messages[1].err));
test.deepEqual(messages[2].status, ['done']);
}).catch(function (err) {
test.ok(!err, 'Got errors: ' + err);
}).finally(function () {
test.done();
});
}
};
module.exports = tests;