Skip to content

Commit

Permalink
chore: update jest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-acampora committed Feb 27, 2025
1 parent 1e99946 commit 95b99a6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JWT_SECRET=nestjs-ddd-devops
JWT_REFRESH_SECRET=nestjs-ddd-devops-refresh
JWT_EXPIRES_IN=3600
JWT_REFRESH_EXPIRES_IN=360000
25 changes: 4 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint 'src/**/*.{ts,tsx}' --fix --no-ignore",
"test": "jest --passWithNoTests --coverage",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test": "jest --config test/config/jest-unit.config.ts --passWithNoTests --coverage",
"test:watch": "jest --config test/config/jest-unit.config.ts --watch",
"test:cov": "jest --config test/config/jest-unit.config.ts --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config test/e2e/jest-e2e.json --detectOpenHandles --forceExit",
"test:e2e": "jest --config test/config/jest-e2e.config.ts --detectOpenHandles --forceExit",
"schema:update": "npm run build && npx mikro-orm schema:update -r --config src/config/database/mikro-orm.config.ts",
"migrate:up": "npm run build && npx mikro-orm migration:up --config --config src/config/database/mikro-orm.config.ts",
"migrate:down": "npm run build && npx mikro-orm migration:down --config --config src/config/database/mikro-orm.config.ts"
Expand Down Expand Up @@ -85,22 +85,5 @@
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.7.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "test",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
1 change: 0 additions & 1 deletion src/libs/util/config.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export const getConfigValue = <T>(
configService: ConfigService,
key: string,
): T => {
console.log('AAA');
return getOrThrowWith<T>(
fromNullable(configService.get<T>(key)),
() => new Error(`Missing ${key}`),
Expand Down
2 changes: 1 addition & 1 deletion src/modules/health/controller/health.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class HealthController {
() => this.db.pingCheck('database'),
() =>
this.disk.checkStorage('storage', { path: '/', thresholdPercent: 0.8 }),
() => this.memory.checkHeap('memory', 500 * 1024 * 1024),
() => this.memory.checkHeap('memory', 750 * 1024 * 1024),
]);
}
}
9 changes: 9 additions & 0 deletions test/config/jest-e2e.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Config } from 'jest';
import baseConfig from './jest.config.base';

const e2eConfig: Config = {
...baseConfig,
testRegex: '.e2e-spec.ts$',
};

export default e2eConfig;
11 changes: 11 additions & 0 deletions test/config/jest-unit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Config } from 'jest';
import baseConfig from './jest.config.base';

const unitConfig: Config = {
...baseConfig,
testRegex: '.*\\.spec\\.ts$',
coverageDirectory: '../coverage',
collectCoverageFrom: ['**/*.(t|j)s'],
};

export default unitConfig;
13 changes: 13 additions & 0 deletions test/config/jest.config.base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from 'jest';

const baseConfig: Config = {
rootDir: '../',
moduleFileExtensions: ['js', 'json', 'ts'],
testEnvironment: 'node',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
setupFiles: ['./config/jest.setup.ts'],
};

export default baseConfig;
3 changes: 3 additions & 0 deletions test/config/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { config } from 'dotenv';

config({ path: '.env.test' });
9 changes: 0 additions & 9 deletions test/e2e/jest-e2e.json

This file was deleted.

0 comments on commit 95b99a6

Please sign in to comment.