Skip to content

Commit 08cecb5

Browse files
authored
Remove unused coveralls, replace request with Axios in tests (#1250)
1 parent f5b909c commit 08cecb5

8 files changed

+250
-985
lines changed

package-lock.json

Lines changed: 0 additions & 759 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"@types/whatwg-mimetype": "^3.0.2",
5757
"body-parser": "^1.20.2",
5858
"colors": "^1.4.0",
59-
"coveralls": "^3.1.1",
6059
"diff": "^5.2.0",
6160
"doctoc": "^2.2.1",
6261
"duplexer": "~0.1.2",

test/express-server-test.js

Lines changed: 58 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use strict';
22

3-
var request = require('request');
43
var assert = require('assert');
54
var express = require('express');
65
var bodyParser = require('body-parser');
76
var soap = require('../');
7+
const axios = require('axios');
88
var expressServer;
99
var server;
1010
var port;
@@ -57,37 +57,36 @@ describe('Express server without middleware', function () {
5757
});
5858

5959
it('should handle body without middleware', function (done) {
60-
request({
61-
url: url + '/SayHello',
62-
method: 'POST',
63-
headers: {
64-
SOAPAction: "sayHello",
65-
"Content-Type": 'text/xml; charset="utf-8"'
66-
},
67-
body: requestXML
68-
}, function (err, response, body) {
69-
if (err) {
60+
axios.post(
61+
url + '/SayHello',
62+
requestXML,
63+
{
64+
headers: {
65+
SOAPAction: "sayHello",
66+
"Content-Type": 'text/xml; charset="utf-8"'
67+
},
68+
}).then(res => {
69+
assert.equal(res.data, responseXML);
70+
done();
71+
}).catch(err => {
7072
throw err;
71-
}
72-
assert.equal(body, responseXML);
73-
done();
74-
});
73+
})
7574
});
7675

7776
it('should serve wsdl', function (done) {
78-
request({
79-
url: url + '/SayHello?wsdl',
80-
method: 'GET',
81-
headers: {
82-
"Content-Type": 'text/xml; charset="utf-8"'
77+
axios.get(
78+
url + '/SayHello?wsdl',
79+
{
80+
headers: {
81+
"Content-Type": 'text/xml; charset="utf-8"'
82+
}
8383
}
84-
}, function (err, response, body) {
85-
if (err) {
84+
).then(res => {
85+
assert.equal(res.data, wsdl);
86+
done();
87+
}).catch(err => {
8688
throw err;
87-
}
88-
assert.equal(body, wsdl);
89-
done();
90-
});
89+
});
9190
});
9291

9392
it('should handle other routes as usual', function (done) {
@@ -98,16 +97,13 @@ describe('Express server without middleware', function () {
9897
return res.status(200).send('test passed');
9998
});
10099

101-
request({
102-
url: url + '/test/r1',
103-
method: 'GET'
104-
}, function (err, response, body) {
105-
if (err) {
100+
axios.get(
101+
url + '/test/r1').then(res => {
102+
assert.equal(res.data, 'test passed');
103+
done();
104+
}).catch(err => {
106105
throw err;
107-
}
108-
assert.equal(body, 'test passed');
109-
done();
110-
});
106+
});
111107
});
112108

113109
});
@@ -148,21 +144,20 @@ describe('Express server with middleware', function () {
148144
});
149145

150146
it('should allow parsing body via express middleware', function (done) {
151-
request({
152-
url: url + '/SayHello',
153-
method: 'POST',
154-
headers: {
155-
SOAPAction: "sayHello",
156-
"Content-Type": 'text/xml; charset="utf-8"'
157-
},
158-
body: requestXML
159-
}, function (err, response, body) {
160-
if (err) {
161-
throw err;
162-
}
163-
assert.equal(body, responseXML);
164-
done();
165-
});
147+
axios.post(
148+
url + '/SayHello',
149+
requestXML,
150+
{
151+
headers: {
152+
SOAPAction: "sayHello",
153+
"Content-Type": 'text/xml; charset="utf-8"'
154+
},
155+
}).then(res => {
156+
assert.equal(res.data, responseXML);
157+
done();
158+
}).catch(err => {
159+
throw err
160+
});
166161
});
167162

168163
});
@@ -204,20 +199,19 @@ describe('Express server with bodyParser.json middleware', function () {
204199
});
205200

206201
it('should not parse body on bodyParser.json middleware', function (done) {
207-
request({
208-
url: url + '/SayHello',
209-
method: 'POST',
210-
headers: {
211-
SOAPAction: "sayHello",
212-
"Content-Type": 'text/xml; charset="utf-8"'
213-
},
214-
body: requestXML
215-
}, function (err, response, body) {
216-
if (err) {
202+
axios.post(
203+
url + '/SayHello',
204+
requestXML,
205+
{
206+
headers: {
207+
SOAPAction: "sayHello",
208+
"Content-Type": 'text/xml; charset="utf-8"'
209+
},
210+
}).then(res => {
211+
assert.equal(res.data, responseXML);
212+
done();
213+
}).catch(err => {
217214
throw err;
218-
}
219-
assert.equal(body, responseXML);
220-
done();
221-
});
215+
});
222216
});
223217
});

test/request-no-envelope-body-test.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
'use strict';
22

3-
var request = require('request');
43
var assert = require('assert');
54
var http = require('http');
65
var soap = require('../');
6+
const { default: axios } = require('axios');
77
var server;
88
var port;
99

10-
describe('No envelope and body elements', function() {
10+
describe('No envelope and body elements', function () {
1111
var wsdl = '<definitions name="HelloService" targetNamespace="http://www.examples.com/wsdl/HelloService.wsdl" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.examples.com/wsdl/HelloService.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><message name="SayHelloRequest"><part name="firstName" type="xsd:string"/></message><message name="SayHelloResponse"><part name="greeting" type="xsd:string"/></message><portType name="Hello_PortType"><operation name="sayHello"><input message="tns:SayHelloRequest"/><output message="tns:SayHelloResponse"/></operation></portType><binding name="Hello_Binding" type="tns:Hello_PortType"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="sayHello"><soap:operation soapAction="sayHello"/><input><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded"/></input><output><soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:examples:helloservice" use="encoded"/></output></operation></binding><service name="Hello_Service"><documentation>WSDL File for HelloService</documentation><port binding="tns:Hello_Binding" name="Hello_Port"><soap:address location="http://localhost:51515/SayHello/" /></port></service></definitions>';
12-
before(function(done){
13-
server = http.createServer(function(req, res) {
12+
before(function (done) {
13+
server = http.createServer(function (req, res) {
1414
res.statusCode = 404;
1515
res.end();
16-
}).listen(51515, function() {
16+
}).listen(51515, function () {
1717
var soapServer = soap.listen(server, '/SayHello', {
1818
Hello_Service: {
1919
Hello_Port: {
20-
sayHello: function(args){
20+
sayHello: function (args) {
2121
return {
2222
greeting: args.firstName
2323
};
@@ -29,12 +29,12 @@ describe('No envelope and body elements', function() {
2929
});
3030
});
3131

32-
after(function(){
32+
after(function () {
3333
server.close();
3434
});
3535

3636
it('should throw an error when Body and Envelope are missing',
37-
function(done){
37+
function (done) {
3838
var requestXML = '<sayHello xmlns="http://www.examples.com/wsdl/HelloService.wsdl"><firstName>tarun</firstName></sayHello>';
3939
var url = 'http://' + server.address().address + ':' + server.address().port;
4040

@@ -43,19 +43,20 @@ describe('No envelope and body elements', function() {
4343
'http://127.0.0.1:' + server.address().port;
4444
}
4545

46-
request({
47-
url: url + '/SayHello',
48-
method: 'POST',
49-
headers: {SOAPAction: "sayHello",
50-
"Content-Type": 'text/xml; charset="utf-8"'},
51-
body: requestXML
52-
}, function(err, response, body){
53-
if(err){
54-
throw err;
55-
}
56-
assert.equal(body.indexOf('Failed to parse the SOAP Message body') !== -1, true);
57-
done();
58-
});
46+
axios.post(
47+
url + '/SayHello',
48+
requestXML,
49+
{
50+
headers: {
51+
SOAPAction: "sayHello",
52+
"Content-Type": 'text/xml; charset="utf-8"'
53+
},
54+
}).then(res => {
55+
throw new Error(`Request must fail`);
56+
}).catch(err => {
57+
assert.equal(err?.response?.data.indexOf('Failed to parse the SOAP Message body') !== -1, true);
58+
done();
59+
});
5960
});
6061

6162
});

test/response-preserve-whitespace-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var request = require('request');
43
var assert = require('assert');
54
var http = require('http');
65
var soap = require('../');

0 commit comments

Comments
 (0)