eureka-init 1.0.5 → 1.1.0

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/.eslintrc.js ADDED
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: true,
4
+ es2021: true,
5
+ node: true,
6
+ },
7
+ extends: [
8
+ 'eslint:recommended',
9
+ 'plugin:prettier/recommended',
10
+ ],
11
+ parserOptions: {
12
+ ecmaVersion: 'latest',
13
+ sourceType: 'module',
14
+ },
15
+ rules: {
16
+ 'no-console': 'warn',
17
+ 'prettier/prettier': 'error',
18
+ },
19
+ };
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no -- commitlint --edit $1
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run lint
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 80,
6
+ "tabWidth": 2,
7
+ "useTabs": false
8
+ }
package/README.md CHANGED
Binary file
@@ -29,6 +29,10 @@ function setup() {
29
29
  path.join(templateDir, '.eslintrc.js'),
30
30
  path.join(cwd, '.eslintrc.js')
31
31
  );
32
+ copyFile(
33
+ path.join(templateDir, 'lint-staged.config.js'),
34
+ path.join(cwd, 'lint-staged.config.js')
35
+ );
32
36
  copyFile(
33
37
  path.join(templateDir, 'jest.config.js'),
34
38
  path.join(cwd, 'jest.config.js')
@@ -97,6 +101,9 @@ function setup() {
97
101
  if (!pkg.scripts.test) {
98
102
  pkg.scripts.test = 'jest --passWithNoTests';
99
103
  }
104
+ if (!pkg.scripts['lint-staged']) {
105
+ pkg.scripts['lint-staged'] = 'lint-staged';
106
+ }
100
107
 
101
108
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
102
109
  console.log('✅ Updated package.json scripts');
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'type-enum': [
5
+ 2,
6
+ 'always',
7
+ ['feat', 'fix', 'refactor', 'chore', 'docs', 'test']
8
+ ],
9
+ 'subject-case': [2, 'always', 'lower-case'],
10
+ 'subject-min-length': [2, 'always', 10],
11
+ 'subject-max-length': [2, 'always', 100],
12
+ 'subject-full-stop': [2, 'never', '.']
13
+ }
14
+ };
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
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
+ testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
11
+ modulePathIgnorePatterns: ['<rootDir>/.next/'],
12
+ };
package/jest.setup.js ADDED
@@ -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
+ }));
package/package.json CHANGED
@@ -1,19 +1,24 @@
1
1
  {
2
2
  "name": "eureka-init",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
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"
8
8
  },
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "prepare": "husky install",
12
+ "lint": "eslint .",
13
+ "format": "prettier --write ."
11
14
  },
12
15
  "keywords": [
13
16
  "husky",
14
17
  "commitlint",
15
18
  "prettier",
16
- "eureka"
19
+ "eureka",
20
+ "lint-staged",
21
+ "eslint-plugin-react"
17
22
  ],
18
23
  "author": "Eureka Group",
19
24
  "license": "ISC",
@@ -26,10 +31,12 @@
26
31
  "eslint": "^8.57.0",
27
32
  "eslint-config-prettier": "^9.1.0",
28
33
  "eslint-plugin-prettier": "^5.1.3",
34
+ "eslint-plugin-react": "^7.34.1",
29
35
  "husky": "^9.0.11",
36
+ "identity-obj-proxy": "^3.0.0",
30
37
  "jest": "^29.7.0",
31
38
  "jest-environment-jsdom": "^29.7.0",
32
- "identity-obj-proxy": "^3.0.0",
39
+ "lint-staged": "^15.2.2",
33
40
  "prettier": "^3.2.5"
34
41
  }
35
- }
42
+ }
@@ -0,0 +1,11 @@
1
+ describe('Contoh Unit Test', () => {
2
+ test('Sistem Testing Eureka Init harus berjalan', () => {
3
+ const sum = (a, b) => a + b;
4
+ expect(sum(1, 2)).toBe(3);
5
+ });
6
+
7
+ test('Lingkungan JSDOM harus tersedia', () => {
8
+ const element = document.createElement('div');
9
+ expect(element).not.toBeNull();
10
+ });
11
+ });
@@ -6,14 +6,23 @@ module.exports = {
6
6
  },
7
7
  extends: [
8
8
  'eslint:recommended',
9
+ 'plugin:react/recommended',
9
10
  'plugin:prettier/recommended',
10
11
  ],
12
+ plugins: ['react'],
11
13
  parserOptions: {
12
14
  ecmaVersion: 'latest',
13
15
  sourceType: 'module',
14
16
  },
17
+ settings: {
18
+ react: {
19
+ version: 'detect',
20
+ },
21
+ },
15
22
  rules: {
16
23
  'no-console': 'warn',
17
24
  'prettier/prettier': 'error',
25
+ 'react/react-in-jsx-scope': 'off',
26
+ 'react/prop-types': 'off',
18
27
  },
19
28
  };
@@ -1,4 +1,4 @@
1
1
  #!/bin/sh
2
2
  . "$(dirname "$0")/_/husky.sh"
3
3
 
4
- npm run lint
4
+ npx lint-staged
@@ -1,4 +1,4 @@
1
- import '@testing-library/jest-dom';
1
+ require('@testing-library/jest-dom');
2
2
 
3
3
  /**
4
4
  * Mock window.matchMedia (Diperlukan untuk Ant Design dan responsive components)
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ // eslint --fix sudah otomatis menjalankan Prettier sekaligus memperbaiki linter
3
+ '*.{js,jsx,ts,tsx}': ['eslint --fix'],
4
+ // File non-JS/TS tetap menggunakan prettier secara langsung
5
+ '*.{json,css,scss,md}': ['prettier --write'],
6
+ };