Skip to content

Commit

Permalink
test: sqlite 파일 생성 로직을 관련 테스트 파일로 이동 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coalery authored Oct 21, 2023
1 parent 19e9193 commit 5b61e9c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@
"testEnvironment": "node",
"moduleNameMapper": {
"@sight/(.*)": "<rootDir>/$1"
},
"setupFiles": [
"<rootDir>/__test__/setup.ts"
]
}
}
}
10 changes: 0 additions & 10 deletions src/__test__/setup.ts

This file was deleted.

25 changes: 19 additions & 6 deletions src/core/persistence/transaction/Transactional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { AopModule } from '@toss/nestjs-aop';
import { existsSync } from 'fs';
import { chmod, rm, writeFile } from 'fs/promises';
import { advanceTo, clear } from 'jest-date-mock';
import { ClsModule, ClsService } from 'nestjs-cls';
import {
Connection,
Entity,
EntityManager,
MikroORM,
PrimaryKey,
} from '@mikro-orm/core';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Injectable } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { AopModule } from '@toss/nestjs-aop';
import { advanceTo, clear } from 'jest-date-mock';
import { ClsModule, ClsService } from 'nestjs-cls';

import { TRANSACTIONAL_ENTITY_MANAGER } from '@sight/core/persistence/transaction/constant';
import { Transactional } from '@sight/core/persistence/transaction/Transactional';
Expand All @@ -30,6 +32,16 @@ class MockClass {
}
}

async function recreateTestSqliteDBFile(path: string) {
const isExists = await existsSync(path);
if (isExists) {
await rm(path);
}

await writeFile(path, '');
await chmod(path, 0o666);
}

describe('Transactional', () => {
let mockClass: MockClass;
let cls: ClsService;
Expand All @@ -40,6 +52,7 @@ describe('Transactional', () => {
advanceTo(new Date());

const dbFilePath = './src/__test__/test.sqlite3';
await recreateTestSqliteDBFile(dbFilePath);

testModule = await Test.createTestingModule({
imports: [
Expand Down

0 comments on commit 5b61e9c

Please sign in to comment.