Skip to content

Commit

Permalink
Merge pull request #699 from jpbochi/new-stack-trace
Browse files Browse the repository at this point in the history
produces edited stack that starts with error name
  • Loading branch information
niftylettuce authored Jan 15, 2021
2 parents fe2368b + 0288826 commit 6f3928f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function wrapAssertFn(assertFn) {
var err = assertFn(res);
if (err && err.stack) {
badStack = err.stack.replace(err.message, '').split('\n').slice(1);
err.stack = [err.message, savedStack, '----', badStack].flat().join('\n');
err.stack = [err.toString(), savedStack, '----', badStack].flat().join('\n');
}
return err;
};
Expand Down
49 changes: 27 additions & 22 deletions test/supertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const nock = require('nock');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

function shouldIncludeStackWithThisFile(err) {
err.stack.should.match(/test\/supertest.js:/);
err.stack.should.startWith(err.name + ':');
}

describe('request(url)', function () {
it('should be supported', function (done) {
const app = express();
Expand Down Expand Up @@ -359,7 +364,7 @@ describe('request(app)', function () {
.expect(404)
.end(function (err, res) {
err.message.should.equal('expected 404 "Not Found", got 200 "OK"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -420,7 +425,7 @@ describe('request(app)', function () {
.expect(200, '')
.end(function (err, res) {
err.message.should.equal('expected \'\' response body, got \'foo\'');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -442,7 +447,7 @@ describe('request(app)', function () {
.expect('hey')
.end(function (err, res) {
err.message.should.equal('expected \'hey\' response body, got \'{"foo":"bar"}\'');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -462,7 +467,7 @@ describe('request(app)', function () {
.expect('hey')
.end(function (err, res) {
err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -495,7 +500,7 @@ describe('request(app)', function () {
.expect({ foo: 'baz' })
.end(function (err, res) {
err.message.should.equal('expected { foo: \'baz\' } response body, got { foo: \'bar\' }');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);

request(app)
.get('/')
Expand Down Expand Up @@ -527,7 +532,7 @@ describe('request(app)', function () {
.expect({ stringValue: 'foo', numberValue: 3, nestedObject: { innerString: 5 } })
.end(function (err, res) {
err.message.should.equal('expected {\n stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: 5 }\n} response body, got {\n stringValue: \'foo\',\n numberValue: 3,\n nestedObject: { innerString: \'5\' }\n}'); // eslint-disable-line max-len
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);

request(app)
.get('/')
Expand All @@ -548,7 +553,7 @@ describe('request(app)', function () {
.expect(/^bar/)
.end(function (err, res) {
err.message.should.equal('expected body \'foobar\' to match /^bar/');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -567,7 +572,7 @@ describe('request(app)', function () {
.expect('hey tj')
.end(function (err, res) {
err.message.should.equal("expected 'hey' response body, got 'hey tj'");
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -600,7 +605,7 @@ describe('request(app)', function () {
.expect('Content-Foo', 'bar')
.end(function (err, res) {
err.message.should.equal('expected "Content-Foo" header field');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -618,7 +623,7 @@ describe('request(app)', function () {
.end(function (err, res) {
err.message.should.equal('expected "Content-Type" of "text/html", '
+ 'got "application/json; charset=utf-8"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -650,7 +655,7 @@ describe('request(app)', function () {
.end(function (err) {
err.message.should.equal('expected "Content-Type" matching /^application/, '
+ 'got "text/html; charset=utf-8"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -667,7 +672,7 @@ describe('request(app)', function () {
.expect('Content-Length', 4)
.end(function (err) {
err.message.should.equal('expected "Content-Length" of "4", got "3"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -694,7 +699,7 @@ describe('request(app)', function () {
})
.end(function (err) {
err.message.should.equal('failed');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -720,7 +725,7 @@ describe('request(app)', function () {
})
.end(function (err) {
err.message.should.equal('some descriptive error');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
(err instanceof Error).should.be.true;
done();
});
Expand Down Expand Up @@ -761,7 +766,7 @@ describe('request(app)', function () {
.expect('Content-Type', /json/)
.end(function (err) {
err.message.should.match(/Content-Type/);
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -805,7 +810,7 @@ describe('request(app)', function () {
.end(function (err) {
err.message.should.equal('expected "Content-Type" matching /bloop/, '
+ 'got "text/html; charset=utf-8"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -824,7 +829,7 @@ describe('request(app)', function () {
.end(function (err) {
err.message.should.equal('expected "Content-Type" matching /bloop/, '
+ 'got "text/html; charset=utf-8"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -843,7 +848,7 @@ describe('request(app)', function () {
.end(function (err) {
err.message.should.equal('expected "Content-Type" matching /bloop/, '
+ 'got "text/html; charset=utf-8"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -1002,7 +1007,7 @@ describe('assert ordering by call order', function () {
.end(function (err, res) {
err.message.should.equal('expected \'hey\' response body, '
+ 'got \'{"message":"something went wrong"}\'');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -1022,7 +1027,7 @@ describe('assert ordering by call order', function () {
.expect('hey')
.end(function (err, res) {
err.message.should.equal('expected 200 "OK", got 500 "Internal Server Error"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand All @@ -1043,7 +1048,7 @@ describe('assert ordering by call order', function () {
.end(function (err, res) {
err.message.should.equal('expected "content-type" matching /html/, '
+ 'got "application/json; charset=utf-8"');
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});
});
Expand Down Expand Up @@ -1216,7 +1221,7 @@ describe('request.get(url).query(vals) works as expected', function () {
.end(function (err, res) {
err.should.be.an.instanceof(Error);
err.message.should.match(/Nock: Disallowed net connect/);
err.stack.should.match(/test\/supertest.js:/);
shouldIncludeStackWithThisFile(err);
done();
});

Expand Down

0 comments on commit 6f3928f

Please sign in to comment.