Browse Source

chore: refining test docs

pull/3720/head
Naveen MR 2 years ago
parent
commit
9ae1a70e72
  1. 2
      .github/workflows/ci-cd.yml
  2. 4
      packages/noco-docs/content/en/engineering/architecture.md
  3. 20
      packages/noco-docs/content/en/engineering/development-setup.md
  4. 52
      packages/noco-docs/content/en/engineering/unit-test.md
  5. 0
      packages/nocodb/tests/unit/.env

2
.github/workflows/ci-cd.yml

@ -673,4 +673,4 @@ jobs:
run: docker-compose -f ./scripts/docker-compose-cypress.yml up -d
- name: run unit tests
working-directory: ./packages/nocodb
run: npm run test:unit
run: npm run test:unit

4
packages/noco-docs/content/en/engineering/architecture.md

@ -1,9 +1,9 @@
---
title: "NocoDB architecture"
title: "Architecture Overview"
description: "Simple overview of NocoDB architecture"
position: 3000
category: "Engineering"
menuTitle: "NocoDB architecture"
menuTitle: "Architecture Overview"
---
By default, if `NC_DB` is not specified, then SQLite will be used to store your meta data. We suggest users to separate the meta data and user data in different databases.

20
packages/noco-docs/content/en/engineering/development-setup.md

@ -6,13 +6,13 @@ category: "Engineering"
menuTitle: "Development setup"
---
### Clone the repo
## Clone the repo
```
git clone https://github.com/nocodb/nocodb
cd nocodb/packages
```
### Build SDK
## Build SDK
```
# build nocodb-sdk
cd nocodb-sdk
@ -20,7 +20,7 @@ npm install
npm run build
```
### Build Backend
## Build Backend
```
# build backend - runs on port 8080
cd ../nocodb
@ -28,7 +28,7 @@ npm install
npm run watch:run
```
### Build Frontend
## Build Frontend
```
# build frontend - runs on port 3000
cd ../nc-gui
@ -38,7 +38,7 @@ npm run dev
Any changes made to frontend and backend will be automatically reflected in the browser.
### Cypress
## Cypress - e2e tests
Cypress tests are divided into 4 suites
- SQLite tests
- Postgres tests
@ -52,7 +52,7 @@ First 3 suites, each have 4 test category
- Miscellaneous (Import, i18n, etc)
#### MySQL tests (ExtDB project)
### MySQL tests (ExtDB project)
```shell
# install dependencies(cypress)
npm install
@ -75,7 +75,7 @@ npm run cypress:open
- Miscellaneous : restMisc.js
```
#### SQLite tests (XCDB project)
### SQLite tests (XCDB project)
```shell
# install dependencies(cypress)
npm install
@ -98,7 +98,7 @@ npm run cypress:open
- Miscellaneous : xcdb-restMisc.js
```
#### PG tests (ExtDB project)
### PG tests (ExtDB project)
```shell
# install dependencies(cypress)
npm install
@ -121,7 +121,7 @@ npm run cypress:open
- Miscellaneous : pg-restMisc.js
```
#### Quick import tests (SQLite project)
### Quick import tests (SQLite project)
```shell
# install dependencies(cypress)
npm install
@ -144,7 +144,7 @@ npm run cypress:open
- quickTest.js
```
#### Quick import tests (PG)
### Quick import tests (PG)
```shell
# install dependencies(cypress)
npm install

52
packages/noco-docs/content/en/engineering/unit-test.md

@ -1,32 +1,40 @@
---
title: "Unit Test"
description: "How to write unit tests"
position: 3300
title: "Writing Tests"
description: "Overview to testing"
position: 3250
category: "Engineering"
menuTitle: "Unit Test"
menuTitle: "Tests"
---
## Key points
## Pre-requisites
- MySQL is preferrable - however we fallback to SQLite
- We use [Mocha](https://mochajs.org/) as our test runner and [chai](https://www.chaijs.com/) as our assertion library.
- We use [Supertest](https://www.npmjs.com/package/supertest) to test our API endpoints.
## Setup
```
cp scripts/.env.copy scripts/.env
open scripts/.env
# Edit the following env variables
# `DB_USER` : mysql username
# `DB_PASSWORD` : mysql password
# `DB_HOST` : mysql host
# `DB_PORT` : mysql port
```
## How to run API tests
```
cd packages/nocodb
npm run test:unit
```
## Key points
- All individual unit tests are independent of each other. We don't use any shared state between tests.
- Test environment also includes `sakila` database and any change on `sakila` by a test is reverted before running other 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
We will create an `Table` test suite as an example.
### Describing test suite
Create `Table` test suite by using `describe` function of mocha.
```typescript
export default function () {
describe('Table', tableTests);
}
```
### Configure test
@ -147,13 +155,5 @@ The root folder for unit tests is `packages/tests/unit`
- Use one file per factory.
## Using sakila db
To use sakila db use `createSakilaProject` from `factory/project` to create a project. This project will be seeded with `sakila` tables.
## Configurations
- For Mysql db configuration, use the following environment variables to configure.
- `DB_USER` : mysql username
- `DB_PASSWORD` : mysql password
- `DB_HOST` : mysql host
- `DB_PORT` : mysql port

0
packages/nocodb/tests/unit/.env

Loading…
Cancel
Save