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
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ea9f003
feat: project setup typescript, jest, babel installed
kleekich21 Jun 19, 2024
1304812
chore: add .gitignore file
kleekich21 Jun 19, 2024
736d691
chore: appy ignore files
kleekich21 Jun 19, 2024
d8ea175
chore: update package.json for script using npm. Now, pnpm is used. m…
kleekich21 Jun 19, 2024
e8e38a4
chore: eslint is installed and config file is added
kleekich21 Jun 19, 2024
21d56f3
chore: add additional configs recommended by typescript-eslint
kleekich21 Jun 19, 2024
4de26c8
chore: fix scirpt for eslint
kleekich21 Jun 19, 2024
e6ea7b9
test: setup jest with ts-jest instead of babel
kleekich21 Jun 19, 2024
9e146c0
feat: make boilerplate file for deeplyCopy
kleekich21 Jun 19, 2024
f649e03
test: add test cases
kleekich21 Jun 19, 2024
7ef9050
chore: cleanup
kleekich21 Jun 19, 2024
36ea769
chore: Update README
kleekich21 Jun 20, 2024
e903d81
chore: add github actions
kleekich21 Jun 20, 2024
105697d
chore: update github actions file to use pnpm
kleekich21 Jun 20, 2024
1acf714
chore: remove on push because first PR fails tests due to TDD
kleekich21 Jun 20, 2024
a49aef7
chore: update target branch for pull_request to "main"
kleekich21 Jun 20, 2024
8488cee
chore: support dual CJS and ESM
kleekich21 Jun 20, 2024
286a806
fix: import error path
kleekich21 Jun 21, 2024
6d6fea8
chore: install prettier
kleekich21 Jun 21, 2024
8bc6b59
chore: add eslint-config-prettier plugin to turn off all rules confli…
kleekich21 Jun 21, 2024
10fa9a0
chore: update script for eslint fix
kleekich21 Jun 21, 2024
5309b6a
refactor: use ESM for exporting babel.config.js
kleekich21 Jun 21, 2024
ce8cf22
style: prettier 룰 적용
kleekich21 Jun 21, 2024
2f56ff4
chore: add build:clean script and update packages
kleekich21 Jun 22, 2024
0de589e
test: remove import jest functions by adding @types/jest
kleekich21 Jun 22, 2024
e7f5606
chore: update lock file
kleekich21 Jun 22, 2024
59f6a0c
chore: switch config module and moduleResolution value for build
kleekich21 Jun 22, 2024
94d663a
test: test script change target path
kleekich21 Jun 22, 2024
4acee48
fix: path updated
kleekich21 Jun 22, 2024
bc52d64
Update run-test-actions.yml
kleekich21 Jun 22, 2024
ce5c519
Update run-test-actions.yml
kleekich21 Jun 22, 2024
0712d1f
fix: import error
kleekich21 Jun 23, 2024
d9930b6
chore: update file structure to support dual package
kleekich21 Jun 23, 2024
5f4442e
chore: update jest config for setting ./src to test
kleekich21 Jun 23, 2024
6721aa9
chore: add prettier plugin to eslint config
kleekich21 Jun 25, 2024
57e3e51
1.0.1-canary.0
kleekich21 Jun 25, 2024
515582b
chore: add build directory for publish
kleekich21 Jun 26, 2024
6c2ac4c
1.0.1-canary.1
kleekich21 Jun 26, 2024
3c5e096
chore: add types directory path
kleekich21 Jun 26, 2024
c2e19af
chore: add .npmignore
kleekich21 Jun 26, 2024
ece442e
1.0.1-canary.3.0
kleekich21 Jun 26, 2024
cfb0aa5
chore: add package.json to .npmignore
kleekich21 Jun 26, 2024
8290f54
1.0.1-canary.4.0
kleekich21 Jun 26, 2024
3f7a41d
chore: add type declaration to esm and cjs build directory
kleekich21 Jul 2, 2024
b65fb92
chore: update import entry points according to updating build directory
kleekich21 Jul 2, 2024
059b43a
chore: add test file to ignore
kleekich21 Jul 2, 2024
6f43cae
chore: update build files
kleekich21 Jul 2, 2024
268bd78
1.0.1-canary.5.0
kleekich21 Jul 2, 2024
194b832
chore: add ./package.json entry point to use to most package.json file
kleekich21 Jul 2, 2024
4661b1e
1.0.1-canary.6.0
kleekich21 Jul 2, 2024
772cf2e
chore: assign different package.json entry point for cjs and esm
kleekich21 Jul 2, 2024
76f861d
1.0.1-canary.7.0
kleekich21 Jul 2, 2024
ec7bb7f
chore: add renameFiles to change extension from .js to .cjs
kleekich21 Jul 2, 2024
6060781
1.0.1-canary.8.0
kleekich21 Jul 2, 2024
c1ae79c
chore: fix extension for cjs
kleekich21 Jul 2, 2024
31c55fa
1.0.1-canary.9.0
kleekich21 Jul 2, 2024
a8e836b
chore: implement renameFiles as typescript, and update script accordi…
kleekich21 Jul 2, 2024
765bc20
chore: update packages
kleekich21 Jul 2, 2024
90f1799
1.0.1-canary.10.0
kleekich21 Jul 2, 2024
1a30259
chore: chore: use ts-node as loader to run renameFiles.ts
kleekich21 Jul 2, 2024
00ed5cb
1.0.1-canary.11.0
kleekich21 Jul 2, 2024
96456c3
chore: add build directory
kleekich21 Jul 2, 2024
79dccb5
chore: apply minor changes
kleekich21 Jul 4, 2024
4099d42
chore: remove build folder
kleekich21 Jul 4, 2024
4195f40
chore: cleanup project
kleekich21 Jul 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Node.js 관련 무시 파일
node_modules/
npm-debug.log

# OS별 무시 파일
.DS_Store
Thumbs.db

# 특정 IDE 및 편집기 관련 무시 파일
.vscode/
.idea/

# 로그 파일
*.log

# 환경 설정 파일
.env

# 빌드 디렉토리
dist/
build/
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [["@babel/preset-env", { targets: { node: "current" } }]],
};
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.strict,
...tseslint.configs.stylistic
);
96 changes: 96 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { describe, expect, jest, test } from "@jest/globals";
import { deeplyCopy } from "./index";

describe("deeplyCopy", () => {
test("primitive type을 복사한다. ", () => {
expect(deeplyCopy(12)).toBe(12);
expect(deeplyCopy("dummy")).toBe("dummy");
expect(deeplyCopy(false)).toBe(false);
expect(deeplyCopy(undefined)).toBe(undefined);
expect(deeplyCopy(null)).toBeNull();
expect(deeplyCopy(Symbol("foo"))).toBe("foo");
});
test("단일 레벨 객체를 복사한다.", () => {
const obj = { a: "foo", b: "bar" };
const copied = deeplyCopy(obj);
expect(copied).toEqual(obj);
expect(copied).not.toBe(obj);
});
test("단일 레벨 배열을 복사한다.", () => {
const arr = [1, 2, 3];
const copied = deeplyCopy(arr);
expect(copied).toEqual(arr);
expect(copied).not.toBe(arr);
});
test("중첩 객체를 내부까지 복사한다.", () => {
const nestedObj = { a: { b: "foo" }, c: { d: { e: "bar" }, f: "baz" } };
const copied = deeplyCopy(nestedObj);
expect(copied).toEqual(nestedObj);
expect(copied).not.toBe(nestedObj);
});
test("중첩 배열을 내부까지 복사한다.", () => {
const nestedArr = [[0], [[1], [2]], [[[3]]]];
const copied = deeplyCopy(nestedArr);
expect(copied).toEqual(nestedArr);
expect(copied).not.toBe(nestedArr);
expect(copied[1]).toEqual(nestedArr[1]);
expect(copied[1]).not.toBe(nestedArr[1]);
expect(copied[1][0]).toEqual(nestedArr[1][0]);
expect(copied[1][0]).not.toBe(nestedArr[1][0]);
});
test("배열을 프로퍼티로 포함한 객체를 복사한다.", () => {
const nestedObj = { a: [1, 2], c: { d: { e: [3] }, f: [4, 5] } };
const copied = deeplyCopy(nestedObj);
expect(copied).toEqual(nestedObj);
expect(copied).not.toBe(nestedObj);
expect(copied.a).toEqual(nestedObj.a);
expect(copied.a).not.toBe(nestedObj.a);
expect(copied.c.d.e).toEqual(nestedObj.c.d.e);
expect(copied.c.d.e).not.toBe(nestedObj.c.d.e);
});
test("객체를 요소로 포함한 배열을 복사한다.", () => {
const nestedArr = [{ a: 1 }, { b: "foo" }, { c: ["bar", "baz"] }];
const copied = deeplyCopy(nestedArr);
expect(copied).toEqual(nestedArr);
expect(copied).not.toBe(nestedArr);
expect(copied[0]).toEqual(nestedArr[0]);
expect(copied[2]).not.toBe(nestedArr[2]);
});
test("사이클이 있는 객체를 복사한다.", () => {
const obj: any = {};
obj.a = obj;
const copied = deeplyCopy(obj);
expect(copied).not.toBe(obj);
expect(copied.a).toBe(copied);
});
test("사이클이 있는 배열을 복사한다.", () => {
const arr: any = [];
arr.push(arr);
const copied = deeplyCopy(arr);
expect(copied).toEqual(arr);
expect(copied).not.toEqual(arr);
});
test("클래스 인스턴스를 복사한다.", () => {
class Node {
val: number;
next: Node | null = null;

constructor(val: number) {
this.val = val;
}
}

let node1 = new Node(1);
let node2 = new Node(2);
node1.next = node2;
node2.next = node1;

const copiedNode1 = deeplyCopy(node1);

expect(copiedNode1).toEqual(node1);
expect(copiedNode1).not.toBe(node1);
expect(copiedNode1.next).toEqual(node2);
expect(copiedNode1.next).not.toBe(node2);
expect(copiedNode1.next.next).toBe(copiedNode1); // check circular reference
});
});
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function deeplyCopy(target: any): any {}
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
};
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "deeply-copy",
"version": "1.0.0",
"description": "custom deep copy function to make a brand new immutable object",
"main": "index.js",
"type": "module",
"scripts": {
"test": "jest",
"build": "pnpm tsc",
"build:watch": "pnpm tsc -w",
"eslint": "npx eslint ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/f-lab-edu/deeply-copy.git"
},
"keywords": [
"deepCopy",
"deepClone"
],
"author": "Kangsik Kevin Lee",
"license": "ISC",
"bugs": {
"url": "https://github.com/f-lab-edu/deeply-copy/issues"
},
"homepage": "https://github.com/f-lab-edu/deeply-copy#readme",
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@eslint/js": "^9.5.0",
"@jest/globals": "^29.7.0",
"@types/eslint__js": "^8.42.3",
"babel-jest": "^29.7.0",
"eslint": "^9.5.0",
"jest": "^29.7.0",
"ts-jest": "^29.1.5",
"typescript": "^5.4.5",
"typescript-eslint": "^7.13.1"
}
}
Loading