eureka-init 1.0.3 → 1.0.6
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 +19 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.prettierrc +8 -0
- package/bin/eureka-init.js +11 -1
- package/commitlint.config.js +14 -0
- package/jest.config.js +12 -0
- package/jest.setup.js +114 -0
- package/package.json +9 -3
- package/src/__tests__/example.test.js +11 -0
- package/templates/example.test.js +11 -0
- package/templates/jest.setup.js +1 -1
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
|
+
};
|
package/.prettierrc
ADDED
package/bin/eureka-init.js
CHANGED
|
@@ -38,6 +38,16 @@ function setup() {
|
|
|
38
38
|
path.join(cwd, 'jest.setup.js')
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
+
// 1a. Create example test in src/__tests__
|
|
42
|
+
const testDir = path.join(cwd, 'src', '__tests__');
|
|
43
|
+
if (!fs.existsSync(testDir)) {
|
|
44
|
+
fs.mkdirSync(testDir, { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
copyFile(
|
|
47
|
+
path.join(templateDir, 'example.test.js'),
|
|
48
|
+
path.join(testDir, 'example.test.js')
|
|
49
|
+
);
|
|
50
|
+
|
|
41
51
|
// 2. Initialize Husky
|
|
42
52
|
try {
|
|
43
53
|
console.log('📦 Setting up Husky...');
|
|
@@ -85,7 +95,7 @@ function setup() {
|
|
|
85
95
|
pkg.scripts.format = 'prettier --write .';
|
|
86
96
|
}
|
|
87
97
|
if (!pkg.scripts.test) {
|
|
88
|
-
pkg.scripts.test = 'jest';
|
|
98
|
+
pkg.scripts.test = 'jest --passWithNoTests';
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
@@ -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,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eureka-init",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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",
|
|
@@ -20,6 +23,9 @@
|
|
|
20
23
|
"dependencies": {
|
|
21
24
|
"@commitlint/cli": "^19.3.0",
|
|
22
25
|
"@commitlint/config-conventional": "^19.2.2",
|
|
26
|
+
"@testing-library/jest-dom": "^6.4.2",
|
|
27
|
+
"@testing-library/react": "^14.2.1",
|
|
28
|
+
"@testing-library/user-event": "^14.5.2",
|
|
23
29
|
"eslint": "^8.57.0",
|
|
24
30
|
"eslint-config-prettier": "^9.1.0",
|
|
25
31
|
"eslint-plugin-prettier": "^5.1.3",
|
|
@@ -29,4 +35,4 @@
|
|
|
29
35
|
"identity-obj-proxy": "^3.0.0",
|
|
30
36
|
"prettier": "^3.2.5"
|
|
31
37
|
}
|
|
32
|
-
}
|
|
38
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -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
|
+
});
|
package/templates/jest.setup.js
CHANGED