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

Refactor the storage adapter tests to use a beforeEach hook #385

Merged

Conversation

kraenhansen
Copy link
Contributor

To implement tests of a storage which use async APIs, I need the teardown function to be able to return a promise which gets awaited. I also took the liberty to refactor the tests a bit to use a beforeEach hook instead of calling setup and teardown in each of the tests. This ensures the teardown gets called even if the test fails. In the current state, this isn't the case since something throwing in the test could prevent the call to teardown.

@kraenhansen kraenhansen force-pushed the refactored-storage-adapter-tests branch from 62831d3 to bb48906 Compare September 6, 2024 12:40
@kraenhansen
Copy link
Contributor Author

cc @HerbCaudill as it seems you've worked on this file too 👍

@kraenhansen kraenhansen changed the title Refactored the storage adapter tests to use a beforeEach hook Refactor the storage adapter tests to use a beforeEach hook Sep 6, 2024
@HerbCaudill HerbCaudill self-assigned this Sep 20, 2024
adapter: StorageAdapterInterface
}

const it = test<AdapterTestContext>
Copy link
Collaborator

Choose a reason for hiding this comment

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

small nitpick - I'd prefer

import { ..., it as _it } from "vitest"

...

const it = _it<AdapterTestContext>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

@HerbCaudill
Copy link
Collaborator

Hi @kraenhansen. Thanks for working on this, and for introducing me to Vitest's test context API! I've leaned heavily on the setup() pattern to avoid beforeEach + global mutable state, but this is much cleaner.

(For anyone following along, it took me a while to find this in the docs - it's not referenced in the API reference, but it's documented in a standalone guide to Test Context.)

@HerbCaudill HerbCaudill merged commit a052bb5 into automerge:main Sep 21, 2024
4 checks passed
@kraenhansen kraenhansen deleted the refactored-storage-adapter-tests branch September 21, 2024 15:22
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.

2 participants