Cannot exit process automatically using supertest
See original GitHub issueDo you want to request a feature or report a bug?
A bug.
What is the current behavior?
The process doesn’t exit after running all test suites.
Use the code below:
const request = require('supertest');
describe('GET /stars', () => {
it('respond with json', (done) => {
const app = require('http').createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end('{ "stars": 1989 }');
});
request(app.listen())
.get('/stars')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
if (err) done(err);
expect(res.body).toEqual({ stars: 1989 });
done();
});
});
});
What is the expected behavior?
The process should exit automatically.
Please provide your exact Jest configuration
// package.json
{
...,
"jest": {
"bail": true
},
...
}
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.3
CPU: x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Binaries:
Node: 8.10.0
Yarn: Not Found
npm: 5.7.1
npmPackages:
jest:
wanted: ^22.4.2
installed: 22.4.2
Actually, jest@^20.0.0
cannot work (I had tried that).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:16
Top Results From Across the Web
Jest did not exit one second after the test run has completed ...
Since start.js isn't imported, the server doesn't need to be closed, Supertest request(app) sets up a server and closes it automatically.
Read more >A step-by-step intro to end-point testing - freeCodeCamp
I've been playing around with testing lately. One thing I tried to do was to test the endpoints of my Express application.
Read more >Supertest: How to Test APIs Like a Pro - Testim Blog
SuperTest is a Node.js testing library for HTTP APIs. Get step-by-step instructions for creating your first API test here!
Read more >Fullstack part4 | Testing the backend
The test imports the Express application from the app.js module and wraps it with the supertest function into a so-called superagent object.
Read more >API testing using SuperTest | HackerNoon
json() method. Then expect(200) is to check the returned status code is equal to 200. Then we end the test by calling done...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same for me, when using
request(app)
with a valid test case but only one Jest test file, I get the Jest did not exit one second after the test run has completed.Otherwise, when adding an empty test in another file, it completes normally.
With this test:
Without:
@SimenB can you re-open this issue, as this may be related to Jest?
I found a strange behavior of Jest about this problem. If there is only one test file, such as
index.spec.js
, the jest will not exit ifapp.listen()
is called. But if there are multiple test files, it will exit as expected.