Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wraps assert functions, updating stack trace of generated errors #690

Merged
merged 1 commit into from Jan 15, 2021

Conversation

jpbochi
Copy link
Contributor

@jpbochi jpbochi commented Dec 3, 2020

Should solve #317

The stack trace of assertion errors created by supertest doesn't refer back to the point where .expect(…) call was made. The trick done here saves the stack of when .expect(…) was called, and inserts that back into the .stack of any possible assertion Error created later.

Example:

I created a file name supertest-test.js with the following content:

const supertest = require('.');

supertest('https://httpbin.org')
  .get('/status/418')
  .expect(200)
  .end(function(err) {
    if (err) console.log(err);
  });

When running node ./supertest-test.js, this was the output:

expected 200 "OK", got 418 "I'm a Teapot"
    at Object.<anonymous> (/Users/jp/src/foss/supertest/supertest-test.js:5:4)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
----
    at Test._assertStatus (/Users/jp/src/foss/supertest/lib/test.js:292:12)
    at /Users/jp/src/foss/supertest/lib/test.js:80:15
    at Test._assertFunction (/Users/jp/src/foss/supertest/lib/test.js:307:11)
    at Test.assert (/Users/jp/src/foss/supertest/lib/test.js:197:21)
    at localAssert (/Users/jp/src/foss/supertest/lib/test.js:155:12)
    at /Users/jp/src/foss/supertest/lib/test.js:152:5
    at Test.Request.callback (/Users/jp/src/foss/supertest/node_modules/superagent/lib/node/index.js:905:3)
    at IncomingMessage.<anonymous> (/Users/jp/src/foss/supertest/node_modules/superagent/lib/node/index.js:1127:20)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)

The content referred by …/supertest-test.js:5:4 is exactly the call to .expect(200).

@coveralls
Copy link

Pull Request Test Coverage Report for Build 470

  • 12 of 12 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 97.447%

Totals Coverage Status
Change from base Build 467: 0.1%
Covered Lines: 146
Relevant Lines: 150

💛 - Coveralls

Copy link

@chrisjmason chrisjmason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@jpbochi
Copy link
Contributor Author

jpbochi commented Jan 15, 2021

I'm so sorry to bother you, but I waited 6 weeks already. Can we get some love here, please? @rimiti

@niftylettuce niftylettuce merged commit 4b1fd0c into ladjs:master Jan 15, 2021
@niftylettuce
Copy link
Collaborator

v6.1.0 released to npm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants