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.0.1
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.0
Choose a head ref
  • 14 commits
  • 8 files changed
  • 7 contributors

Commits on Jul 28, 2020

  1. docs: update README.md promise usage example

    Update promise usage example to call the `done` function and also add a catch block.
    DominusKelvin authored Jul 28, 2020
    Copy the full SHA
    ebd4c29 View commit details

Commits on Oct 9, 2020

  1. Copy the full SHA
    45dcf6e View commit details

Commits on Oct 11, 2020

  1. Copy the full SHA
    616dfb6 View commit details

Commits on Nov 11, 2020

  1. Adds travis jobs on ppc64le

    dineshks1 committed Nov 11, 2020
    Copy the full SHA
    aec2239 View commit details

Commits on Dec 3, 2020

  1. Copy the full SHA
    d41d10b View commit details

Commits on Jan 15, 2021

  1. Fix inconsistent return

    jackton1 authored Jan 15, 2021
    Copy the full SHA
    848962e View commit details
  2. Merge pull request #698 from jackton1/patch-1

    Fix inconsistent return
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    9b0751c View commit details
  3. Merge pull request #690 from jpbochi/new-stack-trace

    Wraps assert functions, updating stack trace of generated errors
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    4b1fd0c View commit details
  4. Merge pull request #664 from DominusKelvin/patch-1

    docs: update README.md promise usage example
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    77a86ed View commit details
  5. Merge pull request #684 from dineshks1/master

    Adds travis jobs on ppc64le
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    ac23355 View commit details
  6. Merge pull request #679 from julienw/do-not-exact-pin-versions

    Do not exact-pin the dependencies versions
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    a676437 View commit details
  7. Merge pull request #678 from pitpit/bugfix/tests

    fix ssl certificate key too small in tests
    niftylettuce authored Jan 15, 2021
    Copy the full SHA
    f133efb View commit details
  8. chore: bump deps

    niftylettuce committed Jan 15, 2021
    Copy the full SHA
    a292f61 View commit details
  9. 6.1.0

    niftylettuce committed Jan 15, 2021
    Copy the full SHA
    fe2368b View commit details
Showing with 694 additions and 865 deletions.
  1. +3 −0 .travis.yml
  2. +4 −2 README.md
  3. +27 −5 lib/test.js
  4. +585 −821 package-lock.json
  5. +8 −8 package.json
  6. +17 −14 test/fixtures/test_cert.pem
  7. +28 −15 test/fixtures/test_key.pem
  8. +22 −0 test/supertest.js
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
arch:
- amd64
- ppc64le
language: node_js

node_js:
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ describe('POST /users', function() {
.expect(200)
.end(function(err, res) {
if (err) return done(err);
done();
return done();
});
});
});
@@ -110,15 +110,17 @@ You can also use promises:

```js
describe('GET /users', function() {
it('responds with json', function() {
it('responds with json', function(done) {
return request(app)
.get('/users')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.then(response => {
assert(response.body.email, 'foo@bar.com')
done();
})
.catch(err => done(err))
});
});
```
32 changes: 27 additions & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
@@ -64,6 +64,28 @@ Test.prototype.serverAddress = function(app, path) {
return protocol + '://127.0.0.1:' + port + path;
};

/**
* Wraps an assert function into another.
* The wrapper function edit the stack trace of any assertion error, prepending a more useful stack to it.
*
* @param {Function} assertFn
* @returns {Function} wrapped assert function
*/

function wrapAssertFn(assertFn) {
var savedStack = new Error().stack.split('\n').slice(3);

return function(res) {
var badStack;
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');
}
return err;
};
}

/**
* Expectations:
*
@@ -83,30 +105,30 @@ Test.prototype.serverAddress = function(app, path) {
Test.prototype.expect = function(a, b, c) {
// callback
if (typeof a === 'function') {
this._asserts.push(a);
this._asserts.push(wrapAssertFn(a));
return this;
}
if (typeof b === 'function') this.end(b);
if (typeof c === 'function') this.end(c);

// status
if (typeof a === 'number') {
this._asserts.push(this._assertStatus.bind(this, a));
this._asserts.push(wrapAssertFn(this._assertStatus.bind(this, a)));
// body
if (typeof b !== 'function' && arguments.length > 1) {
this._asserts.push(this._assertBody.bind(this, b));
this._asserts.push(wrapAssertFn(this._assertBody.bind(this, b)));
}
return this;
}

// header field
if (typeof b === 'string' || typeof b === 'number' || b instanceof RegExp) {
this._asserts.push(this._assertHeader.bind(this, { name: '' + a, value: b }));
this._asserts.push(wrapAssertFn(this._assertHeader.bind(this, { name: '' + a, value: b })));
return this;
}

// body
this._asserts.push(this._assertBody.bind(this, a));
this._asserts.push(wrapAssertFn(this._assertBody.bind(this, a)));

return this;
};
Loading