Title here
Summary here
describe('AuthService', () => {
let service: AuthService;
beforeEach(async () => {
const module = await Test.createTestingModule({
providers: [AuthService],
}).compile();
service = module.get<AuthService>(AuthService);
});
it('should validate JWT token', () => {
const token = 'valid.jwt.token';
expect(service.validateToken(token)).toBeTruthy();
});
});
describe('ProjectController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('/projects (GET)', () => {
return request(app.getHttpServer())
.get('/projects')
.expect(200)
.expect([]);
});
});
src/
├── __tests__/ # Test utilities
├── auth/
│ └── __tests__/ # Auth module tests
├── project/
│ └── __tests__/ # Project module tests
└── vm/
└── __tests__/ # VM module tests
# Run unit tests
npm run test
# Run with coverage
npm run test:cov
# Run e2e tests
npm run test:e2e
# Debug e2e tests
npm run test:e2e:debug
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npm test
- run: npm run test:e2e
# test/.env.test
DATABASE_URL=postgresql://test:test@localhost:5432/test
REDIS_URL=redis://localhost:6379/1
# docker-compose.test.yml
services:
postgres:
image: postgres:13
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Tests",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}