mirror of
https://github.com/embarklabs/web3.js.git
synced 2026-08-30 22:21:10 +00:00
nodejsSet added to FakeXHR2 and httpprovider test cases extended
This commit is contained in:
@@ -7,11 +7,16 @@ var FakeXHR2 = function () {
|
||||
this.readyState = 4;
|
||||
this.onreadystatechange = null;
|
||||
this.async = true;
|
||||
this.agents = {};
|
||||
this.headers = {
|
||||
'Content-Type': 'text/plain'
|
||||
};
|
||||
};
|
||||
|
||||
FakeXHR2.prototype.nodejsSet = function (agents) {
|
||||
this.agents = agents;
|
||||
};
|
||||
|
||||
FakeXHR2.prototype.open = function (method, host, async) {
|
||||
assert.equal(method, 'POST');
|
||||
assert.notEqual(host, null);
|
||||
@@ -33,6 +38,4 @@ FakeXHR2.prototype.send = function (payload) {
|
||||
}
|
||||
};
|
||||
|
||||
FakeXHR2.prototype.nodejsSet = Function.prototype;
|
||||
|
||||
module.exports = {XMLHttpRequest: FakeXHR2};
|
||||
|
||||
+50
-3
@@ -1,5 +1,7 @@
|
||||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var SandboxedModule = require('sandboxed-module');
|
||||
|
||||
SandboxedModule.registerBuiltInSourceTransformer('istanbul');
|
||||
@@ -11,15 +13,60 @@ var HttpProvider = SandboxedModule.require('../packages/web3-providers-http', {
|
||||
singleOnly: true
|
||||
});
|
||||
|
||||
describe('web3-providers-http', function () {
|
||||
describe.only('web3-providers-http', function () {
|
||||
describe('prepareRequest', function () {
|
||||
let provider;
|
||||
let result;
|
||||
let options;
|
||||
let agent;
|
||||
|
||||
it('should set request header', function () {
|
||||
var provider = new HttpProvider('http://localhost:8545', {headers: [{name: 'Access-Control-Allow-Origin', value: '*'}]});
|
||||
var result = provider._prepareRequest();
|
||||
provider = new HttpProvider('http://localhost:8545', {headers: [{name: 'Access-Control-Allow-Origin', value: '*'}]});
|
||||
result = provider._prepareRequest();
|
||||
|
||||
assert.equal(typeof result, 'object');
|
||||
assert.equal(result.headers['Access-Control-Allow-Origin'], '*');
|
||||
});
|
||||
|
||||
it('should use the passed custom http agent', function () {
|
||||
agent = new http.Agent();
|
||||
options = {agent: {http: agent}};
|
||||
provider = new HttpProvider('http://localhost:8545', options);
|
||||
result = provider._prepareRequest();
|
||||
|
||||
assert.equal(typeof result, 'object');
|
||||
assert.equal(result.agents.httpAgent, agent);
|
||||
assert.equal(provider.httpAgent, undefined);
|
||||
assert.equal(provider.httpsAgent, undefined);
|
||||
assert.equal(provider.agent, options.agent);
|
||||
});
|
||||
|
||||
it('should use the passed custom https agent', function () {
|
||||
agent = new https.Agent();
|
||||
options = {agent: {https: agent}};
|
||||
provider = new HttpProvider('http://localhost:8545', options);
|
||||
result = provider._prepareRequest();
|
||||
|
||||
assert.equal(typeof result, 'object');
|
||||
assert.equal(result.agents.httpsAgent, agent);
|
||||
assert.equal(provider.httpAgent, undefined);
|
||||
assert.equal(provider.httpsAgent, undefined);
|
||||
assert.equal(provider.agent, options.agent);
|
||||
});
|
||||
|
||||
it('should use the passed baseUrl', function () {
|
||||
agent = new https.Agent();
|
||||
options = {agent: {https: agent, baseUrl: 'base'}};
|
||||
provider = new HttpProvider('http://localhost:8545', options);
|
||||
result = provider._prepareRequest();
|
||||
|
||||
assert.equal(typeof result, 'object');
|
||||
assert.equal(result.agents.httpsAgent, agent);
|
||||
assert.equal(result.agents.baseUrl, 'base');
|
||||
assert.equal(provider.httpAgent, undefined);
|
||||
assert.equal(provider.httpsAgent, undefined);
|
||||
assert.equal(provider.agent, options.agent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('send', function () {
|
||||
|
||||
Reference in New Issue
Block a user