mole-rpc-autotester
Automatic tester for Mole-RPC (JSON-RPC library) transports.
If you writes own transport for Mole-RPC then use this module to be sure that your transport covers as expected.
This module does end-to-end testing and will:
- Run simple positive tests for simpleClient
- Run simple positive notification tests for simpleClient
- Run positive batch tests for simpleClient
- Run simple positive tests for proxifiedClient
- Run simple positive notification tests for proxifiedClient
- Run proxy positive tests for proxifiedClient
- Run proxy positive notification tests for proxifiedClient
- Run simple negative tests for simpleClient
- Run simple negative tests for proxifiedClient
- Run proxy negative tests for proxifiedClient
- It will test both sync and async calls
- Will test method execution errors
This modules covers a lot of cases but it does not help you with detecting memory leaks, reconnection problems etc.
How to use it?
This example covers almose all of the API of the module.
Do not forget to add 'mole-rpc' and 'mole-rpc-autotester' to devDependencies of your transport's package.json.
const AutoTester = require('mole-rpc-autotester');
const MoleClient = require('mole-rpc/MoleClient');
const MoleClientProxified = require('mole-rpc/MoleClientProxified');
const MoleServer = require('mole-rpc/MoleServer');
const X = require('mole-rpc/X');
const TransportClient = require('./TransportClient');
const TransportServer = require('./TransportServer');
async function main() {
const server = await prepareServer();
const clients = await prepareClients();
const autoTester = new AutoTester({
X,
server,
simpleClient: clients.simpleClient,
proxifiedClient: clients.proxifiedClient
});
await autoTester.runAllTests();
}
async function prepareServer() {
return new MoleServer({
transports: [
new TransportServer(...)
]
});
}
async function prepareClients() {
const simpleClient = new MoleClient({
requestTimeout: 1000,
transport: new TransportClient(...)
});
const proxifiedClient = new MoleClientProxified({
requestTimeout: 1000,
transport: new TransportClient(...)
});
return { simpleClient, proxifiedClient };
}
main().then(console.log, console.error);
Real examples
You can find more tranports here