VulpesOS/gaia/tests/jsmarionette/runner/marionette-js-runner/test/rpc_test.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

66 lines
1.5 KiB
JavaScript
Executable file

'use strict';
suite('rpc', function() {
var RPC = require('../lib/rpc');
var fork = require('child_process').fork;
var assert = require('assert');
var proc;
suiteSetup(function() {
proc = fork(__dirname + '/fixtures/rpc');
});
suiteTeardown(function() {
proc.kill();
});
var subject, client;
setup(function() {
subject = new RPC(proc.send.bind(proc));
client = subject.client('test', ['noArgs', 'args', 'error', 'getSelf']);
proc.on('message', subject.handle());
});
test('noArgs', function() {
return client.noArgs();
});
test('args', function() {
return client.args(1, 2, 3, 4).then(function(result) {
assert.deepEqual(result, [1, 2, 3, 4]);
});
});
test('objects', function() {
var obj;
return client.getSelf().then(function(rpcObj) {
obj = rpcObj;
return rpcObj.args('woot', 'bar');
}).then(function(value) {
assert.deepEqual(value, ['woot', 'bar']);
}).then(function() {
assert(obj.destroy, 'has implicit destroy method');
return obj.destroy();
}).then(function() {
return obj.args();
}).then(
function() { throw new Error('expected error'); },
function(err) {
assert.ok(err.message.indexOf('destroyed') !== -1);
}
);
});
test('error', function() {
return client.error()
.then(function() {
process.nextTick(function() {
throw new Error('must not resolve');
});
})
.catch (function(err) {
assert.equal(err.message, 'xfoo');
});
});
});