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

Server objects seem to be recycled rather than torn down after each test #21

Open
hillct opened this issue Mar 27, 2018 · 2 comments
Open

Comments

@hillct
Copy link

hillct commented Mar 27, 2018

By default, the HTTP server objects need to be undef'd after each test, otherwise you end up with collisions. This can be most easily demonstrated if you setup several tests that expect a 200 response, and several tests that expect other responses. Server instances built to handle test 1 may respond to test 2, etc. Better isolation is required in order to make assure reliability. It appears that the current workaround required that you only ever perform one test using unexpected-express per test file.

@papandreou
Copy link
Member

papandreou commented Mar 27, 2018

Hi @hillct,

I usually wrap unexpected-express in a custom assertion like this so that each test starts with a fresh instance: https://github.com/papandreou/express-processimage/blob/c81b69b4d621a3ad91fb381336ed770305ab500c/test/processImage.js#L32-L41

The exception being cases where I need to test state/caching being built up inside a server instance, eg.: https://github.com/papandreou/express-extractheaders/blob/b8959daca6463ffb045c2d6d7bd08c3eb123dd0a/test/expressExtractHeaders.js#L314-L342

So I guess I agree with the point you're making. Is that what you mean? Would you suggest changing something in the implementation or documentation so as to encourage people to use the library like that?

The documentation site does have an example of using such a custom assertion (http://unexpected.js.org/unexpected-express/#extensive-testing), but it's not explicitly mentioned that it also helps with the test isolation and reliability to do so.

PRs are welcome, as always :)

@hillct
Copy link
Author

hillct commented Mar 27, 2018

Hi @papandreou,
I'm not sure your example case fully address what I'm describing (as far as I can tell). I hesitated in posting this before I had a minimal example to include, which I'll have once I finish up items related to my immediate deadlines. IN the meantime, I'll look over the custom assertion example again to see if I've missed something.

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

No branches or pull requests

2 participants