difftreelog
test SilentConsole cls instead of multiple decorations
in: master
4 files changed
tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/index.ts
+++ b/tests/src/eth/util/playgrounds/index.ts
@@ -6,7 +6,7 @@
import config from '../../../config';
import {EthUniqueHelper} from './unique.dev';
-import {SilentLogger} from '../../../util/playgrounds/unique.dev';
+import {SilentLogger, SilentConsole} from '../../../util/playgrounds/unique.dev';
export {EthUniqueHelper} from './unique.dev';
@@ -16,25 +16,9 @@
export const expect = chai.expect;
export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
- // TODO: Remove, this is temporary: Filter unneeded API output
- // (Jaco promised it will be removed in the next version)
- const consoleErr = console.error;
- const consoleLog = console.log;
- const consoleWarn = console.warn;
-
- const outFn = (printer: any) => (...args: any[]) => {
- for (const arg of args) {
- if (typeof arg !== 'string')
- continue;
- if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis: UniqueApi/2, RmrkApi/1') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')
- return;
- }
- printer(...args);
- };
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
- console.error = outFn(consoleErr.bind(console));
- console.log = outFn(consoleLog.bind(console));
- console.warn = outFn(consoleWarn.bind(console));
const helper = new EthUniqueHelper(new SilentLogger());
try {
@@ -47,9 +31,7 @@
finally {
await helper.disconnect();
await helper.disconnectWeb3();
- console.error = consoleErr;
- console.log = consoleLog;
- console.warn = consoleWarn;
+ silentConsole.disable();
}
}
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -25,6 +25,8 @@
import privateKey from './privateKey';
import promisifySubstrate from './promisify-substrate';
+import {SilentConsole} from '../util/playgrounds/unique.dev';
+
function defaultApiOptions(): ApiOptions {
@@ -74,26 +76,9 @@
settings = settings || defaultApiOptions();
const api: ApiPromise = new ApiPromise(settings);
let result: T = null as unknown as T;
-
- // TODO: Remove, this is temporary: Filter unneeded API output
- // (Jaco promised it will be removed in the next version)
- const consoleErr = console.error;
- const consoleLog = console.log;
- const consoleWarn = console.warn;
- const outFn = (printer: any) => (...args: any[]) => {
- for (const arg of args) {
- if (typeof arg !== 'string')
- continue;
- if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
- return;
- }
- printer(...args);
- };
-
- console.error = outFn(consoleErr.bind(console));
- console.log = outFn(consoleLog.bind(console));
- console.warn = outFn(consoleWarn.bind(console));
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
try {
await promisifySubstrate(api, async () => {
@@ -106,9 +91,7 @@
})();
} finally {
await api.disconnect();
- console.error = consoleErr;
- console.log = consoleLog;
- console.warn = consoleWarn;
+ silentConsole.disable();
}
return result as T;
}
tests/src/util/playgrounds/index.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/index.ts
+++ b/tests/src/util/playgrounds/index.ts
@@ -4,37 +4,13 @@
import {IKeyringPair} from '@polkadot/types/types';
import config from '../../config';
import '../../interfaces/augment-api-events';
-import {DevUniqueHelper} from './unique.dev';
+import {DevUniqueHelper, SilentLogger, SilentConsole} from './unique.dev';
-class SilentLogger {
- log(msg: any, level: any): void { }
- level = {
- ERROR: 'ERROR' as const,
- WARNING: 'WARNING' as const,
- INFO: 'INFO' as const,
- };
-}
export const usingPlaygrounds = async (code: (helper: DevUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {
- // TODO: Remove, this is temporary: Filter unneeded API output
- // (Jaco promised it will be removed in the next version)
- const consoleErr = console.error;
- const consoleLog = console.log;
- const consoleWarn = console.warn;
+ const silentConsole = new SilentConsole();
+ silentConsole.enable();
- const outFn = (printer: any) => (...args: any[]) => {
- for (const arg of args) {
- if (typeof arg !== 'string')
- continue;
- if (arg.includes('1000:: Normal connection closure' || arg === 'Normal connection closure'))
- return;
- }
- printer(...args);
- };
-
- console.error = outFn(consoleErr.bind(console));
- console.log = outFn(consoleLog.bind(console));
- console.warn = outFn(consoleWarn.bind(console));
const helper = new DevUniqueHelper(new SilentLogger());
try {
@@ -45,8 +21,6 @@
}
finally {
await helper.disconnect();
- console.error = consoleErr;
- console.log = consoleLog;
- console.warn = consoleWarn;
+ silentConsole.disable();
}
};
\ No newline at end of file
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth5import {UniqueHelper} from './unique';5import {UniqueHelper} from './unique';6import {ApiPromise, WsProvider} from '@polkadot/api';6import {ApiPromise, WsProvider} from '@polkadot/api';7import * as defs from '../../interfaces/definitions';7import * as defs from '../../interfaces/definitions';8import {TSigner} from './types';9import {IKeyringPair} from '@polkadot/types/types';8import {IKeyringPair} from '@polkadot/types/types';91011export class SilentLogger {12 log(msg: any, level: any): void { }13 level = {14 ERROR: 'ERROR' as const,15 WARNING: 'WARNING' as const,16 INFO: 'INFO' as const,17 };18}192021export class SilentConsole {22 // TODO: Remove, this is temporary: Filter unneeded API output23 // (Jaco promised it will be removed in the next version)24 consoleErr: any;25 consoleLog: any;26 consoleWarn: any;2728 constructor() {29 this.consoleErr = console.error;30 this.consoleLog = console.log;31 this.consoleWarn = console.warn;32 }3334 enable() { 35 const outFn = (printer: any) => (...args: any[]) => {36 for (const arg of args) {37 for (const arg of args) {38 if (typeof arg !== 'string')39 continue;40 if (arg.includes('1000:: Normal connection closure') || arg.includes('Not decorating unknown runtime apis: UniqueApi/2, RmrkApi/1') || arg.includes('RPC methods not decorated:') || arg === 'Normal connection closure')41 return;42 }43 }44 printer(...args);45 };46 47 console.error = outFn(this.consoleErr.bind(console));48 console.log = outFn(this.consoleLog.bind(console));49 console.warn = outFn(this.consoleWarn.bind(console));50 }5152 disable() {53 console.error = this.consoleErr;54 console.log = this.consoleLog;55 console.warn = this.consoleWarn;56 }57}1058115912export class DevUniqueHelper extends UniqueHelper {60export class DevUniqueHelper extends UniqueHelper {