Skip to content

Commit

Permalink
setup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 committed Aug 12, 2024
1 parent b151b4a commit c727139
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 65 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test.cov :; npx jest --passWithNoTests --coverage

test.debug :; node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand

test.e2e:; npx jest --config ./test/jest-e2e.json
test.e2e:; npx jest --config ./jest-e2e.config.ts

pre-commit: typecheck lint-stg

Expand Down
25 changes: 25 additions & 0 deletions jest-e2e.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Config } from 'jest';

const config: Config = {
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
testEnvironment: 'node',
testRegex: '.e2e-spec.ts$',
transform: {
'^.+\\.(t|j)s?$': '@swc/jest',
},
coverageDirectory: './coverage-e2e',
coveragePathIgnorePatterns: [
'/node_modules/',
'<rootDir>/src/(.+)/dto/(.+)',
'<rootDir>/src/(.+)/(.+).module.ts',
'<rootDir>/src/(.+).module.ts',
'<rootDir>/src/main.ts',
'<rootDir>/src/run.ts',
'<rootDir>/src/config/',
'<rootDir>/src/common/db/migrations/',
],
modulePaths: ['<rootDir>', '<rootDir>/src'],
};

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

const config: Config = {
verbose: true,
moduleFileExtensions: ['js', 'json', 'ts'],
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': '@swc/jest',
},
collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!<rootDir>/**/*.module.ts'],
coveragePathIgnorePatterns: [
'/node_modules/',
'<rootDir>/src/(.+)/dto/(.+)',
'<rootDir>/src/(.+)/(.+).module.ts',
'<rootDir>/src/(.+).module.ts',
'<rootDir>/src/main.ts',
'<rootDir>/src/run.ts',
'<rootDir>/src/config/',
'<rootDir>/src/common/db/migrations/',
],
coverageDirectory: '<rootDir>/coverage',
testEnvironment: 'node',
modulePaths: ['<rootDir>', '<rootDir>/src'],
// setupFiles: ['<rootDir>/test/setup.ts'],
};

export default config;
123 changes: 109 additions & 14 deletions package-lock.json

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

20 changes: 1 addition & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"node-fetch": "^3.3.2",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"viem": "^2.19.3"
Expand Down Expand Up @@ -59,24 +60,5 @@
"ts-loader": "^9.4.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s?$": [
"@swc/jest"
]
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
9 changes: 2 additions & 7 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
import { ConfigService } from '@nestjs/config';

@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private configService: ConfigService,
) {}
constructor(private readonly appService: AppService) {}

@Get()
getHello() {
const network = this.configService.get<string>('network');
return this.appService.getHello(network!);
return this.appService.getHello();
}
}
10 changes: 8 additions & 2 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class AppService {
getHello(network: string) {
return `Hello World! ${network}`;
private network: string;

constructor(private readonly configService: ConfigService) {
this.network = this.configService.get<string>('network')!;
}
getHello() {
return `Hello World! ${this.network}`;
}
}
4 changes: 2 additions & 2 deletions test/app.e2e-spec.ts → test/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { default as request } from 'supertest';
import { AppModule } from './../src/app.module';
import { AppModule } from './../../src/app.module';

describe('AppController (e2e)', () => {
let app: INestApplication;
Expand All @@ -19,6 +19,6 @@ describe('AppController (e2e)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
.expect('Hello World! localhost');
});
});
9 changes: 0 additions & 9 deletions test/jest-e2e.json

This file was deleted.

Loading

0 comments on commit c727139

Please sign in to comment.