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: pull side effect out of action bundle import #115

Merged
merged 1 commit into from
Jul 3, 2023
Merged

Conversation

mcous
Copy link
Member

@mcous mcous commented Jul 3, 2023

This PR switches our mocking library from testdouble + testdouble-vitest to vitest-when.

Testdouble is excellent, but we have to jump through some hoops to get it to work nicely with vitest. Switching to vitest-when gives us a very similar stubbing API without the overhead of opting-out of vitest's automocking / mock functions.

To make this change possible, I needed to remove a wart from the action code: prior to this PR, importing the action bundle ran the action. This side-effect on import was difficult to test, and the fact that our tests worked at all for this behavior was more brittle than I realized.

Now, the action bundle exports a main function, and there's a simple action.js at the top-level of the repository that imports and calls that function. This is symmetrical with how the CLI works, with a simple wrapper called bin/npm-publish.js that imports and executes the CLI code from the compiled lib directory.

@mcous mcous merged commit 7ae2800 into main Jul 3, 2023
@mcous mcous deleted the vitest-when branch July 3, 2023 16:13
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.

1 participant