Book Image

Deno Web Development

By : Alexandre Portela dos Santos
Book Image

Deno Web Development

By: Alexandre Portela dos Santos

Overview of this book

Deno is a JavaScript and TypeScript runtime with secure defaults and a great developer experience. With Deno Web Development, you'll learn all about Deno's primitives, its principles, and how you can use them to build real-world applications. The book is divided into three main sections: an introduction to Deno, building an API from scratch, and testing and deploying a Deno application. The book starts by getting you up to speed with Deno's runtime and the reason why it was developed. You'll explore some of the concepts introduced by Node, why many of them transitioned into Deno, and why new features were introduced. After understanding Deno and why it was created, you will start to experiment with Deno, exploring the toolchain and writing simple scripts and CLI applications. As you progress to the second section, you will create a simple web application and then add more features to it. This application will evolve from a simple 'hello world' API to a web application connected to the database, with users, authentication, and a JavaScript client. In the third section, the book will take you through topics such as dependency management, configuration and testing, finishing with an application deployed in a cloud environment. By the end of this web development book, you will become comfortable with using Deno to create, maintain, and deploy secure and reliable web applications.
Table of Contents (15 chapters)
1
Section 1: Getting Familiar with Deno
5
Section 2: Building an Application
10
Section 3: Testing and Deploying

Testing the web server

So far, we have learned how to test different parts of the application. We started with the business logic, which tests how it integrated with the modules that interacted with persistency (the repository), but the web layer still has no tests.

It's true that those tests are very important, but we can agree that if the web layer fails, the user will not have access to any of that logic.

That's what we'll do in this section. We'll spin up our web server, mock its dependencies, and make a few requests to it to ensure the web unit is working.

Let's start by creating the web module's unit test by following these steps:

  1. Go to src/web and create a file named web.test.ts.
  2. Now, in order to test the web server, we need to go back to the createServer function in src/web/index.ts and export the Application object it creates in src/web/index.ts:
    const app = new Application();
    …
    return { app };
  3. We also want to be...