Skip to content

Commit

Permalink
Use assert.ifError function in tests (#976)
Browse files Browse the repository at this point in the history
All instances of `assert.ok(!err)` were replaced with `assert.ifError(err);`,
which provides better output when errors are encountered during testruns.
The former would only output the less-than-useful message,
"Uncaught AssertionError [ERR_ASSERTION]: false == true", while the latter
would output the actual error object that caused the assert to fail.
  • Loading branch information
atavakoli authored and herom committed Oct 3, 2017
1 parent 9399cad commit c94cc1c
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 93 deletions.
2 changes: 1 addition & 1 deletion test/client-customHttp-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ it('should allow customization of httpClient and the wsdl file download should p
{httpClient: httpCustomClient},
function(err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);
assert.equal(client.httpClient, httpCustomClient);
var description = (client.describe());
assert.deepEqual(client.describe(), {
Expand Down
2 changes: 1 addition & 1 deletion test/client-customHttp-xsdinclude-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ it('should allow customization of httpClient, the wsdl file, and associated data
{httpClient: httpCustomClient},
function(err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);
assert.equal(client.httpClient, httpCustomClient);
var description = (client.describe());
assert.deepEqual(client.describe(), {
Expand Down
2 changes: 1 addition & 1 deletion test/client-options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('SOAP Client', function() {
it('should set WSDL options to those specified in createClient', function(done) {
soap.createClient(__dirname+'/wsdl/json_response.wsdl', options, function(err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

assert.ok(client.wsdl.options.ignoredNamespaces[0] === 'ignoreThisNS');
assert.ok(client.wsdl.options.overrideRootElement.namespace === 'tns');
Expand Down
60 changes: 30 additions & 30 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var fs = require('fs'),
var called = false;
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);
called = true;
done();
});
Expand All @@ -62,7 +62,7 @@ var fs = require('fs'),
_.assign({ httpClient: myHttpClient }, meta.options),
function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);
assert.equal(client.httpClient, myHttpClient);
done();
});
Expand All @@ -75,7 +75,7 @@ var fs = require('fs'),
_.assign({ request: myRequest }, meta.options),
function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);
assert.equal(client.httpClient._request, myRequest);
done();
});
Expand All @@ -85,7 +85,7 @@ var fs = require('fs'),
it('should allow customization of envelope', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.notEqual(client.lastRequest.indexOf('xmlns:soapenv='), -1);
Expand All @@ -98,7 +98,7 @@ var fs = require('fs'),
it('should allow passing in XML strings', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', _.assign({ envelopeKey: 'soapenv' }, meta.options), function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

var xmlStr = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<title>404 - Not Found</title>\n\t</head>\n\t<body>\n\t\t<h1>404 - Not Found</h1>\n\t\t<script type="text/javascript" src="http://gp1.wpc.edgecastcdn.net/00222B/beluga/pilot_rtm/beluga_beacon.js"></script>\n\t</body>\n</html>';
client.MyOperation({_xml: xmlStr}, function (err, result, raw, soapHeader) {
Expand All @@ -112,7 +112,7 @@ var fs = require('fs'),
it('should set binding style to "document" by default if not explicitly set in WSDL, per SOAP spec', function (done) {
soap.createClient(__dirname + '/wsdl/binding_document.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

assert.ok(client.wsdl.definitions.bindings.mySoapBinding.style === 'document');
done();
Expand Down Expand Up @@ -163,7 +163,7 @@ var fs = require('fs'),
it('should append `:' + port + '` to the Host header on for a request to a service on that port', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.notEqual(client.lastRequestHeaders.Host.indexOf(':' + port), -1);
Expand All @@ -176,7 +176,7 @@ var fs = require('fs'),
it('should not append `:80` to the Host header on for a request to a service without a port explicitly defined', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.equal(client.lastRequestHeaders.Host.indexOf(':80'), -1);
Expand All @@ -189,7 +189,7 @@ var fs = require('fs'),
it('should not append `:443` to the Host header if endpoints runs on `https`', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function () {
assert.equal(client.lastRequestHeaders.Host.indexOf(':443'), -1);
Expand All @@ -201,7 +201,7 @@ var fs = require('fs'),
it('should append a port to the Host header if explicitly defined', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function () {
assert.ok(client.lastRequestHeaders.Host.indexOf(':443') > -1);
Expand All @@ -214,7 +214,7 @@ var fs = require('fs'),
it('should have xml request modified', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function(err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function(err, result) {
assert.ok(result);
Expand All @@ -234,7 +234,7 @@ var fs = require('fs'),
it('should have the correct extra header in the request', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
Expand All @@ -249,7 +249,7 @@ var fs = require('fs'),
it('should have the wrong extra header in the request', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
Expand All @@ -264,7 +264,7 @@ var fs = require('fs'),
it('should have lastResponse and lastResponseHeaders after the call', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
Expand All @@ -279,7 +279,7 @@ var fs = require('fs'),
it('should have lastElapsedTime after a call with the time option passed', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
Expand All @@ -295,7 +295,7 @@ var fs = require('fs'),
it('should add http headers in method call options', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
Expand All @@ -310,11 +310,11 @@ var fs = require('fs'),
it('should not return error in the call and return the json in body', function (done) {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result, body) {
assert.ok(result);
assert.ok(!err);
assert.ifError(err);
assert.ok(body);
done();
}, null, { "test-header": 'test' });
Expand All @@ -324,7 +324,7 @@ var fs = require('fs'),
it('should add proper headers for soap12', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace_soap12.wsdl', _.assign({ forceSoap12Headers: true }, meta.options), function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
Expand All @@ -341,10 +341,10 @@ var fs = require('fs'),
it('should allow calling the method with args, callback, options and extra headers', function (done) {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result, body) {
assert.ok(!err);
assert.ifError(err);
assert.ok(result);
assert.ok(body.tempResponse === 'temp');
assert.ok(client.lastResponseHeaders.status === 'pass');
Expand All @@ -358,10 +358,10 @@ var fs = require('fs'),
it('should allow calling the method with only a callback', function (done) {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation(function (err, result, body) {
assert.ok(!err);
assert.ifError(err);
assert.ok(result);
assert.ok(body.tempResponse === 'temp');
assert.ok(client.lastResponseHeaders.status === 'fail');
Expand All @@ -374,10 +374,10 @@ var fs = require('fs'),
it('should allow calling the method with args, options and callback last', function (done) {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, { headers: { 'options-test-header': 'test' } }, function (err, result, body) {
assert.ok(!err);
assert.ifError(err);
assert.ok(result);
assert.ok(body.tempResponse === 'temp');
assert.ok(client.lastResponseHeaders.status === 'fail');
Expand All @@ -391,10 +391,10 @@ var fs = require('fs'),
it('should allow calling the method with args, options, extra headers and callback last', function (done) {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, { headers: { 'options-test-header': 'test' } }, { 'test-header': 'test' }, function (err, result, body) {
assert.ok(!err);
assert.ifError(err);
assert.ok(result);
assert.ok(body.tempResponse === 'temp');
assert.ok(client.lastResponseHeaders.status === 'pass');
Expand Down Expand Up @@ -800,7 +800,7 @@ var fs = require('fs'),
}).listen(port, hostname, function () {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result, body) {
server.close();
Expand Down Expand Up @@ -829,12 +829,12 @@ var fs = require('fs'),
}).listen(port, hostname, function () {
soap.createClient(__dirname + '/wsdl/empty_body.wsdl', meta.options, function (err, client) {
assert.ok(client);
assert.ok(!err);
assert.ifError(err);

client.MyOperation({}, function (err, result, body, responseSoapHeaders) {
server.close();
server = null;
assert.ok(!err);
assert.ifError(err);
assert.ok(!responseSoapHeaders);
assert.ok(result);
assert.ok(body);
Expand Down
20 changes: 10 additions & 10 deletions test/server-options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ test.service = {
describe('SOAP Server with Options', function() {
before(function(done) {
fs.readFile(__dirname + '/wsdl/strict/stockquote.wsdl', 'utf8', function(err, data) {
assert.ok(!err);
assert.ifError(err);
test.wsdl = data;
done();
});
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('SOAP Server with Options', function() {
}
// console.log(test.baseUrl);
request(test.baseUrl, function(err, res, body) {
assert.ok(!err);
assert.ifError(err);
console.log(body);
done();
});
Expand All @@ -148,7 +148,7 @@ describe('SOAP Server with Options', function() {
'http://127.0.0.1:' + test.server.address().port;
}
request(test.baseUrl, function(err, res, body) {
assert.ok(!err);
assert.ifError(err);
console.log(body);
done();
});
Expand All @@ -175,9 +175,9 @@ describe('SOAP Server with Options', function() {
}

soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ok(!err);
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'xml response' }, function(err, response, body) {
assert.ok(!err);
assert.ifError(err);
assert.strictEqual(body, responseData);
done();
});
Expand All @@ -204,9 +204,9 @@ describe('SOAP Server with Options', function() {
}

soap.createClient(test.baseUrl + '/stockquote?wsdl', function(err, client) {
assert.ok(!err);
assert.ifError(err);
client.GetLastTradePrice({ tickerSymbol: 'xml response' }, function(err, response, body) {
assert.ok(!err);
assert.ifError(err);
assert.strictEqual(body, responseData);
done();
});
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('SOAP Server with Options', function() {
'</soapenv:Envelope>',
headers: {'Content-Type': 'text/xml'}
}, function(err, res, body) {
assert.ok(!err);
assert.ifError(err);
assert.equal(res.statusCode, 500);
assert.ok(body.indexOf('\n at') !== -1);
done();
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('SOAP Server with Options', function() {
'</soapenv:Envelope>',
headers: {'Content-Type': 'text/xml'}
}, function(err, res, body) {
assert.ok(!err);
assert.ifError(err);
assert.equal(res.statusCode, 500);
assert.equal(body.indexOf('\n at'), -1);
done();
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('SOAP Server with Options', function() {
'</soapenv:Envelope>',
headers: {'Content-Type': 'text/xml'}
}, function(err, res, body) {
assert.ok(!err);
assert.ifError(err);
assert.equal(res.statusCode, 500);
assert.ok(body.match(/<faultcode>.*<\/faultcode>/g),
"Invalid XML");
Expand Down
Loading

0 comments on commit c94cc1c

Please sign in to comment.