Skip to content

Commit

Permalink
test(infra): changing the implementation of the isolated database env…
Browse files Browse the repository at this point in the history
…ironment for e2e tests

Implemented a vitest environment for the Prisma database. Configuration in 'setup-e2e.ts'.
Installed npm-run-all for e2e test scripts and changed scripts in package.json.
Creating ci file for e2e tests and changed ci file for unit tests.
  • Loading branch information
ClaudionorOjr committed Nov 18, 2023
1 parent bfba89d commit c3501bc
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 46 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run e2e tests

on:
workflow_run:
workflows: [Run unit tests]
types:
- completed

jobs:
e2e-tests:
if: github.event.workflow_run.conclusion == 'success'
name: Run e2e tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use node.js
uses: actions/setup-node@v3
with:
node-version: 'latest'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run e2e tests
run: npm run test:e2e
9 changes: 5 additions & 4 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ on:
- alpha

jobs:
run-unit-tests:
unit-tests:
name: Run unit tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout code
uses: actions/checkout@v3

- name: Use node.js
uses: actions/setup-node@v3
with:
node-version: 18
node-version: 'latest'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
- name: Run unit tests
run: npm run test
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,60 @@ Adicionar os scripts de testes ao `package.json`:
},
```

### Test Environment no Vitest

- É necessário criar uma pasta com o nome `vitest-environment-[name]` e iniciar um projeto node dentro dela. Nesse caso à criei na pasta **prisma**.

```sh
# Criando um projeto node em `vitest-environment-prisma`
$ npm init -y
```

- Alterações no `package.json` em **vitest-environment-prisma**:

```json
{
// Nome do arquivo de execução dentro de "vitest-environment-prisma"
"main": "setup-e2e.ts"
}
```

> Criar o arquivo de execução. Neste caso é o arquivo `setup-e2e.ts`.
- Adicionar ao **defineConfig** no arquivo `vite.config.ts`:

```ts
test: {
// O segundo elemento do array environmentMatchGlobs, deve ser exatament o nome ao final de vitest-environmemnt-[name]
// Nesse caso, vitest-environment-prisma
environmentMatchGlobs: [['src/infra/http/controllers/**', 'prisma']],
}
```

- Necessário instalar o `npm-run-all` para rodar os scripts de teste e2e.

```sh
# Executar scripts, os convertendo para funcionar de acordo com o SO que esteja usando
$ npm i npm-run-all -D
```

- Atualizar os scripts de teste para:

```json
"scripts": {
...
"test:create-prisma-environment": "npm link ./prisma/vitest-environment-prisma",
"test:install-prisma-environment": "npm link vitest-environment-prisma",
"test": "vitest run --dir src/domain/use-cases",
"test:watch": "vitest --dir src/domain/use-cases",
"pretest:e2e": "run-s test:create-prisma-environment test:install-prisma-environment",
"test:e2e": "vitest run --dir src/infra/http",
"test:e2e:watch": "vitest --dir src/infra/http",
"test:coverage": "vitest run --coverage",
"test:ui": "vitest --ui"
}
```

</details>

---
Expand Down
Loading

0 comments on commit c3501bc

Please sign in to comment.