Browse Source

chore: docs

pull/3783/head
Naveen MR 2 years ago
parent
commit
dc4671f90f
  1. 12
      .run/Run__Docs.run.xml
  2. 94
      packages/noco-docs/content/en/engineering/testing.md

12
.run/Run__Docs.run.xml

@ -0,0 +1,12 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run::Docs" type="js.build_tools.npm">
<package-json value="$PROJECT_DIR$/packages/noco-docs/package.json" />
<command value="run" />
<scripts>
<script value="dev" />
</scripts>
<node-interpreter value="project" />
<envs />
<method v="2" />
</configuration>
</component>

94
packages/noco-docs/content/en/engineering/testing.md

@ -9,56 +9,61 @@ menuTitle: "Testing"
## Unit Tests
### Pre-requisites
- MySQL is preferrable - however we fallback to SQLite
- MySQL is preferred - however tests can fallback on SQLite too
### Setup
- All the tests are in `packages/nocodb` folder, which will be our working directory. Use the following command to get into that folder.
```bash
cd packages/nocodb
```
- Install the dependencies for `nocodb` package
```bash
npm install
```
#### Environment variables
- Add your `env` file with the following command
``` bash
# add a .env file
cp tests/unit/.env.sample tests/unit/.env
```
- Open the `.env` file
``` bash
# open .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
```
Configure the following variables
> DB_HOST : host </br>
> DB_PORT : port </br>
> DB_USER : username </br>
> DB_PASSWORD : password </br>
### Run Tests
``` bash
npm run test:unit
```
### Key points
## Unit tests : Notes
- 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.
### Folder structure
The root folder for unit tests is `packages/tests/unit`
- `rest` folder contains all the test suites for rest apis.
- `model` folder contains all the test suites for models.
- `factory` folder contains all the helper functions to create test data.
- `init` folder contains helper functions to configure test environment.
- `index.test.ts` is the root test suite file which imports all the test suites.
- `TestDbMngr.ts` is a helper class to manage test databases (i.e. creating, dropping, etc.).
### Patterns to follow
- **Factories**
- Use factories for create/update/delete data. No data should be directly create/updated/deleted in the test.
- While writing a factory make sure that it can be used with as less parameters as possible and use default values for other parameters.
- Use named parameters for factories.
``` typescript
createUser({ email, password})
```
- Use one file per factory.
### Walk through of writing a unit test
We will create an `Table` test suite as an example.
@ -153,33 +158,8 @@ export default function () {
We can then import the `Table` test suite to `Rest` test suite in `packages/nocodb/tests/unit/rest/index.test.ts` file(`Rest` test suite is imported in the root test suite file which is `packages/nocodb/tests/unit/index.test.ts`).
### Folder structure
The root folder for unit tests is `packages/tests/unit`
- `rest` folder contains all the test suites for rest apis.
- `model` folder contains all the test suites for models.
- `factory` folder contains all the helper functions to create test data.
- `init` folder contains helper functions to configure test environment.
- `index.test.ts` is the root test suite file which imports all the test suites.
- `TestDbMngr.ts` is a helper class to manage test databases (i.e. creating, dropping, etc.).
### Patterns to follow
- **Factories**
- Use factories for create/update/delete data. No data should be directly create/updated/deleted in the test.
- While writing a factory make sure that it can be used with as less parameters as possible and use default values for other parameters.
- Use named parameters for factories.
``` typescript
createUser({ email, password})
```
- 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.
### Seeding sample db (Sakila)
```typescript
function tableTest() {
@ -190,7 +170,9 @@ function tableTest() {
beforeEach(async function () {
context = await init();
/******* Start : Seeding sample database **********/
sakilaProject = await createSakilaProject(context);
/******* End : Seeding sample database **********/
customerTable = await getTable({project: sakilaProject, name: 'customer'})
});
@ -218,5 +200,5 @@ function tableTest() {
### Running tests
> TODO
### Notes
## Cypress Tests : Notes
> TODO
Loading…
Cancel
Save