mirror of
https://github.com/nocodb/nocodb.git
synced 2026-04-30 18:36:59 +00:00
fix(nocodb): Added env configuration to unit test and added that to docs as well
This commit is contained in:
@@ -1,46 +1,70 @@
|
||||
---
|
||||
title: "Writing Tests"
|
||||
description: "Overview to testing"
|
||||
title: "Writing Unit Tests"
|
||||
description: "Overview to unit testing"
|
||||
position: 3250
|
||||
category: "Engineering"
|
||||
menuTitle: "Testing"
|
||||
menuTitle: "Unit tests"
|
||||
---
|
||||
|
||||
## API Tests
|
||||
## Pre-requisites
|
||||
|
||||
### Pre-requisites
|
||||
- MySQL is preferrable - however we fallback to SQLite
|
||||
|
||||
### Setup
|
||||
```
|
||||
cp scripts/.env.copy scripts/.env
|
||||
open scripts/.env
|
||||
## Setup
|
||||
|
||||
# Edit the following env variables
|
||||
# `DB_USER` : mysql username
|
||||
# `DB_PASSWORD` : mysql password
|
||||
# `DB_HOST` : mysql host
|
||||
# `DB_PORT` : mysql port
|
||||
```
|
||||
- All the tests are in `packages/nocodb` folder, which will be our working directory. Use the following command to get into that folder.
|
||||
|
||||
### Running tests
|
||||
```
|
||||
```bash
|
||||
cd packages/nocodb
|
||||
```
|
||||
|
||||
- Install the dependencies for `nocodb` package
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
### Environment variables
|
||||
|
||||
- Add your `env` file with the following command
|
||||
|
||||
```
|
||||
cp tests/unit/.env.copy tests/unit/.env
|
||||
```
|
||||
|
||||
- Open the `.env` file
|
||||
|
||||
```
|
||||
open tests/unit/.env
|
||||
````
|
||||
|
||||
- Configure the following variables
|
||||
|
||||
> DB_USER : mysql username </br>
|
||||
> DB_PASSWORD : mysql password </br>
|
||||
> DB_HOST : mysql host </br>
|
||||
> DB_PORT : mysql port </br>
|
||||
|
||||
|
||||
|
||||
## How to run tests
|
||||
|
||||
```
|
||||
|
||||
npm run test:unit
|
||||
```
|
||||
|
||||
### Notes
|
||||
## Key points
|
||||
|
||||
#### Key points
|
||||
- All individual unit tests are independent of each other. We don't use any shared state between tests.
|
||||
- Test environment includes `sakila` sample database and any change to it by a test is reverted before running other tests.
|
||||
- While running unit tests, it tries to connect to mysql server running on `localhost:3306` with username `root` and password `password`(which can be configured) and if not found, it will use `sqlite` as a fallback, hence no requirement of any sql server to run tests.
|
||||
|
||||
#### Walk through of writing a unit test
|
||||
### Walk through of writing a unit test
|
||||
|
||||
We will create an `Table` test suite as an example.
|
||||
|
||||
|
||||
##### Configure test
|
||||
#### Configure test
|
||||
|
||||
We will configure `beforeEach` which is called before each test is executed. We will use `init` function from `nocodb/packages/tests/unit/init/index.ts`, which is a helper function which configures the test environment(i.e resetting state, etc.).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user