Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pipelines for tests #14

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/unit-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: CI Pipeline - Tests Only

on:
push:
branches:
- '**'
- '!develop'
pull_request:
branches:
- '**'

jobs:
test:
runs-on: ubuntu-latest

services:
mongodb:
image: mongo:latest
ports:
- 27017:27017

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

- name: Set up Node.js for tests
uses: actions/setup-node@v3
with:
node-version: '21'

- name: Install dependencies
run: npm ci

- name: Run unit tests
env:
MONGODB_HOST: localhost
MONGODB_PORT: 27017
MONGODB_DATABASE: dev
MONGODB_USER: root
MONGODB_PASSWORD: dev
MONGO_URI: mongodb://root:dev@localhost:27017/dev
run: npm run test

- name: Run e2e tests
env:
MONGODB_HOST: localhost
MONGODB_PORT: 27017
MONGODB_DATABASE: dev
MONGODB_USER: root
MONGODB_PASSWORD: dev
MONGO_URI: mongodb://root:dev@localhost:27017/dev
run: npm run test:e2e
60 changes: 23 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"check-branch-name": "chmod 755 ./.husky/hooks/check-branch-naming.sh && sh ./.husky/hooks/check-branch-naming.sh",
"format": "prettier --write \"{src,test}/**/*.ts\" \"test/**/*.ts\"",
"lint": "eslint \"{src,test}/**/*.ts\" --fix",
"prepare": "husky",
"prepare": "if [ \"$NODE_ENV\" != \"production\" ]; then husky install; fi",
"prepare:dev": "docker-compose -f docker/docker-compose.yml up -d",
"start": "nest start",
"start:debug": "nest start --debug --watch",
Expand All @@ -19,11 +19,10 @@
"test": "jest",
"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:e2e": "jest --config ./test/jest-e2e.json --detectOpenHandles",
"test:watch": "jest --watch"
},
"dependencies": {
"@nestjs/cli": "^10.4.2",
"@nestjs/common": "^10.3.10",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.3.10",
Expand All @@ -36,14 +35,14 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"dotenv": "^16.4.5",
"mongoose": "^8.5.1",
"mongoose": "^8.7.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"uuid": "^10.0.0"
},
"devDependencies": {
"@eslint/js": "^9.7.0",
"@nestjs/cli": "^10.4.2",
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.2",
"@nestjs/testing": "^10.3.10",
"@types/eslint__js": "^8.42.3",
Expand Down
9 changes: 9 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';

@Controller('/')
export class AppController {
@Get()
getHello(): string {
return 'Hello i::team!';
}
}
25 changes: 25 additions & 0 deletions src/app.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppModule } from './app.module';
import { INestApplication } from '@nestjs/common';

describe('AppModule', () => {
let appModule: TestingModule;
let app: INestApplication;

beforeAll(async () => {
appModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();

app = appModule.createNestApplication();
await app.init();
});

it('should compile the module', () => {
expect(appModule).toBeDefined();
});

afterAll(async () => {
await app.close();
});
});
11 changes: 6 additions & 5 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { getMongoConnectionString } from './libs';
import { AppController } from './app.controller';

@Module({
imports: [
Expand All @@ -12,12 +12,13 @@ import { getMongoConnectionString } from './libs';
MongooseModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: async (configService: ConfigService) => ({
uri: getMongoConnectionString(configService),
}),
useFactory: async (configService: ConfigService) => {
const uri = `mongodb://${configService.get<string>('MONGODB_HOST')}:${configService.get<string>('MONGODB_PORT')}/${configService.get<string>('MONGODB_DATABASE')}`;
return { uri };
},
}),
],
controllers: [],
controllers: [AppController],
providers: [],
})
export class AppModule {}
4 changes: 4 additions & 0 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ describe('AppController (e2e)', () => {
await app.init();
});

afterAll(async () => {
await app.close();
});

it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
Expand Down
Loading