This repository has been archived by the owner on May 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
79 lines (57 loc) · 2.09 KB
/
index.js
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
73
74
75
76
77
var net = require('net'),
dnode = require('dnode'),
TestCafe = require('testcafe').TestCafe;
exports.Server = function (cfg, port) {
var testCafe = new TestCafe(cfg);
var server = net.createServer(function (conn) {
var d = dnode({
on: function (evtName, callback) {
testCafe.on(evtName, callback);
},
listAvailableBrowsers: function (callback) {
callback(testCafe.listAvailableBrowsers());
},
listConnectedWorkers: function (callback) {
callback(testCafe.listConnectedWorkers());
},
listDirectory: testCafe.listDirectory.bind(testCafe),
runTests: testCafe.runTests.bind(testCafe)
});
conn.pipe(d).pipe(conn);
//NOTE: this fixes https://github.com/DevExpress/TestCafe-RPC/issues/1
conn.on('error', function () {
conn.destroy();
});
});
server.listen(port);
return testCafe;
};
var Client = exports.Client = function (serverPort, serverHostname) {
this.serverPort = serverPort;
this.serverHostname = serverHostname;
};
Client.prototype._rpc = function (methodName, args, callback, isEvent) {
var d = dnode.connect(this.serverPort, this.serverHostname).on('remote', function (remote) {
args.push(function () {
callback.apply(null, arguments);
if (!isEvent)
d.end();
});
remote[methodName].apply(remote, args);
});
};
Client.prototype.listAvailableBrowsers = function (callback) {
this._rpc('listAvailableBrowsers', [], callback, false);
};
Client.prototype.listConnectedWorkers = function (callback) {
this._rpc('listConnectedWorkers', [], callback, false);
};
Client.prototype.listDirectory = function (path, callback) {
this._rpc('listDirectory', [path], callback, false);
};
Client.prototype.runTests = function (options, callback) {
this._rpc('runTests', [options], callback, false);
};
Client.prototype.on = function (evtName, handler) {
this._rpc('on', [evtName], handler, true);
};