Our great sponsors
-
uvu-fastify-graphql
Using uvu for TypeScript API testing: we take a look at integrating a fast test runner into your backend continuous integration workflow.
-
SurveyJS
Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.
-
supertest
🕷 Super-agent driven library for testing node.js HTTP servers using a fluent API. Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
In this post we will look at using uvu for TypeScript API testing. uvu is a lightweight and lightning fast test runner. It is bare-boned though has enough functionality to run unit and integration tests on your app's backend. Being so fast you can merge it into your continuous integration process. This means you can run tests before every push to your git repo. On top it works well with test driven development, where you write tests first to define expected behaviour and then implement your feature.
We won't build an app as we normally do in these posts. I have created a basic GraphQL API coded in TypeScript and using Fastify and Apollo server though. So you can clone that from the git repo to follow along or check out details we don't have time to go into here. Although that code uses Fastify, you can use uvu with Express or other node-based servers. You can also use it with JavaScript (not just TypeScript).
SuperTest is helpful for testing the GraphQL endpoints. We can use it to send HTTP requests and make assertions on the responses. If you are working on a Fastify project, as we will see, you use inbuilt Fastify functionality and don't need to add supertest.