Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ladjs/supertest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.1.0
Choose a base ref
...
head repository: ladjs/supertest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.1.1
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 15, 2021

  1. Copy the full SHA
    0288826 View commit details
  2. Merge pull request #699 from jpbochi/new-stack-trace

    produces edited stack that starts with error name
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    6f3928f View commit details
  3. 6.1.1

    niftylettuce committed Jan 15, 2021
    Copy the full SHA
    abd2f45 View commit details
Showing with 30 additions and 25 deletions.
  1. +1 −1 lib/test.js
  2. +1 −1 package-lock.json
  3. +1 −1 package.json
  4. +27 −22 test/supertest.js
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supertest",
"version": "6.1.0",
"version": "6.1.1",
"description": "SuperAgent driven library for testing HTTP servers",
"main": "index.js",
"author": "TJ Holowaychuk",
49 changes: 27 additions & 22 deletions test/supertest.js
Original file line number Diff line number Diff line change
@@ -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();
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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('/')
@@ -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('/')
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});
});
@@ -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();
});