mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-19 19:55:51 +00:00
* sets up linting config and runs `yarn lint --fix` once, so that all changes will show up correctly in future PRs. * Note that there are still a lot of linter errors.
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { Client, BroadcastClient } from "xrpl-local";
|
|
|
|
import { createMockRippled } from "./mockRippled";
|
|
import { getFreePort } from "./testUtils";
|
|
|
|
function setupMockRippledConnection(testcase, port) {
|
|
return new Promise<void>((resolve, reject) => {
|
|
testcase.mockRippled = createMockRippled(port);
|
|
testcase._mockedServerPort = port;
|
|
testcase.client = new Client(`ws://localhost:${port}`);
|
|
testcase.client.connect().then(resolve).catch(reject);
|
|
});
|
|
}
|
|
|
|
function setupMockRippledConnectionForBroadcast(testcase, ports) {
|
|
return new Promise<void>((resolve, reject) => {
|
|
const servers = ports.map((port) => `ws://localhost:${port}`);
|
|
testcase.mocks = ports.map((port) => createMockRippled(port));
|
|
testcase.client = new BroadcastClient(servers);
|
|
testcase.client.connect().then(resolve).catch(reject);
|
|
});
|
|
}
|
|
|
|
function setup(this: any) {
|
|
return getFreePort().then((port) => {
|
|
return setupMockRippledConnection(this, port);
|
|
});
|
|
}
|
|
|
|
function setupBroadcast(this: any) {
|
|
return Promise.all([getFreePort(), getFreePort()]).then((ports) => {
|
|
return setupMockRippledConnectionForBroadcast(this, ports);
|
|
});
|
|
}
|
|
|
|
function teardown(this: any, done) {
|
|
this.client
|
|
.disconnect()
|
|
.then(() => {
|
|
if (this.mockRippled != null) {
|
|
this.mockRippled.close();
|
|
} else {
|
|
this.mocks.forEach((mock) => mock.close());
|
|
}
|
|
setImmediate(done);
|
|
})
|
|
.catch(done);
|
|
}
|
|
|
|
export default {
|
|
setup,
|
|
teardown,
|
|
setupBroadcast,
|
|
createMockRippled,
|
|
};
|