Lints top-level test files (#1594)

* lint broadcastClient

* lint client

* fix most of connection

* remove unused files

* lint mockRippled

* lint mockRippledTest

* lint runClientTests

* lint setupClient

* lint setupClientWeb

* lint shamap

* lint testUtils

* resolve tsc issues

* Fix tests

* lint rest of connection

* respond to comments
This commit is contained in:
Mayukha Vadari
2021-09-07 14:25:39 -05:00
parent c8a2a6690b
commit 949cc031ee
44 changed files with 342 additions and 402 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable mocha/no-setup-in-describe -- Necessary to programmatically generate tests */
import fs from 'fs'
import path from 'path'
@@ -9,18 +10,23 @@ import { Client } from 'xrpl-local'
* Throws errors when we detect the absence of tests.
* Puts all the client methods under one "describe" umbrella.
*/
describe('Client [Test Runner]', function () {
describe('Client', function () {
// doesn't need a functional client, just needs to instantiate to get a list of public methods
// (to determine what methods are missing from )
const allPublicMethods = getAllPublicMethods(new Client('wss://'))
const allTestSuites = loadTestSuites()
// Report any missing tests.
const allTestedMethods = new Set(allTestSuites.map((s) => s.name))
const allTestedMethods = new Set(
allTestSuites.map((testsuite) => testsuite.name),
)
for (const methodName of allPublicMethods) {
if (!allTestedMethods.has(methodName)) {
// TODO: Once migration is complete, remove `.skip()` so that missing tests are reported as failures.
// eslint-disable-next-line mocha/no-skipped-tests -- See above TODO
it.skip(`${methodName} - no test suite found`, function () {
throw new Error(
`Test file not found! Create file "test/client/${methodName}.ts".`,
@@ -30,13 +36,14 @@ describe('Client [Test Runner]', function () {
}
})
function getAllPublicMethods(client: Client) {
function getAllPublicMethods(client: Client): string[] {
return Array.from(
new Set([
...Object.getOwnPropertyNames(client),
...Object.getOwnPropertyNames(Client.prototype),
]),
).filter((key) => !key.startsWith('_')) // removes private methods
// removes private methods
).filter((key) => !key.startsWith('_'))
}
/**
@@ -51,18 +58,24 @@ interface LoadedTestSuite {
}
function loadTestSuites(): LoadedTestSuite[] {
const allTests: any[] = fs.readdirSync(path.join(__dirname, 'client'), {
// eslint-disable-next-line node/no-sync -- Necessary for file processing
const allTests = fs.readdirSync(path.join(__dirname, 'client'), {
encoding: 'utf8',
})
return allTests
.map((methodName) => {
if (methodName.startsWith('.DS_Store')) {
.map((filename) => {
if (filename.startsWith('.DS_Store')) {
return null
}
if (methodName.endsWith('.ts')) {
methodName = methodName.slice(0, -3)
let methodName: string
if (filename.endsWith('.ts')) {
methodName = filename.slice(0, -3)
} else {
methodName = filename
}
const testSuite = require(`./client/${methodName}`)
// eslint-disable-next-line max-len -- Many errors to disable
// eslint-disable-next-line @typescript-eslint/no-var-requires, node/global-require, global-require, @typescript-eslint/no-require-imports, import/no-dynamic-require -- Necessary for client tests
const testSuite = require(path.join(__dirname, 'client', filename))
return {
name: methodName,
config: testSuite.config || {},