feat: Jest Test Runner (#2170)

This commit is contained in:
justinr1234
2023-02-03 17:03:07 -06:00
committed by GitHub
parent 5a63f18faf
commit 5fe480ece4
229 changed files with 13497 additions and 17033 deletions

View File

@@ -1,26 +1,46 @@
import { Client, Wallet } from 'xrpl-local'
import { Client, Wallet } from '../../src'
import serverUrl from './serverUrl'
import { fundAccount } from './utils'
export async function teardownClient(this: Mocha.Context): Promise<void> {
this.client.removeAllListeners()
this.client.disconnect()
export interface XrplIntegrationTestContext {
client: Client
wallet: Wallet
}
export async function teardownClient(
context: XrplIntegrationTestContext,
): Promise<void> {
context.client.removeAllListeners()
return context.client.disconnect()
}
async function connectWithRetry(client: Client, tries = 0): Promise<void> {
return client.connect().catch(async (error) => {
if (tries < 10) {
return new Promise((resolve) => {
setTimeout(() => {
resolve(connectWithRetry(client, tries + 1))
}, 1000)
})
}
throw error
})
}
export async function setupClient(
this: Mocha.Context,
server = serverUrl,
): Promise<void> {
this.wallet = Wallet.generate()
return new Promise<void>((resolve, reject) => {
this.client = new Client(server)
this.client
.connect()
.then(async () => {
await fundAccount(this.client, this.wallet)
resolve()
})
.catch(reject)
): Promise<XrplIntegrationTestContext> {
const context: XrplIntegrationTestContext = {
client: new Client(server, { timeout: 200000 }),
wallet: Wallet.generate(),
}
return connectWithRetry(context.client).then(async () => {
await fundAccount(context.client, context.wallet, {
count: 20,
delayMs: 1000,
})
return context
})
}