Add polyfill for WebSocket (node) (#31)

This commit is contained in:
Jaco Greeff
2017-12-03 15:37:56 +01:00
committed by GitHub
parent aa0a231224
commit 53e7f06b03
8 changed files with 57 additions and 8 deletions
+1 -1
View File
@@ -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"
}
}
+3 -2
View File
@@ -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"
}
}
+2
View File
@@ -11,6 +11,8 @@ type WsMessageType = {
data: any
};
require('./polyfill');
const JsonRpcCoder = require('../jsonRpcCoder');
module.exports = class WsProvider extends JsonRpcCoder implements ProviderInterface {
+6
View File
@@ -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();
});
});
+1 -1
View File
@@ -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"
}
}