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

Comprehensive cleanup after each test #1465

Merged
merged 5 commits into from
Feb 24, 2019
Merged

Comprehensive cleanup after each test #1465

merged 5 commits into from
Feb 24, 2019

Conversation

paulmelnikow
Copy link
Member

@paulmelnikow paulmelnikow commented Feb 22, 2019

This adds a global afterEach hook that resets nock global state to the condition it's in when it's initially required. It's worth noting that there isn't a single function for doing this; I've got four function calls here to accomplish that. It's worth taking a moment here to validate that this is indeed the correct sequence of calls. See #1441 for some discussion on that.

It removes most or all of the one-off global-state cleanup code that's sprinkled among the tests.

  • Tests may now assume that, at the time they're invoked, that nock's initial state will match the state it has when it has just been required.
  • Tests are not responsible for restoring that state afterward.
  • If tests need nock in a different starting state, it's up to them to set it.
  • If tests create other state, such as starting a server, it's up to them to clean it up.

I've included some miscellaneous adjacent style cleanup.

I've deferred the various test_back* suites because they are all intertwingled, and require a bit more focused effort to unravel.

@paulmelnikow paulmelnikow changed the title Replace one-off global-state cleanup code with cleanup after each test Replace one-off global-state cleanup code with comprehensive cleanup after each test Feb 22, 2019
@paulmelnikow paulmelnikow changed the title Replace one-off global-state cleanup code with comprehensive cleanup after each test Comprehensive cleanup after each test Feb 22, 2019
Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

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

This is great! Maybe consider calling the file cleanup_after_all.js? It might be more clear than cleanup_hook.js

@paulmelnikow
Copy link
Member Author

Sure. I think I'll use cleanup_after_each.

@nockbot
Copy link
Collaborator

nockbot commented Apr 12, 2019

🎉 This PR is included in version 11.0.0-beta.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nockbot
Copy link
Collaborator

nockbot commented Aug 13, 2019

🎉 This PR is included in version 11.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

gr2m pushed a commit that referenced this pull request Sep 4, 2019
This adds a global `afterEach` hook that resets nock global state to the condition it's in when it's initially `require`d. It's worth noting that there isn't a single function for doing this; I've got four function calls here to accomplish that. It's worth taking a moment here to validate that this is indeed the correct sequence of calls. See #1441 for some discussion on that.

It removes most or all of the one-off global-state cleanup code that's sprinkled among the tests.

- Tests may now assume that, at the time they're invoked, that nock's initial state will match the state it has when it has just been `require`d.
- Tests are not responsible for restoring that state afterward.
- If tests need nock in a _different_ starting state, it's up to them to set it.
- If tests create _other_ state, such as starting a server, it's up to them to clean it up.

I've included some miscellaneous adjacent style cleanup.

I've deferred the various `test_back*` suites because they are all intertwingled, and require a bit more focused effort to unravel.
gr2m pushed a commit that referenced this pull request Sep 4, 2019
This adds a global `afterEach` hook that resets nock global state to the condition it's in when it's initially `require`d. It's worth noting that there isn't a single function for doing this; I've got four function calls here to accomplish that. It's worth taking a moment here to validate that this is indeed the correct sequence of calls. See #1441 for some discussion on that.

It removes most or all of the one-off global-state cleanup code that's sprinkled among the tests.

- Tests may now assume that, at the time they're invoked, that nock's initial state will match the state it has when it has just been `require`d.
- Tests are not responsible for restoring that state afterward.
- If tests need nock in a _different_ starting state, it's up to them to set it.
- If tests create _other_ state, such as starting a server, it's up to them to clean it up.

I've included some miscellaneous adjacent style cleanup.

I've deferred the various `test_back*` suites because they are all intertwingled, and require a bit more focused effort to unravel.
gr2m pushed a commit that referenced this pull request Sep 5, 2019
This adds a global `afterEach` hook that resets nock global state to the condition it's in when it's initially `require`d. It's worth noting that there isn't a single function for doing this; I've got four function calls here to accomplish that. It's worth taking a moment here to validate that this is indeed the correct sequence of calls. See #1441 for some discussion on that.

It removes most or all of the one-off global-state cleanup code that's sprinkled among the tests.

- Tests may now assume that, at the time they're invoked, that nock's initial state will match the state it has when it has just been `require`d.
- Tests are not responsible for restoring that state afterward.
- If tests need nock in a _different_ starting state, it's up to them to set it.
- If tests create _other_ state, such as starting a server, it's up to them to clean it up.

I've included some miscellaneous adjacent style cleanup.

I've deferred the various `test_back*` suites because they are all intertwingled, and require a bit more focused effort to unravel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants