Skip to content
Merged
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
8 changes: 4 additions & 4 deletions .env.test-ci
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ NODE_ENV=local
SITE_ORIGIN=http://localhost:3000

# Database connection parameters
DB_HOST=db
DB_PORT=5432
DB_DATABASE=ionicapp_test
DB_USERNAME=user_test
DB_HOST=localhost
DB_PORT=54321
DB_DATABASE=ionicapp_test
DB_USERNAME=username_test
DB_PASSWORD=secret_test

# TypeOrm configuration (true or false)
Expand Down
27 changes: 16 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: .
- uses: actions/setup-node@v4
with:
node-version: 22.14
Expand All @@ -21,7 +23,7 @@ jobs:
**/node_modules
**/.env.test
**/.env.example
key: ${{ runner.os }}-node-npm-${{ hashFiles('**/package-lock.json', '**/.env.test', '**/.env.example') }}
key: ${{ runner.os }}-node-npm-${{ hashFiles('./package-lock.json', './.env.test', './.env.example') }}
restore-keys: |
${{ runner.os }}-node-npm-
- name: Install deps
Expand All @@ -48,21 +50,17 @@ jobs:
**/node_modules
**/.env.test
**/.env.example
key: ${{ runner.os }}-node-npm-${{ hashFiles('**/package-lock.json', '**/.env.test', '**/.env.example') }}
key: ${{ runner.os }}-node-npm-${{ hashFiles('./package-lock.json', './.env.test', './.env.example') }}
- name: Run unit tests
run: npm run test:unit

test-api-int:
test-api-int-e2e:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- uses: isbang/compose-action@v1.5.1
with:
compose-file: "./docker/docker-compose.test-ci.yml"
services: |
postgres_test
redis_test
- run: cp .env.test-ci .env -f
- run: cat .env
- uses: actions/cache@v4
id: npm-cache
with:
Expand All @@ -71,7 +69,12 @@ jobs:
**/node_modules
**/.env.test
**/.env.example
key: ${{ runner.os }}-node-npm-${{ hashFiles('**/package-lock.json', '**/.env.test', '**/.env.example') }}
key: ${{ runner.os }}-node-npm-${{ hashFiles('./package-lock.json', './.env.test', './.env.example') }}
- uses: isbang/compose-action@v1.5.1
with:
compose-file: "docker-compose.yml"
services: |
postgres_tests
- run: npm ci
- name: Get build result artifact
uses: actions/download-artifact@v4
Expand All @@ -81,5 +84,7 @@ jobs:
- run: cp .env.test-ci .env.test -f
- name: Run migrations
run: npm run migration:test:run
- name: Run ingegration tests
- name: Run ingegration and e2e tests
run: npm run test:int
- name: Run e2e tests
run: npm run test:e2e
4 changes: 2 additions & 2 deletions package-lock.json

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

48 changes: 37 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ionicapp",
"version": "0.0.2",
"version": "0.0.3",
"description": "",
"author": "",
"private": true,
Expand All @@ -22,11 +22,12 @@
"migration:revert": "npm run typeorm migration:revert",
"migration:generate": "npm run typeorm migration:generate src/db/migrations/$npm_config_name",
"migration:create": "npx typeorm-ts-node-commonjs migration:create src/db/migrations/$npm_config_name",
"test": "jest",
"test:unit": "jest --selectProjects api-unit",
"test:e2e": "jest --selectProjects api-e2e --detectOpenHandles",
"test:int": "jest --selectProjects api-integration --detectOpenHandles",
"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:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
},
"dependencies": {
"@nestjs/common": "^11.0.1",
Expand Down Expand Up @@ -85,15 +86,40 @@
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"testTimeout": 50000,
"projects": [
{
"displayName": "api-e2e",
"testRegex": ".*\\.e2e-spec\\.ts$",
"transform": {
"^.+\\.ts": "ts-jest"
},
"maxWorkers": 1,
"rootDir": "test"
},
{
"displayName": "api-unit",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.ts": "ts-jest"
},
"maxWorkers": 1,
"rootDir": "src"
},
{
"displayName": "api-integration",
"testRegex": ".*\\.int-spec\\.ts$",
"transform": {
"^.+\\.ts": "ts-jest"
},
"maxWorkers": 1,
"rootDir": "test"
}
]
}
}
}
31 changes: 31 additions & 0 deletions test/app.int-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { App } from 'supertest/types';
import { AppModule } from './../src/app.module';
import { AppService } from '../src/app.service';

describe('AppController (integration)', () => {
let app: INestApplication<App>;
let appService: AppService;

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

app = moduleFixture.createNestApplication();
await app.init();
appService = moduleFixture.get<AppService>(AppService);
});
afterAll(async () => {
await app.close();
});

it('shoud call appService.checkHealth', async () => {
const spyOnCheckHealth = jest.spyOn(appService, 'checkHealth');
spyOnCheckHealth.mockImplementation(() => 'OK');
await request(app.getHttpServer()).get('/health');
expect(spyOnCheckHealth).toHaveBeenCalledTimes(1);
});
});
9 changes: 0 additions & 9 deletions test/jest-e2e.json

This file was deleted.

Loading