TDD course with AdonisJs - 1. Let's build a reddit clone
Published 9/7/2019
This article is part of a series:
1 TDD course with AdonisJs - 1. Let's build a reddit clone
2 TDD course with AdonisJs - 2. Our first test
3 TDD course with AdonisJs - 3. Model factories & DB transactions
4 TDD course with AdonisJs - 4. Using the auth middleware
5 TDD course with AdonisJs - 5. Middlewares
6 TDD course with AdonisJs - 6. Validation
7 TDD course with AdonisJs - 7. Moderators
8 TDD course with AdonisJs - 8. Third party APIs, ioc and custom validators
AdonisJs is great for test driven development. Let's build an API for a simple version of reddit using TDD. It will consist of subforums, threads, comments and users. You can find the GitHub for it here: https://github.com/MZanggl/tdd-adonisjs/commit/b2582b286e4da0166f30a8d6a8eee7c3aeb1c8bb.
Without further ado, let's get the project set up!
Install CLI and framework
npm i -g @adonisjs/cli
In this course we want to focus only on the adonis part and not the frontend, so let's create the project using the "api only" flag.
adonis new forum --api-only
cd forum
Install testing library
Adonis comes with its own testing library, let's install it with
adonis install @adonisjs/vow
We have to add the vowProvider under "start/app.js" in the aceProviders array to register the adonis test commands.
const aceProviders = [
'@adonisjs/vow/providers/VowProvider',
]
The installation of vow comes with an example test, run adonis test
, npm test
or simply npm t
to run it.
To make sure things are working, run the project using adonis serve --dev
and head to the url in your browser!
Check out my e-book!
And that's all there is to it, in the next blog post we will create our first test!