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

Export each function separately to ease automocking #2288

Merged
merged 3 commits into from
May 1, 2024

Conversation

oxc
Copy link
Contributor

@oxc oxc commented May 1, 2024

Alongside typescript definitions we create a header file that will be imported when someone tries to load the kolmafia typescript library outside of KoLmafia. Each function simply throws an error.

So far, a single function was exported under all function names. This prevents a feature employed by some testing libaries called automocking, where each function is automatically replaced with a mocked version, because all functions then reference the same mock. Instead, export a separate function for each library function, and use named function syntax to ensure the function objects have a name.

Alongside typescript definitions we create a header file that will be
imported when someone tries to load the kolmafia typescript library
outside of KoLmafia. Each function simply throws an error.

So far, a single function was exported under all function names. This
prevents a feature employed by some testing libaries called automocking,
where each function is automatically replaced with a mocked version,
because all functions then reference the same mock.
Instead, export a separate function for each library function, and use
named function syntax to ensure the function objects have a name.
@oxc oxc requested a review from a team as a code owner May 1, 2024 08:31
@gausie gausie enabled auto-merge (squash) May 1, 2024 11:17
@gausie gausie merged commit f4241ad into kolmafia:main May 1, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants