Skip to content

Commit f88e84b

Browse files
authored
Merge pull request #20 from jpb06/fix/jest-memory-leaks
Fix/jest memory leaks
2 parents 5b685af + c77c3f7 commit f88e84b

24 files changed

+538
-285
lines changed

.eslintrc.yml

+92-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,84 @@
1+
root: true
2+
13
parser: '@typescript-eslint/parser'
24

35
parserOptions:
4-
project: './tsconfig.json'
5-
sourceType: 'module'
6+
project: ./tsconfig.json
7+
sourceType: module
68

79
plugins:
810
- '@typescript-eslint/eslint-plugin'
911
- prettier
1012
- import
11-
12-
root: true
13+
- jest
1314

1415
extends:
1516
- eslint:recommended
1617
- plugin:@typescript-eslint/recommended
1718
- plugin:prettier/recommended
1819
- plugin:import/typescript
20+
- plugin:jest/recommended
21+
- plugin:jest/style
1922

2023
env:
2124
jest: true
2225
node: true
2326

2427
rules:
25-
'@typescript-eslint/no-explicit-any': off
26-
'@typescript-eslint/interface-name-prefix': off
27-
'@typescript-eslint/explicit-function-return-type': off
28+
'@typescript-eslint/await-thenable': error
2829
'@typescript-eslint/explicit-module-boundary-types': off
30+
'@typescript-eslint/explicit-function-return-type': error
31+
'@typescript-eslint/explicit-member-accessibility': off
32+
'@typescript-eslint/indent': off
33+
'@typescript-eslint/interface-name-prefix': off
34+
'@typescript-eslint/member-delimiter-style': off
35+
'@typescript-eslint/member-ordering': error
36+
'@typescript-eslint/no-confusing-non-null-assertion': error
37+
'@typescript-eslint/no-empty-interface': off
38+
'@typescript-eslint/no-explicit-any': error
39+
'@typescript-eslint/no-extra-non-null-assertion': error
40+
'@typescript-eslint/no-floating-promises':
41+
- error
42+
- ignoreVoid: true
43+
'@typescript-eslint/no-non-null-assertion': error
44+
'@typescript-eslint/no-use-before-define': off
45+
'@typescript-eslint/no-unused-vars':
46+
- error
47+
- argsIgnorePattern: '^_'
48+
'@typescript-eslint/no-var-requires': off
49+
'@typescript-eslint/switch-exhaustiveness-check': error
50+
array-bracket-newline:
51+
- error
52+
- consistent
53+
array-bracket-spacing:
54+
- error
55+
- never
56+
array-callback-return: error
57+
block-spacing:
58+
- error
59+
brace-style: error
60+
camelcase:
61+
- off
62+
- properties: never
63+
complexity: error
64+
computed-property-spacing:
65+
- error
66+
- never
67+
curly:
68+
- error
69+
- all
70+
default-case: off
71+
default-case-last: off
72+
dot-location:
73+
- error
74+
- property
75+
dot-notation: error
76+
eqeqeq: error
77+
eol-last: error
78+
func-call-spacing:
79+
- error
80+
- never
81+
func-style: error
2982
import/no-unresolved: off
3083
import/order:
3184
- error
@@ -38,14 +91,44 @@ rules:
3891
alphabetize:
3992
order: 'asc'
4093
pathGroups:
94+
- pattern: '@nestjs/**'
95+
group: external
4196
- pattern: '{@tests/**,@type/**,@modules/**,@database/**,@decorators/**,@filters/**,@pipes/**}'
4297
group: internal
4398
position: before
4499
pathGroupsExcludedImportTypes:
45100
- builtin
101+
jest/no-conditional-expect: off
102+
key-spacing: error
103+
keyword-spacing: error
104+
lines-between-class-members: error
105+
newline-per-chained-call: off
46106
no-console:
47107
- error
48-
- allow: [warn, error]
108+
- allow:
109+
- warn
110+
- error
111+
no-dupe-keys: error
112+
no-else-return: error
113+
no-implicit-coercion: error
114+
no-invalid-this: error
115+
no-lonely-if: error
116+
no-multi-spaces: error
117+
no-return-await: error
118+
no-trailing-spaces: error
119+
no-useless-return: error
120+
no-unneeded-ternary: error
121+
prefer-arrow-callback:
122+
- error
123+
prefer-const: error
49124
prettier/prettier:
50125
- error
51-
- endOfLine: auto
126+
template-curly-spacing:
127+
- error
128+
- never
129+
valid-typeof: error
130+
jest/expect-expect:
131+
- error
132+
- assertFunctionNames:
133+
- expect
134+
- request.**.expect

.github/workflows/checks.yml

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
name: checks
2-
on: [push]
1+
on:
2+
push:
3+
branches:
4+
- master
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
name: Main workflow
38
jobs:
49
install:
510
runs-on: ubuntu-latest
@@ -27,7 +32,7 @@ jobs:
2732
node-version: '16.x'
2833

2934
- name: Setting yarn version
30-
run: yarn policies set-version 1.22.10
35+
run: yarn policies set-version 1.22.17
3136

3237
- name: Install dependencies
3338
run: yarn install --prefer-offline
@@ -43,3 +48,9 @@ jobs:
4348

4449
- name: Generating coverage badges
4550
uses: jpb06/[email protected]
51+
52+
- name: SonarCloud Scan
53+
uses: sonarsource/sonarcloud-github-action@master
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

README.md

+27-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# Sandbox
22

33
[![Open in Visual Studio Code](https://open.vscode.dev/badges/open-in-vscode.svg)](https://open.vscode.dev/jpb06/nestjs-prisma-postgres-sandbox)
4-
![Code quality](https://img.shields.io/codefactor/grade/github/jpb06/nestjs-prisma-postgres-sandbox?logo=codefactor)
4+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=jpb06_nestjs-prisma-postgres-sandbox&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=jpb06_nestjs-prisma-postgres-sandbox)
5+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=jpb06_nestjs-prisma-postgres-sandbox&metric=security_rating)](https://sonarcloud.io/dashboard?id=jpb06_nestjs-prisma-postgres-sandbox)
6+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=jpb06_nestjs-prisma-postgres-sandbox&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=jpb06_nestjs-prisma-postgres-sandbox)
7+
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=jpb06_nestjs-prisma-postgres-sandbox&metric=code_smells)](https://sonarcloud.io/dashboard?id=jpb06_nestjs-prisma-postgres-sandbox)
8+
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=jpb06_nestjs-prisma-postgres-sandbox&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=jpb06_nestjs-prisma-postgres-sandbox)
9+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=jpb06_nestjs-prisma-postgres-sandbox&metric=coverage)](https://sonarcloud.io/dashboard?id=jpb06_nestjs-prisma-postgres-sandbox)
510
![Coverage](./badges/coverage-global%20coverage.svg)
611
![Github workflow](https://img.shields.io/github/workflow/status/jpb06/nestjs-prisma-postgres-sandbox/checks?label=last%20workflow&logo=github-actions)
712
![Last deployment](https://img.shields.io/github/deployments/jpb06/nestjs-prisma-postgres-sandbox/nestjs-prisma-postgres?label=last%20deployment&logo=heroku)
@@ -30,71 +35,77 @@ So let's talk about the stack (pushing on an open door here, but hey):
3035

3136
## :zap: Guidelines
3237

33-
### :diamonds: Schema splitting
38+
### 🔶 Schema splitting
3439

3540
We do not want a huge prisma schema. We want to isolate each model (table or set of tables) in its own file.
3641

37-
### :diamonds: Well documented routes
42+
### 🔶 Well documented routes
3843

3944
Let's have a swagger documenting properly exposed routes, that is mainly for each route:
4045

4146
- a description.
4247
- the list of possible responses.
4348
- a definition of the inputs and outputs.
4449

45-
### :diamonds: Full testing coverage
50+
### 🔶 Full testing coverage
4651

4752
We want to test everything to learn how to properly test, and to face every single difficulty that comes with testing. We will at very least do end to end using superagent, controllers testing, service testing.
4853

49-
### :diamonds: No testing against the database
54+
### 🔶 No testing against the database
5055

5156
All tests should run without any interaction with a database.
5257

5358
## :zap: Usage
5459

55-
### :diamonds: run locally
60+
### 🔶 run locally
5661

57-
:point_down: Since our prisma schemas are split within modules, we will have to merge them all in one file prisma can understand. Let's do just that:
62+
#### 👇 Since our prisma schemas are split within modules, we will have to merge them all in one file prisma can understand. Let's do just that:
5863

5964
```bash
6065
yarn prisma:merge
6166
```
6267

63-
:point_down: Now, we need to tell prisma to generate in node_modules the code actually allowing us to interact with the database:
68+
#### 👇 Now, we need to tell prisma to generate in node_modules the code actually allowing us to interact with the database:
6469

6570
```bash
6671
yarn prisma:gen
6772
```
6873

69-
:point_down: You will need docker and docker-compose to get the postgres database up and running. You can use this command to launch the database container:
74+
#### 👇 You will need docker and docker-compose to get the postgres database up and running. You can use this command to launch the database container:
7075

7176
```bash
72-
yarn dev:db
77+
yarn docker
7378
```
7479

75-
:point_down: Then, let's inject some data in our dev database using:
80+
#### 👇 Then, let's inject some data in our dev database using:
7681

7782
```bash
7883
yarn prisma:seed
7984
```
8085

81-
:point_down: We can now launch the backend in dev:
86+
#### 👇 We can now launch the backend in dev:
8287

8388
```bash
8489
yarn dev
8590
```
8691

87-
### :diamonds: test all the things
92+
#### 😵 You can do the merge, gen & seed steps all at once using the following command:
93+
94+
```bash
95+
yarn dev:db
96+
```
97+
98+
### 🔶 test all the things
8899

89-
:point_down: We can run all the tests and get a coverage report using the following:
100+
🔶 We can run all the tests and get a coverage report using the following:
90101

91102
```bash
92103
yarn test:dev
93104
```
94105

95106
## :zap: Subjects
96107

97-
### :diamonds: Authentication
108+
### 🔶 Authentication
98109

99110
Let's use passport to setup jwt based authentication.
100111

@@ -121,7 +132,7 @@ We have two users in database to play with the routes:
121132
- :white_check_mark: services
122133
- :white_check_mark: local passport strategy
123134

124-
### :diamonds: CRUD
135+
### 🔶 CRUD
125136

126137
Let's create CRUD routes to manage a list of books.
127138
We want to make sure to give a proper feedback when foreign keys violations do occur (when we try to delete an entry whose key is referenced in another table or when we try to update an entry with a foreign key that does not exist). Let's use filters for that!

jest.config.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
const { pathsToModuleNameMapper } = require('ts-jest/utils');
3+
34
const {
45
compilerOptions: { paths: tsconfigPaths },
56
} = require('./tsconfig');
67

78
module.exports = {
89
roots: ['<rootDir>/src/'],
10+
logHeapUsage: true,
911
moduleFileExtensions: ['js', 'json', 'ts'],
1012
moduleNameMapper: {
1113
...pathsToModuleNameMapper(tsconfigPaths, { prefix: '<rootDir>/src' }),
1214
},
13-
testRegex: '\\.(test|spec)\\.ts$',
1415
transform: {
15-
'^.+\\.(t|j)s$': 'ts-jest',
16+
'^.+\\.ts$': 'ts-jest',
1617
},
1718
collectCoverageFrom: ['**/*.ts'],
1819
coveragePathIgnorePatterns: ['/tests-related/', '.dto\\.ts'],
1920
coverageDirectory: './coverage',
2021
testEnvironment: 'node',
2122
coverageReporters: ['json-summary', 'text', 'lcov'],
23+
globals: {
24+
'ts-jest': {
25+
isolatedModules: true,
26+
},
27+
},
2228
};

0 commit comments

Comments
 (0)