GSoC 2020: Tasty Testing with Mocha and Chai ☕️

This article covers configuring TypeScript unit testing with mocha as well as the test cases are written for Parsers and Transformers in the code generation component

Rajitha Warusavitarana
Leopards Lab
3 min readAug 3, 2020

--

Welcome to another article about the Node Cloud project. In the previous article, the class-based transformer for GCP plugin was described in detail and an overall explanation of the code generation component was given. As I mentioned in the previous article my next main goal was to write unit tests for the code generation component. In this article, I will explain how I configured Mocha with TypeScript and about the unit test cases that I have written so far.

Photo by Karim MANJRA on Unsplash

The code generator is located in a sperate Yarn workspace as I explained in the Lerna package management article. All the other workspaces are based on JavaScript. Since the code generator is written with TypeScript configuring Mocha is bit different. Thanks to an article written by Jeong Woo Chang, I got it configured easily. In order to execute unit tests Cross-env, TS-Node and some type definitions had to be installed as development dependencies in addition to Mocha and Chai.

After configuring Mocha, I looked in to some tutorials as I didn’t have much experience in unit testing. Parsers and transformers are implemented as isolated units for each cloud provider. I have completed writing unit tests for several contexts for the functions which are relevant to the parsers and transformers. Since transformers requires JavaScript files and a larger data object as input I had to create dummy datasets, for each testcase there is a dataset which contains a JSON file containing data and the relevant JavaScript file. You can check them in the #58 PR. There are some few more unit tests that needs to be written for the data extraction process. I had to do some minor code changes to isolate the data extraction process for unit testing. Unit tests for this will be finishing up soon and I will be documenting the code generation component in detail this week. I took feedback from my mentors in the weekly sync-up on Saturday regarding the unit tests that I have written so far. Then we discussed about the plans for the upcoming week. The pull requests related for unit testing is listed below.

That’s pretty much it for this article. Keep in touch to read more updates about the Node Cloud project.

Good Bye…

--

--