-
Notifications
You must be signed in to change notification settings - Fork 734
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
Further wrangler init
tests (and refactorings)
#124
Further wrangler init
tests (and refactorings)
#124
Conversation
This commit uses jest spies to capture the output from `console` method calls to avoid having to hand code the capturing.
🦋 Changeset detectedLatest commit: 23e29e7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -83,3 +83,9 @@ export async function prompt(text: string, type: "text" | "password" = "text") { | |||
// ): Promise<{ label: string; value: string }>{ | |||
|
|||
// } | |||
|
|||
// Export as an object so that it is easier to mock for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be necessary, but I'll swing by next week and figure out mocking that'll let us keep the original exports. (Dropping this comment here to remind myself)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried a number of different ways to achieve this by "mocking" the module. But it either didn't work or was really messy. I would be interested to see your approach.
`compatibility_date = "${compatibilityDate}"` + "\n" | ||
); | ||
console.log(`✨ Succesfully created wrangler.toml`); | ||
// TODO: suggest next steps? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, this might be a great place to suggest a list of "starters" and automatically make a src
with contents. This may be a good replacement for the generate
command.
* then an error is thrown. | ||
*/ | ||
function mockConfirm(...expectations: { text: string; result: boolean }[]) { | ||
const mockImplementation = async (text: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dope mock, solves the input problem neatly.
Thanks for the quick review (after hours!!) |
021a06c
to
23e29e7
Compare
As mentioned in #124 (comment), it's possible to use regular exports from a module, but still be able to mock their implementations in jest. This PR does so, and passes tests.
* export functions from dialogs.tsx, pass tests As mentioned in #124 (comment), it's possible to use regular exports from a module, but still be able to mock their implementations in jest. This PR does so, and passes tests.
See the individual commits...