Skip to content

Commit

Permalink
docs: update Testing description
Browse files Browse the repository at this point in the history
  • Loading branch information
fengstats committed Apr 2, 2024
1 parent 1428ac0 commit 0e12a26
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 7 deletions.
55 changes: 51 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ By constructing sentences with conjunctions, it helps you learn English better~

## 🚀 How To Start ?

### Requirements
**The mentioned operations below are based on the root directory of the current project, please be attentive to ensure there are no errors!**

### 0. Requirements

- **pnpm version >= 8**

Expand All @@ -24,8 +26,6 @@ By constructing sentences with conjunctions, it helps you learn English better~
- **Redis version >= 5.0.0**
- **Docker**. please make sure it is installed and running successfully on your local machine.

**The mentioned operations below are based on the root directory of the current project, please be attentive to ensure there are no errors!**

```bash
docker --version # Docker version 24.0.7, build afdd53b

Expand Down Expand Up @@ -86,7 +86,9 @@ When executing this command, try to keep a little time from the previous command
pnpm db:init
```

### 5. Create and Upload Course Data (Only Execute This During the Initial Database Initialization)
### 5. Create and Upload Course Data

**Only Execute This During the Initial Database Initialization**

```bash
pnpm db:upload
Expand All @@ -104,6 +106,51 @@ pnpm dev:serve
pnpm dev:client
```

## ⚒ About testing

**Run the test before submitting the commit, and submit the code after the test passes, so as to avoid multiple commits to solve the test problem**

### Front-end Testing

The main is the single test of Vitest and the automated test of cypress, execute the following command:

```bash
# Enter the front-end project directory
cd apps/client

# vitest
pnpm test:unit:run
# cypress
pnpm test:e2e:run

# monitor vitest, convenient hot update to see test results
pnpm test:unit:watch
```

### Backend Testing

Mainly Jest single test and end-to-end test, but need to access the test database, so you need to ensure that

1. testdb and testRedis services in Docker Compose started normally
2. The configuration information in the `.env.test` file is correct. If there is no such file, you can copy the contents of the `apps/api/.env.example` file to the `apps/api/.env.test` file. The following command is provided to directly use

Execute the following command:

```bash
# Enter Backend Project Directory
cd apps/api

# If you have an.env.test file, you don't need to run this step
cp .env.test.example .env.test

# Single test
pnpm test:unit:run
# End-to-end testing
pnpm test:e2e:run
# Single test and end-to-end test run together
pnpm test
```

## ❓ FAQ

### Database connection failed
Expand Down
53 changes: 50 additions & 3 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

## 🚀 如何开始?

**以下所有相关操作都基于项目根目录位置,请注意检查不要出错!**

### 0. 注意事项

- **pnpm version >= 8**
Expand All @@ -24,8 +26,6 @@
- **Redis version >= 5.0.0**
- 项目依赖 **Docker**,所以请确保你本地已安装并成功运行

**以下所有相关操作都基于项目根目录位置,请注意检查不要出错!⚠️**

```bash
docker --version # Docker version 24.0.7, build afdd53b

Expand Down Expand Up @@ -86,7 +86,9 @@ docker-compose up -d
pnpm db:init
```

### 5. 创建并上传课程数据(只在第一次初始化数据库时执行)
### 5. 创建并上传课程数据

**只有第一次初始化数据库后需要执行**

```bash
pnpm db:upload
Expand All @@ -104,6 +106,51 @@ pnpm dev:serve
pnpm dev:client
```

## ⚒ 关于测试

**提交 commit 前先跑测试,测试通过后再提交代码,以免产生多次 commit 来解决测试问题的情况出现**

### 前端测试

主要就是 Vitest 的单测以及 cypress 的自动化测试,执行以下命令:

```bash
# 进入前端项目目录
cd apps/client

# vitest
pnpm test:unit:run
# cypress
pnpm test:e2e:run

# 监听 vitest,方便热更新看测试结果
pnpm test:unit:watch
```

### 后端测试

主要就是 Jest 的单测和端对端测试,但需要接入测试的数据库,所以需要先确保

1. Docker Compose 中的 testdb 和 testRedis 服务正常启动
2. `.env.test` 文件中的配置信息是正确的,如果没有这个文件,可以复制 `apps/api/.env.example` 文件内容到 `apps/api/.env.test` 文件,下面有提供命令直接用

执行以下命令:

```bash
# 进入后端项目目录
cd apps/api

# 如果有 .env.test 文件,就不需要跑这一步了
cp .env.test.example .env.test

# 单测
pnpm test:unit:run
# 端对端测试
pnpm test:e2e:run
# 单测和端对端测试一起跑
pnpm test
```

## ❓ 常见问题解答

### 数据库连接不上
Expand Down

0 comments on commit 0e12a26

Please sign in to comment.