Skip to content

Commit a73f19f

Browse files
committed
feat: Integrate CI with linter, tests with coverage, and build (#31)
* ci: Create CI * ci: Refactor naming * chore(tests): Define coverage * chore: Add coverage command * ci: Run only PR * chore(ide): Exclude coverage dir * chore(tests): Ignore lib and prisma folders in coverage * refactor(make): Refactor tests command * chore(tests): Fix jest config * perf(tests): Refactor jest config * test: Add tests for UserAdapter * chore: Create format check * chore(linter): Import plugin:prettier/recommended * chore(deps): Install eslint-config-prettier * chore(make): Remove npm run format:c * chore(linter): Remove formatter from linter * chore(make): Add format commands * ci: Add formatter:prettier job * revert: Test to import prettier in linter again * fix(linter): Fix configuration * fix: Clean * fix(make): Fix format command * style: Format files with Prettier * fix: Fix linter issues
1 parent c10ebbb commit a73f19f

File tree

11 files changed

+209
-171
lines changed

11 files changed

+209
-171
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- develop
8+
9+
jobs:
10+
linter_eslint:
11+
name: linter:eslint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 20
18+
cache: 'npm'
19+
- run: npm ci
20+
- run: npm run lint
21+
22+
tests_units:
23+
name: tests:units
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: 20
30+
cache: 'npm'
31+
- run: npm ci
32+
- run: npm run test:cov
33+
34+
build_app:
35+
name: build:app
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version: 20
42+
cache: 'npm'
43+
- run: npm ci
44+
- run: npm run build

.idea/locklite.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@ lint: node_modules
2626
npm run lint
2727

2828
format: node_modules
29-
npm run format
29+
npm run format:w
3030

3131
tests: node_modules
32-
npm run test
32+
npm test
33+
34+
coverage: node_modules
35+
npm run test:cov
3336

3437
migrate: up
3538
npx prisma migrate dev --name init
3639

37-
.PHONY: up down dev build lint format tests migrate
40+
.PHONY: up down dev build lint format tests coverage migrate
3841

3942
# Aliases
4043
run: up dev
41-
.PHONY: run
44+
checks: lint
45+
checks_build: checks build
46+
.PHONY: run checks checks_build

eslint.config.mjs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ export default tseslint.config(
2020
...tseslint.configs.recommended,
2121
...compat.extends('next/core-web-vitals', 'next/typescript'),
2222
...compat.extends('plugin:jest/recommended'),
23+
...compat.extends('plugin:prettier/recommended'),
2324

2425
{
25-
ignores: ['node_modules', 'dist', 'jest.config.cjs'],
26+
ignores: ['*', '!src/**', '!tests/**'],
2627
},
2728

2829
{
@@ -39,7 +40,7 @@ export default tseslint.config(
3940
},
4041
rules: {
4142
// Formatting
42-
'prettier/prettier': ['error', { semi: true }],
43+
'prettier/prettier': ['warn', { semi: true }],
4344
semi: ['error', 'always'],
4445
'max-len': ['warn', { code: 300, ignoreUrls: true }],
4546

@@ -86,10 +87,13 @@ export default tseslint.config(
8687
'@typescript-eslint/class-literal-property-style': ['warn', 'fields'],
8788
'@typescript-eslint/no-empty-function': ['warn'],
8889
'@typescript-eslint/adjacent-overload-signatures': 'warn',
89-
"@typescript-eslint/consistent-type-imports": ["error", {
90-
"prefer": "type-imports",
91-
"disallowTypeAnnotations": false
92-
}],
90+
'@typescript-eslint/consistent-type-imports': [
91+
'error',
92+
{
93+
prefer: 'type-imports',
94+
disallowTypeAnnotations: false,
95+
},
96+
],
9397

9498
// Naming conventions
9599
'@typescript-eslint/naming-convention': [
@@ -136,9 +140,6 @@ export default tseslint.config(
136140
{
137141
files: ['**/*.test.ts', '**/*.spec.ts', '**/*.test.tsx', '**/*.spec.tsx'],
138142
plugins: { jest: eslintPluginJest },
139-
languageOptions: {
140-
env: { 'jest/globals': true },
141-
},
142143
settings: {
143144
jest: { version: 29 },
144145
},

jest.config.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import type { Config } from 'jest';
33
const config: Config = {
44
preset: 'ts-jest',
55
testEnvironment: 'jsdom',
6+
roots: ['<rootDir>/tests'],
67
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
7-
globals: {
8-
'ts-jest': {
9-
tsconfig: 'tsconfig.jest.json',
10-
},
11-
},
128
transform: {
13-
'^.+\\.(ts|tsx)$': ['ts-jest', {}],
9+
'^.+\\.(ts|tsx)$': [
10+
'ts-jest',
11+
{
12+
tsconfig: 'tsconfig.jest.json',
13+
},
14+
],
1415
},
15-
roots: ['<rootDir>'],
1616
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
1717
moduleNameMapper: {
1818
'^@/(.*)$': '<rootDir>/$1',
@@ -22,6 +22,16 @@ const config: Config = {
2222
'^@prisma/(.*)$': '<rootDir>/prisma/$1',
2323
'^@lib/(.*)$': '<rootDir>/lib/$1',
2424
},
25+
testMatch: ['**/?(*.)+(spec|test).[tj]s?(x)'],
26+
coverageThreshold: {
27+
global: {
28+
branches: 80,
29+
functions: 80,
30+
lines: 80,
31+
statements: 80,
32+
},
33+
},
34+
coveragePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/prisma/'],
2535
};
2636

2737
export default config;

0 commit comments

Comments
 (0)