eureka-init 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,9 +28,10 @@ Perintah ini akan:
28
28
  1. Membuat file `commitlint.config.js`.
29
29
  2. Membuat file `.prettierrc`.
30
30
  3. Membuat file `.eslintrc.js`.
31
- 4. Menjalankan `npx husky install`.
32
- 5. Membuat hook `.husky/commit-msg` dan `.husky/pre-commit`.
33
- 6. Menambahkan script `prepare`, `lint`, dan `format` di `package.json`.
31
+ 4. Membuat file `jest.config.js` dan `jest.setup.js`.
32
+ 5. Menjalankan `npx husky install`.
33
+ 6. Membuat hook `.husky/commit-msg` dan `.husky/pre-commit`.
34
+ 7. Menambahkan script `prepare`, `lint`, `format`, dan `test` di `package.json`.
34
35
 
35
36
  ## 🧱 Format Commit
36
37
  Gunakan format: `<type>: <subject>`
@@ -53,3 +54,4 @@ Gunakan format: `<type>: <subject>`
53
54
  Setelah instalasi, Anda bisa menggunakan:
54
55
  - `npm run lint`: Menjalankan eslint.
55
56
  - `npm run format`: Menjalankan prettier untuk merapikan kode.
57
+ - `npm run test`: Menjalankan unit test menggunakan Jest.
@@ -29,6 +29,14 @@ function setup() {
29
29
  path.join(templateDir, '.eslintrc.js'),
30
30
  path.join(cwd, '.eslintrc.js')
31
31
  );
32
+ copyFile(
33
+ path.join(templateDir, 'jest.config.js'),
34
+ path.join(cwd, 'jest.config.js')
35
+ );
36
+ copyFile(
37
+ path.join(templateDir, 'jest.setup.js'),
38
+ path.join(cwd, 'jest.setup.js')
39
+ );
32
40
 
33
41
  // 2. Initialize Husky
34
42
  try {
@@ -76,6 +84,9 @@ function setup() {
76
84
  if (!pkg.scripts.format) {
77
85
  pkg.scripts.format = 'prettier --write .';
78
86
  }
87
+ if (!pkg.scripts.test) {
88
+ pkg.scripts.test = 'jest';
89
+ }
79
90
 
80
91
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
81
92
  console.log('✅ Updated package.json scripts');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eureka-init",
3
- "version": "1.0.0",
4
- "description": "Shared configuration for Husky, Commitlint, and Prettier for Eureka Group",
3
+ "version": "1.0.2",
4
+ "description": "Shared configuration for Husky, Commitlint, Prettier, ESLint, and Jest for Eureka Group",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "eureka-init": "bin/eureka-init.js"
@@ -24,6 +24,9 @@
24
24
  "eslint-config-prettier": "^9.1.0",
25
25
  "eslint-plugin-prettier": "^5.1.3",
26
26
  "husky": "^9.0.11",
27
+ "jest": "^29.7.0",
28
+ "jest-environment-jsdom": "^29.7.0",
29
+ "identity-obj-proxy": "^3.0.0",
27
30
  "prettier": "^3.2.5"
28
31
  }
29
32
  }
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ testEnvironment: 'jsdom',
3
+ collectCoverage: true,
4
+ coverageDirectory: 'coverage',
5
+ moduleNameMapper: {
6
+ '\\.(css|less|scss|sass)$': 'identity-obj-proxy',
7
+ },
8
+ setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
9
+ testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
10
+ };
@@ -0,0 +1,114 @@
1
+ import '@testing-library/jest-dom';
2
+
3
+ /**
4
+ * Mock window.matchMedia (Diperlukan untuk Ant Design dan responsive components)
5
+ */
6
+ Object.defineProperty(window, 'matchMedia', {
7
+ writable: true,
8
+ value: jest.fn().mockImplementation((query) => ({
9
+ matches: false,
10
+ media: query,
11
+ onchange: null,
12
+ addListener: jest.fn(), // deprecated
13
+ removeListener: jest.fn(), // deprecated
14
+ addEventListener: jest.fn(),
15
+ removeEventListener: jest.fn(),
16
+ dispatchEvent: jest.fn(),
17
+ })),
18
+ });
19
+
20
+ /**
21
+ * Mock IntersectionObserver (Biasanya digunakan untuk lazy loading image)
22
+ */
23
+ global.IntersectionObserver = class IntersectionObserver {
24
+ constructor() { }
25
+ observe() { }
26
+ unobserve() { }
27
+ disconnect() { }
28
+ };
29
+
30
+ /**
31
+ * Mock ResizeObserver (Dibutuhkan untuk Framer Motion dan UI responsif)
32
+ */
33
+ global.ResizeObserver = class ResizeObserver {
34
+ constructor() { }
35
+ observe() { }
36
+ unobserve() { }
37
+ disconnect() { }
38
+ };
39
+
40
+ /**
41
+ * Mock window.scrollTo (Penting untuk alur checkout/pembelian)
42
+ */
43
+ Object.defineProperty(window, 'scrollTo', {
44
+ value: () => { },
45
+ writable: true
46
+ });
47
+
48
+ /**
49
+ * Mock Next.js Navigation (useRouter, usePathname, dll)
50
+ */
51
+ jest.mock('next/navigation', () => ({
52
+ useRouter: () => ({
53
+ push: jest.fn(),
54
+ replace: jest.fn(),
55
+ prefetch: jest.fn(),
56
+ back: jest.fn(),
57
+ }),
58
+ usePathname: () => '',
59
+ useSearchParams: () => new URLSearchParams(),
60
+ }));
61
+
62
+ /**
63
+ * Mock SweetAlert2 (Sering digunakan di project Eureka)
64
+ */
65
+ jest.mock('sweetalert2', () => ({
66
+ fire: jest.fn().mockResolvedValue({ isConfirmed: true }),
67
+ }));
68
+
69
+ /**
70
+ * Mock LocalStorage
71
+ */
72
+ const localStorageMock = (function () {
73
+ let store = {};
74
+ return {
75
+ getItem: (key) => store[key] || null,
76
+ setItem: (key, value) => {
77
+ store[key] = value.toString();
78
+ },
79
+ removeItem: (key) => {
80
+ delete store[key];
81
+ },
82
+ clear: () => {
83
+ store = {};
84
+ },
85
+ };
86
+ })();
87
+
88
+ Object.defineProperty(window, 'localStorage', {
89
+ value: localStorageMock,
90
+ });
91
+
92
+ /**
93
+ * Mock Fetch API
94
+ */
95
+ global.fetch = jest.fn(() =>
96
+ Promise.resolve({
97
+ json: () => Promise.resolve({}),
98
+ })
99
+ );
100
+
101
+ /**
102
+ * Mock Axios (Standar alur pembelian di Eureka Group)
103
+ */
104
+ jest.mock('axios', () => ({
105
+ get: jest.fn(() => Promise.resolve({ data: {} })),
106
+ post: jest.fn(() => Promise.resolve({ data: {} })),
107
+ put: jest.fn(() => Promise.resolve({ data: {} })),
108
+ delete: jest.fn(() => Promise.resolve({ data: {} })),
109
+ create: jest.fn(function () { return this; }),
110
+ interceptors: {
111
+ request: { use: jest.fn(), eject: jest.fn() },
112
+ response: { use: jest.fn(), eject: jest.fn() },
113
+ },
114
+ }));