Add polyfill for WebSocket (node) (#31)
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
"@polkadot/api-jsonrpc": "^0.5.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.6.6",
|
||||
"@polkadot/util": "^0.6.7",
|
||||
"babel-runtime": "^6.26.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,9 @@
|
||||
"nock": "^9.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/util": "^0.6.6",
|
||||
"@polkadot/util": "^0.6.7",
|
||||
"babel-runtime": "^6.26.0",
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"ws": "^3.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ type WsMessageType = {
|
||||
data: any
|
||||
};
|
||||
|
||||
require('./polyfill');
|
||||
|
||||
const JsonRpcCoder = require('../jsonRpcCoder');
|
||||
|
||||
module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterface {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
// @flow
|
||||
|
||||
if (typeof WebSocket === 'undefined') {
|
||||
global.WebSocket = require('ws');
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// ISC, Copyright 2017 Jaco Greeff
|
||||
|
||||
describe('ws/polyfill', () => {
|
||||
let origWs;
|
||||
|
||||
beforeEach(() => {
|
||||
origWs = global.WebSocket;
|
||||
global.fetch = null;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.WebSocket = origWs;
|
||||
});
|
||||
|
||||
it('polyfills with no exceptions (without WebSocket)', () => {
|
||||
expect(require('./polyfill')).toBeDefined();
|
||||
});
|
||||
|
||||
it('polyfills with no exceptions (with WebSocket)', () => {
|
||||
global.WebSocket = () => true;
|
||||
|
||||
expect(require('./polyfill')).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -33,7 +33,7 @@
|
||||
"@polkadot/api-format": "^0.5.11",
|
||||
"@polkadot/api-jsonrpc": "^0.5.11",
|
||||
"@polkadot/api-provider": "^0.5.11",
|
||||
"@polkadot/util": "^0.6.6",
|
||||
"@polkadot/util": "^0.6.7",
|
||||
"babel-runtime": "^6.26.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user