diff --git a/backend/package-lock.json b/backend/package-lock.json index a69a022..5a87950 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -25,6 +25,7 @@ "@types/supertest": "^6.0.0", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", + "c8": "^9.1.0", "eslint": "^8.42.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", @@ -3168,6 +3169,31 @@ "node": ">= 0.8" } }, + "node_modules/c8": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/c8/-/c8-9.1.0.tgz", + "integrity": "sha512-mBWcT5iqNir1zIkzSPyI3NCR9EZCVI3WUD+AVO17MVWTSFNyUueXE82qTeampNtTr+ilN/5Ua3j24LgbCKjDVg==", + "dev": true, + "dependencies": { + "@bcoe/v8-coverage": "^0.2.3", + "@istanbuljs/schema": "^0.1.3", + "find-up": "^5.0.0", + "foreground-child": "^3.1.1", + "istanbul-lib-coverage": "^3.2.0", + "istanbul-lib-report": "^3.0.1", + "istanbul-reports": "^3.1.6", + "test-exclude": "^6.0.0", + "v8-to-istanbul": "^9.0.0", + "yargs": "^17.7.2", + "yargs-parser": "^21.1.1" + }, + "bin": { + "c8": "bin/c8.js" + }, + "engines": { + "node": ">=14.14.0" + } + }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", diff --git a/backend/package.json b/backend/package.json index db6d838..00729d3 100644 --- a/backend/package.json +++ b/backend/package.json @@ -13,12 +13,11 @@ "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", - "test": "npm run test:unit && npm run test:e2e", + "test": "jest", "test:watch": "jest --watch", "test:cov": "jest --coverage", "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "jest --config ./test/jest-e2e.json", - "test:unit": "jest" + "test:e2e": "jest --config ./test/jest-e2e.json" }, "dependencies": { "@nestjs/common": "^10.0.0", @@ -65,6 +64,13 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "coverageThreshold": { + "global": { + "lines": 90, + "functions": 90, + "branches": 90 + } + } } } diff --git a/backend/src/app.controller.spec.ts b/backend/src/app.controller.spec.ts index 10b040e..b01ee42 100644 --- a/backend/src/app.controller.spec.ts +++ b/backend/src/app.controller.spec.ts @@ -11,7 +11,7 @@ describe('AppController', () => { }); describe('getPing', () => { - it('should return pong on ping', () => { + it('should call getPing in app service', () => { jest.spyOn(appService, 'getPing').mockReturnValue('pong'); expect(appController.getPing()).toBe('pong'); }); diff --git a/backend/src/app.service.spec.ts b/backend/src/app.service.spec.ts new file mode 100644 index 0000000..9597ac9 --- /dev/null +++ b/backend/src/app.service.spec.ts @@ -0,0 +1,15 @@ +import { AppService } from './app.service'; + +describe('AppController', () => { + let appService: AppService; + + beforeEach(async () => { + appService = new AppService(); + }); + + describe('getPing', () => { + it('should return pong on getPing', () => { + expect(appService.getPing()).toBe('pong'); + }); + }); +});