diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b46b93ee..26d4b56c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,23 +20,21 @@ jobs: key: ${{ secrets.SSH_KEY }} port: ${{ secrets.PORT }} script: | - node -v export NVM_DIR=~/.nvm source ~/.nvm/nvm.sh - node -v cd /root/web05-Denamu git pull origin main cd server/ - mkdir -p src/configs + mkdir -p configs - echo "DB_TYPE=mysql" > src/configs/.env.db.production - echo "DB_DATABASE=${{ secrets.PRODUCT_DB_DATABASE }}" >> src/configs/.env.db.production - echo "DB_HOST=${{ secrets.PRODUCT_DB_HOST }}" >> src/configs/.env.db.production - echo "DB_PORT=${{ secrets.PRODUCT_DB_PORT }}" >> src/configs/.env.db.production - echo "DB_USERNAME=${{ secrets.PRODUCT_DB_USERNAME }}" >>src/configs/.env.db.production - echo "DB_PASSWORD=${{ secrets.PRODUCT_DB_PASSWORD }}" >> src/configs/.env.db.production + echo "DB_TYPE=mysql" > configs/.env.db.production + echo "DB_DATABASE=${{ secrets.PRODUCT_DB_DATABASE }}" >> configs/.env.db.production + echo "DB_HOST=${{ secrets.PRODUCT_DB_HOST }}" >> configs/.env.db.production + echo "DB_PORT=${{ secrets.PRODUCT_DB_PORT }}" >> configs/.env.db.production + echo "DB_USERNAME=${{ secrets.PRODUCT_DB_USERNAME }}" >> configs/.env.db.production + echo "DB_PASSWORD=${{ secrets.PRODUCT_DB_PASSWORD }}" >> configs/.env.db.production npm ci - npm build + npm run build nohup npm run start > server.log 2>&1 & diff --git a/server/src/configs/.env.db.test b/server/configs/.env.db.test similarity index 100% rename from server/src/configs/.env.db.test rename to server/configs/.env.db.test diff --git a/server/test/jest-e2e.json b/server/jest-e2e.json similarity index 82% rename from server/test/jest-e2e.json rename to server/jest-e2e.json index e9d912f3..5bcd52a3 100644 --- a/server/test/jest-e2e.json +++ b/server/jest-e2e.json @@ -5,5 +5,6 @@ "testRegex": ".e2e-spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" - } + }, + "coverageDirectory": "coverage" } diff --git a/server/jest-unit.json b/server/jest-unit.json new file mode 100644 index 00000000..ce44697d --- /dev/null +++ b/server/jest-unit.json @@ -0,0 +1,11 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": "..", + "testEnvironment": "node", + "testPathIgnorePatterns": [".e2e-spec.ts$"], + "testRegex": ".spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "coverageDirectory": "coverage" +} diff --git a/server/package.json b/server/package.json index fcf7e62e..d48c5c96 100644 --- a/server/package.json +++ b/server/package.json @@ -12,11 +12,14 @@ "start:dev": "cross-env NODE_ENV=development nest start --watch", "start:debug": "cross-env NODE_ENV=development nest start --debug --watch", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", + "test:unit": "cross-env NODE_ENV=test jest --config jest-unit.json", + "test:unit:cov": "cross-env NODE_ENV=test jest --config jest-unit.json --coverage", + "test:e2e": "cross-env NODE_ENV=test jest --config jest-e2e.json", + "test:e2e:cov": "cross-env NODE_ENV=test jest --config jest-e2e.json --coverage", "test": "cross-env NODE_ENV=test jest", "test:watch": "cross-env NODE_ENV=test jest --watch", "test:cov": "cross-env NODE_ENV=test jest --coverage", - "test:debug": "cross-env NODE_ENV=test node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", - "test:e2e": "cross-env NODE_ENV=test jest --config ./test/jest-e2e.json" + "test:debug": "cross-env NODE_ENV=test node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand" }, "dependencies": { "@nestjs/common": "^10.0.0", @@ -65,8 +68,8 @@ "json", "ts" ], - "rootDir": "src", - "testRegex": ".*\\.spec\\.ts$", + "rootDir": "test", + "testRegex": ".*\\.(e2e-spec|spec)\\.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" }, diff --git a/server/src/app.module.ts b/server/src/app.module.ts index 976a0920..c8e8bcd7 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -9,7 +9,7 @@ import { loadDBSetting } from './common/database/load.config'; winstonModule, ConfigModule.forRoot({ isGlobal: true, - envFilePath: `${__dirname}/src/configs/.env.db.${process.env.NODE_ENV === 'test' ? 'test' : 'production'}`, + envFilePath: `${process.cwd()}/configs/.env.db.${process.env.NODE_ENV === 'test' ? 'test' : 'production'}`, }), TypeOrmModule.forRootAsync({ imports: [ConfigModule], diff --git a/server/src/blog/blog.entity.ts b/server/src/blog/blog.entity.ts index 92e36b4c..1e9fce33 100644 --- a/server/src/blog/blog.entity.ts +++ b/server/src/blog/blog.entity.ts @@ -1,5 +1,5 @@ -import { Feed } from 'src/feed/feed.entity'; -import { RssInformation } from 'src/rss/rss.entity'; +import { Feed } from '../feed/feed.entity'; +import { RssInformation } from '../rss/rss.entity'; import { Entity, OneToMany } from 'typeorm'; @Entity({ diff --git a/server/src/common/database/load.config.ts b/server/src/common/database/load.config.ts index cb58e109..baae4a5f 100644 --- a/server/src/common/database/load.config.ts +++ b/server/src/common/database/load.config.ts @@ -7,7 +7,7 @@ export function loadDBSetting(configService: ConfigService) { const port = configService.get('DB_PORT'); const username = configService.get('DB_USERNAME'); const password = configService.get('DB_PASSWORD'); - const entities = [__dirname + '/../**/*.entity.{js,ts}']; + const entities = [`${__dirname}/../../**/*.entity.{js,ts}`]; const synchronize = true; const logging = process.env.NODE_ENV === 'production' ? false : true; diff --git a/server/src/feed/feed.entity.ts b/server/src/feed/feed.entity.ts index 54c180d7..f9c8345b 100644 --- a/server/src/feed/feed.entity.ts +++ b/server/src/feed/feed.entity.ts @@ -1,4 +1,3 @@ -import { Blog } from 'src/blog/blog.entity'; import { BaseEntity, Column, @@ -7,6 +6,7 @@ import { ManyToOne, PrimaryGeneratedColumn, } from 'typeorm'; +import { Blog } from '../blog/blog.entity'; @Entity({ name: 'feed' }) export class Feed extends BaseEntity { @@ -15,7 +15,7 @@ export class Feed extends BaseEntity { @Column({ name: 'created_at', - type: 'timestamp', + type: 'datetime', nullable: false, }) createdAt: Date; diff --git a/server/test/app.e2e-spec.ts b/server/test/app.e2e-spec.ts index 50cda623..5bb081b8 100644 --- a/server/test/app.e2e-spec.ts +++ b/server/test/app.e2e-spec.ts @@ -1,7 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; -import { AppModule } from './../src/app.module'; +import { AppModule } from '../src/app.module'; describe('AppController (e2e)', () => { let app: INestApplication; @@ -18,7 +18,7 @@ describe('AppController (e2e)', () => { it('/ (GET)', () => { return request(app.getHttpServer()) .get('/') - .expect(200) - .expect('Hello World!'); + .expect(404) + .expect('Not Found'); }); }); diff --git a/server/test/test.spec.ts b/server/test/test.spec.ts new file mode 100644 index 00000000..bb38208e --- /dev/null +++ b/server/test/test.spec.ts @@ -0,0 +1,7 @@ +import { add } from '../src/test'; + +describe('test', () => { + test('1', () => { + expect(add(1, 1)).toBe(2); + }); +}); diff --git a/server/tsconfig.json b/server/tsconfig.json index 95f5641c..7ef42c1a 100644 --- a/server/tsconfig.json +++ b/server/tsconfig.json @@ -9,7 +9,7 @@ "target": "ES2021", "sourceMap": true, "outDir": "./dist", - "baseUrl": "./", + "baseUrl": "..", "incremental": true, "skipLibCheck": true, "strictNullChecks": false,