Loading
Current section: End-to-End Mocking 4 exercises
solution

Communicating Between Processes with File System in Node.js

Loading solution

Transcript

00:00 So first, let's make the utility. We're going to go to our resend mock again, and we're going to export a function called require Email it's going to take an email address So yeah email address that works. We'll call it a string and then oh it looks like I called it recipient We'll use that instead

00:19 And then we just need to grab that file from the file system in the same place So here's our path join the email to over here So that's going to be our recipient and that will get us back our email So here's what const email is that and then let's parse it so that the types are nice, right?

00:38 So we're parsing it with the email schema right here We can reparse it because we're reading it from disk so it could have possibly changed it is it's very possible So then we can return at the result of that and now our require email is nice and ready to

00:55 Let us require some email, so let's go to our onboarding test and Right in here We have this utility wait for which you feel free to dive into that But it's basically just like waiting for whatever callback to not throw an error anymore

01:11 Inspired by a testing library the testing library wait for that. I wrote quite a while ago okay, so let's wait for that require email and We're gonna say onboarding Data dot email we don't have to lowercase. I guess yeah, we should lowercase it right because our

01:32 Application is going to lowercase it before sending the email So yeah lowercase that and then we can return require email We no longer need to cast as any and now that email is going to be exactly what it should be So if we save this and run the test it should work, please Yes

01:50 Past awesome job Kelly an awesome job you we can still take a look at that email And there's that email that we was just created so we're in a good place here so quick review all we did was read the JSON from the file system that was written and then parsed it and then

02:10 our onboarding test so it's separate process so this recent mock is running in process a Over here are with our server and then onboarding test is running a process B with playwright and So we're just waiting for that email to be written and as soon as it is we can require that email By the recipient and then proceed with our test So there you go that is

02:33 Process to process communication via the file system and in the future MSW will actually support process to process communication In a little bit more of a first-class way and it's unclear to me whether that's going to change the way that I Recommend doing this. So just keep an eye on the instructions. I'll update those if

02:53 if there's a Another way to do this That you might be interested in looking at and of course the epic stack will be updated to that as well And eventually if there is like a very much a better way to do this, then I will update this video also So if this video isn't updated then this way is still a great way to do it

03:12 But yeah writing to the file system works out pretty well. So there you go. Well done