Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1] 프로젝트 셋업 / TDD를 위한 deeplyCopy 테스트 코드 작성 / Dual Package 지원 #2

Merged
merged 65 commits into from
Jul 5, 2024

Conversation

kleekich21
Copy link
Collaborator

@kleekich21 kleekich21 commented Jun 19, 2024

상세

  • 프로젝트 기본 셋업:
  • TypeScript
  • Jest, ts-jest
  • babel
  • ESLint
  • Prettier
  • tsc를 이용한 Dual Packages 지원
  • CJS
  • ESM
  • TDD를 위한 테스트 환경 구성
  • script 추가
  • .gitignore 추가
  • 테스트 코드 작성

이번 PR에서 중점적으로 봐주었으면 하는 사항들

  • 테스트 코드 작성 내용
  • deeplyCopy 인자와 return value의 타입 => 가이드에 P로 generic type을 명시해주셨군요
  • 프로젝트 셋업 관련하여 보완하거나 개선할 사항들

deeplyCopy 테스트 케이스

  • primitive Type을 복사한다. (number, string, boolean, undefined, null, symbol)
  • 단일 레벨 객체를 복사한다.
  • 단일 레벨 배열을 복사한다.
  • 중첩 객체를 내부까지 복사한다.
  • 중첩 배열을 내부까지 복사한다.
  • 배열을 프로퍼티로 포함한 객체를 복사한다.
  • 객체를 요소로 포함한 배열을 복사한다.
  • 사이클이 있는 구조를 복사한다.
  • 클래스 인스턴스를 복사한다.

참고

TDD로 진행하므로 테스트 코드 먼저 작성하였습니다. deeplyCopy는 구현 전이라, 현재 모든 테스트는 fail하는 상태입니다.
테스트 진행은 npm run test 로 진행하실 수 있습니다.

질문

  • README에 어떤 요소들이 들어가면 좋나요?

다음 PR

  • deeplyCopy 구현
  • 필요시 test refactoring

@kleekich21 kleekich21 self-assigned this Jun 19, 2024
Copy link

@f-lab-cadiz f-lab-cadiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README.md엔 모듈 설치 방법이랑 간단한 API 소개 정도만 있으면 좋을 것 같네요!

  1. GitHub Actions로 테스트 항상 실행되고 모두 통과해야 main으로 머지될 수 있도록 설정해보면 어떨까요?
  2. CJS, ESM 지원 모두 할 수 있도록 세팅해봐도 좋을 것 같아요! (관련 아티클)

@f-lab-cadiz
Copy link

Prettier도 설정해두면 좋겠네요!

@kleekich21 kleekich21 changed the title [#1] 프로젝트 셋업 및 TDD를 위한 deeplyCopy 테스트 코드 작성 [#1] 프로젝트 셋업 / TDD를 위한 deeplyCopy 테스트 코드 작성 / Dual Package 지원 Jul 2, 2024
@kleekich21
Copy link
Collaborator Author

듀얼 패키지 지원을 위해 컴파일 단계에서 .cjs 파일을 생성하려고 했지만 Typescript가 아직 그 기능을 지원하고 있지 않음. 따라서, 확장자명 변경 로직을 추가 함. 관련 이슈

renameFiles.js Outdated
Comment on lines 1 to 24
import fs from 'fs';
import path from 'path';

function renameFiles(directory, oldExt, newExt) {
fs.readdir(directory, (err, files) => {
if (err) throw err;

files.forEach((file) => {
if (path.extname(file) === oldExt) {
const oldPath = path.join(directory, file);
const newPath = path.join(
directory,
path.basename(file, oldExt) + newExt,
);
fs.rename(oldPath, newPath, (err) => {
if (err) throw err;
console.log(`Renamed: ${file} -> ${path.basename(newPath)}`);
});
}
});
});
}

renameFiles('./build/cjs', '.js', '.cjs');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 부분만 ts로 한 번 바꿔주세요! 🙇

package.json Outdated
"build": "npm run build:cjs && npm run build:esm && npm run build:rename && npm run rename",
"build:cjs": "tsc --p ./cjs/tsconfig.json",
"build:esm": "tsc --p ./esm/tsconfig.json",
"build:rename": "npx tsc renameFiles.ts",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsx 혹은 ts-node 써서 하는 방식으로 수정 부탁드려요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영 완료하였습니다!

Copy link

@f-lab-cadiz f-lab-cadiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM 고생하셨습니다!

머지하기 전에 renameFiles.js만 지우면 좋을 것 같네요 ㅎㅎ

Copy link

sonarcloud bot commented Jul 5, 2024

@kleekich21
Copy link
Collaborator Author

kleekich21 commented Jul 5, 2024

@f-lab-cadiz 꼼꼼히 봐주셔서 감사합니다!

@kleekich21 kleekich21 merged commit 4b6ff28 into main Jul 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants