solana/web3.js/test/__mocks__/rpc-websockets.js

32 lines
673 B
JavaScript
Raw Normal View History

2020-02-28 17:45:57 +08:00
// @flow
import {Client as LiveClient} from 'rpc-websockets';
2018-10-26 21:37:39 -07:00
2018-11-01 14:41:06 -07:00
// Define TEST_LIVE in the environment to test against the real full node
2018-10-26 21:37:39 -07:00
// identified by `url` instead of using the mock
2018-11-01 14:41:06 -07:00
export const mockRpcEnabled = !process.env.TEST_LIVE;
2018-10-26 21:37:39 -07:00
let mockNotice = true;
class MockClient {
constructor(url: string) {
if (mockNotice) {
console.log(
'Note: rpc-websockets mock is disabled, testing live against',
url,
);
mockNotice = false;
2018-10-26 21:37:39 -07:00
}
}
connect() {}
close() {}
on() {}
call(): Promise<Object> {
2018-10-26 21:37:39 -07:00
throw new Error('call unsupported');
}
}
const Client = mockRpcEnabled ? MockClient : LiveClient;
export {Client};