This repository contains the source code for the Advanced TypeScript breakout session at DevNexus 2017.
The repository is organized into steps for transitioning a Node.js application from vanilla JavaScript to TypeScript with Mocha unit tests. Finally, dependency injection is added to the project to facilitate alternating repositories.
Each folder contains the previous step's completed code. In other words, the code in each folder is what your code should look like once the necessary changes from the previous step have been made. For example, the Step 2
folder contains all of the code changes outlined in Step 1
(Step 2
is a completed version of Step 1's
instructions).
The objective(s) of each folder are outlined below.
The starter folder contains a basic Node.js express server that serves a simple Angular 2 application. The Angular 2 application queries data from an API exposed by the Node.js application; the data returned by the API is hard-coded. The objective of this folder is to simply get familiar with the application.
In this step, we add unit tests to the express application to begin our server-side testing.
The purpose of this step is to add Mocha unit tests to the Node.js API and the data repository.
Before we begin our conversion from JavaScript to TypeScript, let's clean up our project a bit.
Now that unit tests have been added to the Node.js application, we'll begin coverting the application to TypeScript. The first refactoring is the express application.
The purpose of this step is to finish our Node.js vanilla Javascript-to-TypeScript conversion. Additionally, we will move the hard-coded data to an external JSON file to mimic an external repository.
We'll start by properly creating our unit tests to test a secondary repository. We will then create the secondary 'repository' that contains the data in an XML file to mimic a different repository type.
To this point, we've converted the entire application from JavaScript to TypeScript and have added unit tests. We will now decouple the data layer and the service layer by introducing dependency injection. By adding dependency injection, we can easily switch between our two repositories while requiring very minimal refactoring.
As a bonus, we'll add the capability to dynamically switch between repositories via the URL.