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

Add support for Express apps #11

Closed
brunogirin opened this issue Sep 29, 2021 · 3 comments
Closed

Add support for Express apps #11

brunogirin opened this issue Sep 29, 2021 · 3 comments
Labels
wontfix This will not be worked on

Comments

@brunogirin
Copy link

In order to make the API more closely aligned with supertest, add support for the Express apps. supertest makes it possible to write:

await request(app).get(...)

When doing this, supertest starts the server before running the tests and closes it at the end. superwstest currently requires this to be done externally in beforeEach and afterAll blocks. Mimicking what supertest does would make it easier for people who come from supertest to pick up superwstest.

@davidje13
Copy link
Owner

I recall looking in to this back when I was writing the library, and in the end decided the more explicit form is safer. If I recall correctly, supertest itself has a subtle bug if you pass an express app in and rely on it starting & stopping the server for you (I'll see if I can find the issue for it. Vaguely remember something about a race condition causing tests to occasionally fail…)

@davidje13
Copy link
Owner

Ah; found it (easy to find because I raised it!): ladjs/supertest#566

See also the linked issues for that; at least at the time (and maybe still?), supertest never closed servers started this way, so as your tests run you will gradually build up more and more servers listening on different ports! It's a pity that style is the one they push in the readme because it's really quite problematic!

@davidje13
Copy link
Owner

I added a section to the readme to explain this decision in detail and updated the error thrown by the library to include a link to it.

So for now I'm going to close this as won't-fix. I think at the very least, adding this feature would depend on ladjs/supertest#566 being fixed first, but even with that fixed, it would need to be possible to reliably know when the test has finished to avoid leaving the test runner hanging (requiring the user to add an afterEach for this would presumably be no better than the current situation).

Feel free to re-open if you have any suggestions on how to support this safely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants