So what we can do now is we can, you know, create a little bit more stuff. So for example, you can create abc-d.js, for example. So in this file here, you see we have created a little bit of a directory structure. And then hello from D. Now if we go here and restart, you can actually see abc-d, oh abc, and then that's d.js. So as you can see, with using Fastify Autoload, we can actually, oh, just, Yay. By using Fastify Autoload, we can open up this file and down to, and load it up from the abc-d direct, from the abc folder.
Okay, so let's move one step forward. Now, what if I want to write a unit test, for example? Let's create a new test.js file. Now, I'm going to use a very simple, a very simple utility that, here we go. A very simple utility that it's actually very, very handy, which is called tape. I am a fan of very easy test tools. So I don't know, I am hopefully you are like that too but if you don't, you can use whatever you want. So I need tape, I need Fastify, and then I will need my app. So note that I'm actually not creating the server but I'm actually loading my apps in a separate way. So what I can do is for example, load the hello world. Well, I can test hello world. So I want to test my hello world function, so I'm using a nothing function here and then I'm using DEEP equal. Here we go. And then we can do create a server, which is my Fastify server and then we can do register. Guess what we are going to do. I'm going to pass App in here, which is our Fastify plugin. So I'm going to put that plugin in then what I need, what we can do now is we can await, we can call our server using our internal testing utility. So we can do await server.inject and slash, which is our route. And then we can do deep equal, res json and then specify the fact that we want hello world. Here we go. So, and then what we need to do, we need to remember to close our server. So we are doing this. Now we can run no test and, oh, where did I put this? Test. Oh, yeah.
Comments