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

Designs a new "fsTeardown" API #6

Merged
merged 11 commits into from
Aug 31, 2021
Merged

Designs a new "fsTeardown" API #6

merged 11 commits into from
Aug 31, 2021

Conversation

kettanaito
Copy link
Owner

@kettanaito kettanaito commented Aug 25, 2021

This is a breaking change.

Motivation

  • Allow creating more complex file structures with less API clutter.
  • Support runtime file/directory creation, so that each individual suit could create its own tree structure. The API is designed to be used globally, not in each test.
  • Support resetting the entire mock base directory between tests.

Breaking changes

  • createTeardown is renamed to fsTeardown to be aligned with the package's name.
  • .getPath is renamed to .resolve to be aligned with path.resolve.
  • .addFile was replaced with .create that allows creating files and directories.
  • Adds a new .reset() method that restores the directory to its initial state (paths from the fsTeardown call).

@kettanaito
Copy link
Owner Author

Hey, @nzakas. I'd like to re-design the public API of this library and wanted to ask your opinion on the proposed changes. You can find the updated README on this feature branch. Thank you.

@kettanaito kettanaito mentioned this pull request Aug 25, 2021
Copy link

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

I like it! Nice work.

@kettanaito
Copy link
Owner Author

I wonder if .prepare() is an intuitive method name to instantiate the mocks. My worry is that people will confuse it with .create() that has a similar meaning.

Some alternatives to .prepare():

  • init
  • mock
  • emit
  • write

@nzakas
Copy link

nzakas commented Aug 31, 2021

I think prepare is fine, but if you want to be explicit, you could use writeToDisk.

@kettanaito
Copy link
Owner Author

Agreed. I'll keep .prepare and .create and see whether the usage will suggest some changes. Thank you, Nicholas!

@kettanaito kettanaito merged commit 261bbc9 into master Aug 31, 2021
@kettanaito kettanaito deleted the api-refactoring branch August 31, 2021 13:00
@kettanaito
Copy link
Owner Author

@nzakas, if you need help updating ESLint with these changes just let me know. I may need a quick intro to your custom setup to migrate it efficiently.

@nzakas
Copy link

nzakas commented Sep 1, 2021

We likely won’t update the tests, as they are working fine right now, but if you’d like to try doing it yourself, please feel free.

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