@dannysir/js-te 0.2.2 → 0.3.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/README.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  Jest에서 영감을 받아 만든 가벼운 JavaScript 테스트 프레임워크입니다.
4
4
 
5
+
6
+ ## [📎 최근 업데이트 0.3.0v](https://github.com/dannysir/js-te-package/blob/main/CHANGELOG.md)
7
+
8
+
9
+ ### `mock` 이후 import를 해야하는 문제 해결
10
+ - 문제 : 기존의 경우 모킹 기능 이용시 반드시 동적 import문을 mock 다음에 작성해야 했음
11
+ - 해결
12
+ - 기존 `mockStore`를 직접 비교하여 import하는 방식에서 wrapper 패턴을 이용하도록 적용
13
+ - 모듈을 새로운 함수로 만들어 함수를 실행할 때마다 `mockStore`와 비교하여 값을 리턴하도록 수정
14
+ ### 모듈 변환 최적화
15
+ - 문제 : 앞선 변경으로 인해 모든 파일의 모듈들이 사용될 때마다 `mockStore`와 비교하는 로직이 실행됨
16
+ - 해결
17
+ - `cli`로직에 mock을 미리 검사하여 mock 경로를 미리 저장하는 로직을 추가
18
+ - 미리 확인한 mock 경로를 이용해 import문이 만약 저장된 경로일 때만 babel 변환
19
+
20
+ ---
5
21
  ## 설치
6
22
 
7
23
  ```bash
@@ -29,10 +45,12 @@ describe('[단순 연산 테스트]', () => {
29
45
 
30
46
  package.json에 추가.
31
47
 
32
- - type을 module로 설정해주세요.
48
+ - ~~type을 module로 설정해주세요.~~
49
+ > ✅ 0.2.1 버전부터 common js 방식을 지원합니다.
50
+
33
51
  ```json
34
52
  {
35
- "type": "module",
53
+ "type": "module", // 0.2.1 버전부터 common js도 사용 가능
36
54
  "scripts": {
37
55
  "test": "js-te"
38
56
  }
@@ -133,10 +151,23 @@ Babel을 사용해서 import/require 구문을 변환하여 mock 함수를 가
133
151
  1. `mock(path, mockObj)` 선언 확인
134
152
  2. `path`를 key로 이용해 Map에 저장
135
153
  2. Babel로 코드 변환
136
- 1. 전체 파일의 import/require문 확인
137
- 2. (0.0.3 버전 추가) import 경로를 **절대 경로**로 변환
138
- 2. import 경로(절대 경로)가 Map에 존재하면 mock 객체로 변환
139
- 3. import 경로(절대 경로) Map에 없다면 그대로 import
154
+ ```jsx
155
+ // 0.3.0 버전 이후
156
+ const _original = await import('./random.js');
157
+ const random = (...args) => {
158
+ const module = mockStore.has('/path/to/random.js')
159
+ ? { ..._original, ...mockStore.get('/path/to/random.js') }
160
+ : _original;
161
+ return module.random(...args);
162
+ };
163
+
164
+ // 0.3.0 버전 이전
165
+ const _original = await import('./random.js');
166
+ const _module = mockStore.has('/path/to/random.js')
167
+ ? { ..._original, ...mockStore.get('/path/to/random.js') }
168
+ : _original;
169
+ const {random1, random2} = _module;
170
+ ```
140
171
  3. 테스트 실행
141
172
  4. 원본 파일 복구
142
173
 
@@ -148,8 +179,10 @@ Babel을 사용해서 import/require 구문을 변환하여 mock 함수를 가
148
179
 
149
180
  1. 반드시 경로는 절대 경로로 입력해주세요.
150
181
  - babel이 import문에서 절대 경로로 변환하여 확인을 하기 때문에 반드시 절대 경로로 등록해주세요.
151
- 2. import문을 반드시 mocking 이후에 선언해주세요.
152
- - mocking 전에 import를 하게 되면 mocking되기 전의 모듈을 가져오게 됩니다.
182
+ 2. ~~import문을 반드시 mocking 이후에 선언해주세요.~~
183
+ - ~~mocking 전에 import를 하게 되면 mocking되기 전의 모듈을 가져오게 됩니다.~~
184
+
185
+ > **0.3.0 버전부터 import문을 mock선언 이후에 하지 않아도 됩니다.**
153
186
 
154
187
  **💡 부분 모킹(Partial Mocking)**
155
188
 
@@ -162,14 +195,13 @@ export const subtract = (a, b) => a - b;
162
195
  export const multiply = (a, b) => a * b;
163
196
 
164
197
  // math.test.js
198
+ const { add, multiply } = import('./math.js'); // 0.3.0 버전부터는 최상단에 선언 가능
199
+
165
200
  test('부분 모킹 예제', async () => {
166
- // multiply만 모킹하고 add, subtract는 원본 사용
167
- mock('/Users/san/Js-Te/math.js', {
168
- multiply: () => 100 // multiply만 모킹
201
+ mock('/Users/san/untitled/index.js', {
202
+ multiply: () => 100
169
203
  });
170
204
 
171
- const { add, subtract, multiply } = await import('./math.js');
172
-
173
205
  expect(add(2, 3)).toBe(5); // 원본 함수 사용
174
206
  expect(subtract(5, 3)).toBe(2); // 원본 함수 사용
175
207
  expect(multiply(2, 3)).toBe(100); // 모킹된 함수 사용
@@ -200,17 +232,15 @@ import { random } from './random.js'; // 자유롭게 import하면 babel에서
200
232
  export const play = () => random() * 10;
201
233
 
202
234
  // game.test.js
235
+ import {play} from './game.js';
236
+
203
237
  test('랜덤 함수 모킹', async () => {
204
238
  // 1. 먼저 모킹
205
239
  mock('/Users/san/Js-Te/test-helper/random.js', { // 반드시 절대 경로로 등록
206
240
  random: () => 0.5
207
241
  });
208
242
 
209
- // 2. 다음 import (CommonJS도 가능)
210
- const { play } = await import('./game.js');
211
- // 또는: const { play } = require('./game.js');
212
-
213
- // 3. 모킹된 값 사용
243
+ // 2. 모킹된 사용
214
244
  expect(play()).toBe(5);
215
245
  });
216
246
  ```
@@ -343,11 +373,14 @@ describe('문자열 테스트', () => {
343
373
  #### 전체 모킹
344
374
  ```javascript
345
375
  // mocking.test.js
376
+ import {random} from '../src/test-helper/game.js'; // 0.2.4 버전부터 import문 상단 배치 가능
377
+
346
378
  test('[mocking] - mocking random function', async () => {
347
379
  mock('/Users/san/Js-Te/test-helper/random.js', {
348
380
  random: () => 3,
349
381
  });
350
- const {play} = await import('../src/test-helper/game.js');
382
+ // 0.3.0 버전 이전까지는 반드시 mock 이후 동적 import문 작성
383
+ // const {play} = await import('../src/test-helper/game.js');
351
384
  expect(play()).toBe(30);
352
385
  });
353
386
 
@@ -387,10 +420,11 @@ test('[partial mocking] - mock only multiply', async () => {
387
420
  ## 링크
388
421
 
389
422
  - [GitHub](https://github.com/dannysir/Js-Te)
423
+ - [블로그 포스트](https://velog.io/@dannysir/series/npm-테스트-라이브러리-만들기)
390
424
 
391
425
  ## 만든 이유
392
426
 
393
- 우아한테크코스 과제하면서 Jest 써보고 테스트 프레임워크가 어떻게 동작하는지 궁금해서 만들어봤습니다.
427
+ Jest를 사용하며 JavaScript 테스트 라이브러리의 구조가 궁금하여 만들게 되었습니다.
394
428
 
395
429
  ## 라이선스
396
430
 
@@ -1,218 +1,317 @@
1
1
  import path from 'path';
2
2
  import {BABEL, MOCK} from "./constants.js";
3
3
 
4
- export const babelTransformImport = ({types: t}) => {
5
- return {
6
- visitor: {
7
- Program(path) {
8
- const mockStoreDeclaration = t.VariableDeclaration('const', [
9
- t.VariableDeclarator(
10
- t.Identifier(MOCK.STORE_NAME),
11
- t.MemberExpression(
12
- t.Identifier('global'),
13
- t.Identifier(MOCK.STORE_NAME)
4
+ export const babelTransformImport = (mockedPaths = null) => {
5
+ return ({types: t}) => {
6
+ return {
7
+ visitor: {
8
+ Program(path) {
9
+ const mockStoreDeclaration = t.VariableDeclaration('const', [
10
+ t.VariableDeclarator(
11
+ t.Identifier(MOCK.STORE_NAME),
12
+ t.MemberExpression(
13
+ t.Identifier('global'),
14
+ t.Identifier(MOCK.STORE_NAME)
15
+ )
14
16
  )
15
- )
16
- ]);
17
- path.node.body.unshift(mockStoreDeclaration);
18
- },
17
+ ]);
18
+ path.node.body.unshift(mockStoreDeclaration);
19
+ },
19
20
 
20
- ImportDeclaration(nodePath, state) {
21
- const source = nodePath.node.source.value;
21
+ ImportDeclaration(nodePath, state) {
22
+ const source = nodePath.node.source.value;
22
23
 
23
- if (source === MOCK.STORE_PATH) {
24
- return;
25
- }
24
+ if (source === MOCK.STORE_PATH) {
25
+ return;
26
+ }
26
27
 
27
- const currentFilePath = state.filename || process.cwd();
28
- const currentDir = path.dirname(currentFilePath);
28
+ const currentFilePath = state.filename || process.cwd();
29
+ const currentDir = path.dirname(currentFilePath);
29
30
 
30
- let absolutePath;
31
- if (source.startsWith(BABEL.PERIOD)) {
32
- absolutePath = path.resolve(currentDir, source);
33
- } else {
34
- absolutePath = source;
35
- }
31
+ let absolutePath;
32
+ if (source.startsWith(BABEL.PERIOD)) {
33
+ absolutePath = path.resolve(currentDir, source);
34
+ } else {
35
+ absolutePath = source;
36
+ }
36
37
 
37
- const specifiers = nodePath.node.specifiers;
38
+ if (mockedPaths && !mockedPaths.has(absolutePath)) {
39
+ return;
40
+ }
38
41
 
39
- const originalVarName = nodePath.scope.generateUidIdentifier('original');
40
- const moduleVarName = nodePath.scope.generateUidIdentifier(BABEL.MODULE);
42
+ const specifiers = nodePath.node.specifiers;
43
+ const originalVarName = nodePath.scope.generateUidIdentifier('original');
41
44
 
42
- /*
43
- Transformed code for partial mocking support in ESM:
45
+ /*
44
46
 
45
- const _original = await import('./random.js');
46
- const _module = mockStore.has('/path/to/random.js')
47
- ? { ..._original, ...mockStore.get('/path/to/random.js') }
48
- : _original;
49
- const {random1, random2} = _module;
50
- */
47
+ const _original = await import('./random.js');
48
+ const random = (...args) => {
49
+ const module = mockStore.has('/path/to/random.js')
50
+ ? { ..._original, ...mockStore.get('/path/to/random.js') }
51
+ : _original;
52
+ return module.random(...args);
53
+ };
54
+ */
51
55
 
52
- const originalDeclaration = t.variableDeclaration(BABEL.CONST, [
53
- t.variableDeclarator(
54
- originalVarName,
55
- t.awaitExpression(
56
- t.importExpression(t.stringLiteral(source))
56
+ const originalDeclaration = t.variableDeclaration(BABEL.CONST, [
57
+ t.variableDeclarator(
58
+ originalVarName,
59
+ t.awaitExpression(
60
+ t.importExpression(t.stringLiteral(source))
61
+ )
57
62
  )
58
- )
59
- ]);
60
-
61
- const moduleDeclaration = t.variableDeclaration(BABEL.CONST, [
62
- t.variableDeclarator(
63
- moduleVarName,
64
- t.conditionalExpression(
65
- t.callExpression(
66
- t.memberExpression(t.identifier(MOCK.STORE_NAME), t.identifier(BABEL.HAS)),
67
- [t.stringLiteral(absolutePath)]
68
- ),
69
- t.objectExpression([
70
- t.spreadElement(originalVarName),
71
- t.spreadElement(
63
+ ]);
64
+
65
+ const wrapperDeclarations = specifiers.map(spec => {
66
+ let importedName, localName;
67
+
68
+ if (t.isImportDefaultSpecifier(spec)) {
69
+ importedName = 'default';
70
+ localName = spec.local.name;
71
+ } else if (t.isImportNamespaceSpecifier(spec)) {
72
+ localName = spec.local.name;
73
+ return t.variableDeclarator(
74
+ t.identifier(localName),
75
+ t.conditionalExpression(
72
76
  t.callExpression(
73
- t.memberExpression(t.identifier(MOCK.STORE_NAME), t.identifier(BABEL.GET)),
77
+ t.memberExpression(t.identifier(MOCK.STORE_NAME), t.identifier(BABEL.HAS)),
74
78
  [t.stringLiteral(absolutePath)]
75
- )
79
+ ),
80
+ t.objectExpression([
81
+ t.spreadElement(originalVarName),
82
+ t.spreadElement(
83
+ t.callExpression(
84
+ t.memberExpression(t.identifier(MOCK.STORE_NAME), t.identifier(BABEL.GET)),
85
+ [t.stringLiteral(absolutePath)]
86
+ )
87
+ )
88
+ ]),
89
+ originalVarName
76
90
  )
77
- ]),
78
- originalVarName
79
- )
80
- )
81
- ]);
82
-
83
- const extractDeclarations = specifiers.map(spec => {
84
- let importedName, localName;
91
+ );
92
+ } else {
93
+ importedName = spec.imported.name;
94
+ localName = spec.local.name;
95
+ }
85
96
 
86
- if (t.isImportDefaultSpecifier(spec)) {
87
- importedName = 'default';
88
- localName = spec.local.name;
89
- } else if (t.isImportNamespaceSpecifier(spec)) {
90
- localName = spec.local.name;
91
97
  return t.variableDeclarator(
92
98
  t.identifier(localName),
93
- moduleVarName
99
+ t.arrowFunctionExpression(
100
+ [t.restElement(t.identifier('args'))],
101
+ t.blockStatement([
102
+ t.variableDeclaration(BABEL.CONST, [
103
+ t.variableDeclarator(
104
+ t.identifier(BABEL.MODULE),
105
+ t.conditionalExpression(
106
+ t.callExpression(
107
+ t.memberExpression(t.identifier(MOCK.STORE_NAME), t.identifier(BABEL.HAS)),
108
+ [t.stringLiteral(absolutePath)]
109
+ ),
110
+ t.objectExpression([
111
+ t.spreadElement(originalVarName),
112
+ t.spreadElement(
113
+ t.callExpression(
114
+ t.memberExpression(t.identifier(MOCK.STORE_NAME), t.identifier(BABEL.GET)),
115
+ [t.stringLiteral(absolutePath)]
116
+ )
117
+ )
118
+ ]),
119
+ originalVarName
120
+ )
121
+ )
122
+ ]),
123
+ t.returnStatement(
124
+ t.callExpression(
125
+ t.memberExpression(t.identifier(BABEL.MODULE), t.identifier(importedName)),
126
+ [t.spreadElement(t.identifier('args'))]
127
+ )
128
+ )
129
+ ])
130
+ )
94
131
  );
95
- } else {
96
- importedName = spec.imported.name;
97
- localName = spec.local.name;
98
- }
99
-
100
- return t.variableDeclarator(
101
- t.identifier(localName),
102
- t.memberExpression(moduleVarName, t.identifier(importedName))
103
- );
104
- });
132
+ });
105
133
 
106
- const extractDeclaration = t.variableDeclaration(BABEL.CONST, extractDeclarations);
107
-
108
- nodePath.replaceWithMultiple([originalDeclaration, moduleDeclaration, extractDeclaration]);
109
- },
110
-
111
- VariableDeclaration(nodePath, state) {
112
- const declarations = nodePath.node.declarations;
113
-
114
- if (!declarations || declarations.length === 0) {
115
- return;
116
- }
117
-
118
- if (nodePath.node._transformed) {
119
- return;
120
- }
134
+ const wrapperDeclaration = t.variableDeclaration(BABEL.CONST, wrapperDeclarations);
121
135
 
122
- const newDeclarations = [];
123
- let hasTransformation = false;
136
+ nodePath.replaceWithMultiple([originalDeclaration, wrapperDeclaration]);
137
+ },
124
138
 
125
- for (const declarator of declarations) {
126
- const init = declarator.init;
139
+ VariableDeclaration(nodePath, state) {
140
+ const declarations = nodePath.node.declarations;
127
141
 
128
- if (!init ||
129
- !t.isCallExpression(init) ||
130
- !t.isIdentifier(init.callee, { name: 'require' }) ||
131
- !init.arguments[0] ||
132
- !t.isStringLiteral(init.arguments[0])) {
133
- newDeclarations.push(declarator);
134
- continue;
142
+ if (!declarations || declarations.length === 0) {
143
+ return;
135
144
  }
136
145
 
137
- hasTransformation = true;
138
- const source = init.arguments[0].value;
139
- const currentFilePath = state.filename || process.cwd();
140
- const currentDir = path.dirname(currentFilePath);
141
-
142
- let absolutePath;
143
- if (source.startsWith(BABEL.PERIOD)) {
144
- absolutePath = path.resolve(currentDir, source);
145
- } else {
146
- absolutePath = source;
147
- }
146
+ if (nodePath.node._transformed) {
147
+ return;
148
+ }
148
149
 
149
- /*
150
- Transformed code for partial mocking support:
150
+ const newDeclarations = [];
151
+ let hasTransformation = false;
152
+
153
+ for (const declarator of declarations) {
154
+ const init = declarator.init;
155
+
156
+ if (!init ||
157
+ !t.isCallExpression(init) ||
158
+ !t.isIdentifier(init.callee, {name: 'require'}) ||
159
+ !init.arguments[0] ||
160
+ !t.isStringLiteral(init.arguments[0])) {
161
+ newDeclarations.push(declarator);
162
+ continue;
163
+ }
164
+
165
+ const source = init.arguments[0].value;
166
+ const currentFilePath = state.filename || process.cwd();
167
+ const currentDir = path.dirname(currentFilePath);
168
+
169
+ let absolutePath;
170
+ if (source.startsWith(BABEL.PERIOD)) {
171
+ absolutePath = path.resolve(currentDir, source);
172
+ } else {
173
+ absolutePath = source;
174
+ }
175
+
176
+ if (mockedPaths && !mockedPaths.has(absolutePath)) {
177
+ newDeclarations.push(declarator);
178
+ continue;
179
+ }
180
+
181
+ hasTransformation = true;
182
+ const originalVar = nodePath.scope.generateUidIdentifier('original');
183
+
184
+ /*
185
+
186
+ const _original = require('./random');
187
+ const random = (...args) => {
188
+ const module = mockStore.has('/path/to/random.js')
189
+ ? { ..._original, ...mockStore.get('/path/to/random.js') }
190
+ : _original;
191
+ return module.random(...args);
192
+ };
193
+ */
151
194
 
152
- const _original = require('./random');
153
- const _module = mockStore.has('/path/to/random.js')
154
- ? { ..._original, ...mockStore.get('/path/to/random.js') }
155
- : _original;
156
- */
157
-
158
- const originalVar = nodePath.scope.generateUidIdentifier('original');
159
- const originalDeclarator = t.variableDeclarator(
160
- originalVar,
161
- t.callExpression(
162
- t.identifier('require'),
163
- [t.stringLiteral(source)]
164
- )
165
- );
166
-
167
- const transformedRequire = t.conditionalExpression(
168
- t.callExpression(
169
- t.memberExpression(
170
- t.identifier(MOCK.STORE_NAME),
171
- t.identifier(BABEL.HAS)
172
- ),
173
- [t.stringLiteral(absolutePath)]
174
- ),
175
- t.objectExpression([
176
- t.spreadElement(originalVar),
177
- t.spreadElement(
195
+ newDeclarations.push(
196
+ t.variableDeclarator(
197
+ originalVar,
178
198
  t.callExpression(
179
- t.memberExpression(
180
- t.identifier(MOCK.STORE_NAME),
181
- t.identifier(BABEL.GET)
182
- ),
183
- [t.stringLiteral(absolutePath)]
199
+ t.identifier('require'),
200
+ [t.stringLiteral(source)]
184
201
  )
185
202
  )
186
- ]),
187
- originalVar
188
- );
189
-
190
- if (t.isObjectPattern(declarator.id) || t.isArrayPattern(declarator.id)) {
191
- const tempVar = nodePath.scope.generateUidIdentifier('module');
192
-
193
- newDeclarations.push(originalDeclarator);
194
-
195
- newDeclarations.push(
196
- t.variableDeclarator(tempVar, transformedRequire)
197
203
  );
198
204
 
199
- newDeclarations.push(
200
- t.variableDeclarator(declarator.id, tempVar)
201
- );
202
- } else {
203
- newDeclarations.push(originalDeclarator);
204
-
205
- newDeclarations.push(
206
- t.variableDeclarator(declarator.id, transformedRequire)
207
- );
205
+ if (t.isObjectPattern(declarator.id)) {
206
+ const properties = declarator.id.properties;
207
+
208
+ properties.forEach(prop => {
209
+ const key = prop.key.name;
210
+ const localName = prop.value.name;
211
+
212
+ newDeclarations.push(
213
+ t.variableDeclarator(
214
+ t.identifier(localName),
215
+ t.arrowFunctionExpression(
216
+ [t.restElement(t.identifier('args'))],
217
+ t.blockStatement([
218
+ t.variableDeclaration(BABEL.CONST, [
219
+ t.variableDeclarator(
220
+ t.identifier(BABEL.MODULE),
221
+ t.conditionalExpression(
222
+ t.callExpression(
223
+ t.memberExpression(
224
+ t.identifier(MOCK.STORE_NAME),
225
+ t.identifier(BABEL.HAS)
226
+ ),
227
+ [t.stringLiteral(absolutePath)]
228
+ ),
229
+ t.objectExpression([
230
+ t.spreadElement(originalVar),
231
+ t.spreadElement(
232
+ t.callExpression(
233
+ t.memberExpression(
234
+ t.identifier(MOCK.STORE_NAME),
235
+ t.identifier(BABEL.GET)
236
+ ),
237
+ [t.stringLiteral(absolutePath)]
238
+ )
239
+ )
240
+ ]),
241
+ originalVar
242
+ )
243
+ )
244
+ ]),
245
+ t.returnStatement(
246
+ t.callExpression(
247
+ t.memberExpression(
248
+ t.identifier(BABEL.MODULE),
249
+ t.identifier(key)
250
+ ),
251
+ [t.spreadElement(t.identifier('args'))]
252
+ )
253
+ )
254
+ ])
255
+ )
256
+ )
257
+ );
258
+ });
259
+ } else {
260
+ newDeclarations.push(
261
+ t.variableDeclarator(
262
+ declarator.id,
263
+ t.arrowFunctionExpression(
264
+ [t.restElement(t.identifier('args'))],
265
+ t.blockStatement([
266
+ t.variableDeclaration(BABEL.CONST, [
267
+ t.variableDeclarator(
268
+ t.identifier(BABEL.MODULE),
269
+ t.conditionalExpression(
270
+ t.callExpression(
271
+ t.memberExpression(
272
+ t.identifier(MOCK.STORE_NAME),
273
+ t.identifier(BABEL.HAS)
274
+ ),
275
+ [t.stringLiteral(absolutePath)]
276
+ ),
277
+ t.objectExpression([
278
+ t.spreadElement(originalVar),
279
+ t.spreadElement(
280
+ t.callExpression(
281
+ t.memberExpression(
282
+ t.identifier(MOCK.STORE_NAME),
283
+ t.identifier(BABEL.GET)
284
+ ),
285
+ [t.stringLiteral(absolutePath)]
286
+ )
287
+ )
288
+ ]),
289
+ originalVar
290
+ )
291
+ )
292
+ ]),
293
+ t.returnStatement(
294
+ t.callExpression(
295
+ t.memberExpression(
296
+ t.identifier(BABEL.MODULE),
297
+ t.identifier('default')
298
+ ),
299
+ [t.spreadElement(t.identifier('args'))]
300
+ )
301
+ )
302
+ ])
303
+ )
304
+ )
305
+ );
306
+ }
208
307
  }
209
- }
210
308
 
211
- if (hasTransformation) {
212
- nodePath.node.declarations = newDeclarations;
213
- nodePath.node._transformed = true;
309
+ if (hasTransformation) {
310
+ nodePath.node.declarations = newDeclarations;
311
+ nodePath.node._transformed = true;
312
+ }
214
313
  }
215
314
  }
216
- }
217
- };
218
- };
315
+ };
316
+ }
317
+ };
package/bin/cli.js CHANGED
@@ -7,6 +7,7 @@ import {findAllSourceFiles, findTestFiles} from "./utils/findFiles.js";
7
7
  import {green, red, yellow} from "../utils/consoleColor.js";
8
8
  import {getTestResultMsg} from "../utils/makeMessage.js";
9
9
  import {RESULT_TITLE} from "../constants.js";
10
+ import {collectMockedPaths} from "../src/mock/collectMocks.js";
10
11
 
11
12
  const getUserModuleType = () => {
12
13
  try {
@@ -38,19 +39,20 @@ const main = async () => {
38
39
  global[key] = jsTe[key];
39
40
  });
40
41
 
42
+ const testFiles = findTestFiles(process.cwd());
43
+ console.log(`\nFound ${green(testFiles.length)} test file(s)`);
44
+
45
+ const mockedPaths = collectMockedPaths(testFiles);
46
+
41
47
  const sourceFiles = findAllSourceFiles(process.cwd());
42
48
  for (const file of sourceFiles) {
43
- transformFiles(file);
49
+ transformFiles(file, mockedPaths);
44
50
  }
45
51
 
46
- const testFiles = findTestFiles(process.cwd());
47
-
48
- console.log(`\nFound ${green(testFiles.length)} test file(s)`);
49
-
50
52
  for (const file of testFiles) {
51
53
  console.log(`\n${yellow(file)}\n`);
54
+ transformFiles(file, mockedPaths);
52
55
 
53
- transformFiles(file);
54
56
  await import(path.resolve(file));
55
57
 
56
58
  const {passed, failed} = await jsTe.run();
@@ -6,13 +6,13 @@ import {red} from "../../utils/consoleColor.js";
6
6
 
7
7
  const originalFiles = new Map();
8
8
 
9
- export const transformFiles = (filePath) => {
9
+ export const transformFiles = (filePath, mockPath) => {
10
10
  const originalCode = fs.readFileSync(filePath, 'utf-8');
11
11
  originalFiles.set(filePath, originalCode);
12
12
 
13
13
  const transformed = transformSync(originalCode, {
14
14
  filename: filePath,
15
- plugins: [babelTransformImport],
15
+ plugins: [babelTransformImport(mockPath)],
16
16
  parserOpts: {
17
17
  sourceType: BABEL.MODULE,
18
18
  plugins: ['dynamicImport']
@@ -256,4 +256,4 @@ exports.mockStore = mockStore;
256
256
  exports.run = run;
257
257
  exports.test = test;
258
258
  exports.unmock = unmock;
259
- //# sourceMappingURL=index.cjs.js.map
259
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../constants.js","../src/testManager.js","../src/mock/store.js","../utils/consoleColor.js","../utils/formatString.js","../src/matchers.js","../src/expect.js","../utils/makeMessage.js","../src/testRunner.js","../index.js"],"sourcesContent":["export const RESULT_TITLE = {\n TESTS: 'Tests: ',\n TOTAL : 'Total Result: '\n};\n\nexport const CHECK = '✓ ';\n\nexport const CROSS = '✗ ';\n\nexport const DIRECTORY_DELIMITER = ' > ';\n\nexport const EMPTY = '';\n\nexport const DEFAULT_COUNT = 0;\n\nexport const COLORS = {\n reset: '\\x1b[0m',\n green: '\\x1b[32m',\n red: '\\x1b[31m',\n yellow: '\\x1b[33m',\n cyan: '\\x1b[36m',\n gray: '\\x1b[90m',\n bold: '\\x1b[1m'\n};\n\nexport const MOCK = {\n STORE_NAME: 'mockStore',\n STORE_PATH : '@dannysir/js-te/src/mock/store.js'\n};\n\nexport const BABEL = {\n MODULE: 'module',\n CONST: 'const',\n HAS: 'has',\n GET: 'get',\n PERIOD: '.',\n};\n\nexport const PATH = {\n NODE_MODULES: 'node_modules',\n TEST_DIRECTORY: 'test',\n TEST_FILE: '.test.js',\n JAVASCRIPT_FILE: '.js',\n BIN: 'bin',\n DIST: 'dist',\n};\n","import {DIRECTORY_DELIMITER} from \"../constants.js\";\n\nclass TestManager {\n #tests = [];\n #testDepth = [];\n #beforeEachArr = [];\n\n describe(str, fn) {\n this.#testDepth.push(str);\n const prevLength = this.#beforeEachArr.length;\n fn();\n this.#beforeEachArr.length = prevLength;\n this.#testDepth.pop();\n }\n\n test(description, fn) {\n const beforeEachHooks = [...this.#beforeEachArr];\n\n const testObj = {\n description,\n fn: async () => {\n for (const hook of beforeEachHooks) {\n await hook();\n }\n await fn();\n },\n path: this.#testDepth.join(DIRECTORY_DELIMITER),\n }\n this.#tests.push(testObj);\n }\n\n testEach(cases) {\n return (description, fn) => {\n cases.forEach(testCase => {\n const args = Array.isArray(testCase) ? testCase : [testCase];\n this.test(this.#formatDescription(args, description), () => fn(...args));\n });\n };\n }\n\n beforeEach(fn) {\n this.#beforeEachArr.push(fn);\n }\n\n getTests() {\n return [...this.#tests];\n }\n\n clearTests() {\n this.#tests = [];\n this.#testDepth = [];\n this.#beforeEachArr = [];\n }\n\n #formatDescription(args, description) {\n let argIndex = 0;\n return description.replace(/%([so])/g, (match, type) => {\n if (argIndex >= args.length) return match;\n\n const arg = args[argIndex++];\n\n switch (type) {\n case 's':\n return arg;\n case 'o':\n return JSON.stringify(arg);\n default:\n return match;\n }\n });\n }\n}\n\nexport const testManager = new TestManager();","export const mockStore = new Map();\n\nexport function clearAllMocks() {\n mockStore.clear();\n}\n\nexport function mock(modulePath, mockExports) {\n mockStore.set(modulePath, mockExports);\n}\n\nexport function unmock(modulePath) {\n mockStore.delete(modulePath);\n}\n\nexport function isMocked(modulePath) {\n return mockStore.has(modulePath);\n}\n","import {COLORS} from \"../constants.js\";\n\nexport const colorize = (text, color) => `${color}${text}${COLORS.reset}`;\n\nexport const green = (text) => colorize(text, COLORS.green + COLORS.bold);\nexport const red = (text) => colorize(text, COLORS.red + COLORS.bold);\nexport const bold = (text) => colorize(text, COLORS.bold);\nexport const yellow = (text) => colorize(text, COLORS.yellow + COLORS.bold);","import {CHECK, CROSS, DIRECTORY_DELIMITER, EMPTY} from \"../constants.js\";\nimport {green, red} from \"./consoleColor.js\";\n\nexport const formatSuccessMessage = (test) => {\n const pathString = test.path === '' ? EMPTY : test.path + DIRECTORY_DELIMITER;\n return green(CHECK) + pathString + test.description;\n};\n\nexport const formatFailureMessage = (test, error) => {\n const messages = [];\n messages.push(red(CROSS) + test.path + test.description);\n messages.push(red(` Error Message : ${error.message}`));\n return messages.join('\\n');\n};\n\nexport const getErrorMsg = (expect, actual) => {\n return `Expected ${JSON.stringify(expect)} but got ${JSON.stringify(actual)}`;\n};\nexport const getThrowErrorMsg = (expect) => {\n return `Expected function to throw an error containing \"${expect}\", but it did not throw`;\n};","\nimport {getErrorMsg, getThrowErrorMsg} from \"../utils/formatString.js\";\n\nconst runArgFnc = (actual) => {\n if (typeof actual === 'function') {\n return actual();\n }\n return actual;\n};\n\nexport const toBe = (actual, expected) => {\n const value = runArgFnc(actual);\n if (value !== expected) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toEqual = (actual, expected) => {\n const value = runArgFnc(actual);\n if (JSON.stringify(value) !== JSON.stringify(expected)) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toThrow = (actual, expected) => {\n try {\n runArgFnc(actual);\n } catch (e) {\n if (!e.message.includes(expected)) {\n throw new Error(getErrorMsg(expected, e.message));\n }\n return;\n }\n throw new Error(getThrowErrorMsg(expected));\n};\n\nexport const toBeTruthy = (actual) => {\n const value = runArgFnc(actual);\n if (!value) {\n throw new Error(getErrorMsg(true, value));\n }\n};\n\nexport const toBeFalsy = (actual) => {\n const value = runArgFnc(actual);\n if (value) {\n throw new Error(getErrorMsg(false, value));\n }\n};\n","import {toBe, toBeFalsy, toBeTruthy, toEqual, toThrow} from \"./matchers.js\";\n\nexport const expect = (actual) => {\n return {\n toBe(expected) {\n toBe(actual, expected);\n },\n toEqual(expected) {\n toEqual(actual, expected);\n },\n toThrow(expected) {\n toThrow(actual, expected);\n },\n toBeTruthy() {\n toBeTruthy(actual);\n },\n toBeFalsy() {\n toBeFalsy(actual);\n }\n }\n};\n","import {bold, green, red} from \"./consoleColor.js\";\n\nexport const getTestResultMsg = (title, success, fail) => {\n let msg = '\\n';\n\n msg += title;\n msg += green(success + ' passed') + ', ';\n if (fail) {\n msg += red(fail + ' failed') + ', ';\n }\n msg += bold(success + fail + ' total');\n\n return msg;\n};","import {DEFAULT_COUNT, RESULT_TITLE} from \"../constants.js\";\nimport {testManager} from \"./testManager.js\";\nimport {formatFailureMessage, formatSuccessMessage} from \"../utils/formatString.js\";\nimport {getTestResultMsg} from \"../utils/makeMessage.js\";\nimport {clearAllMocks} from \"./mock/store.js\";\n\nexport const run = async () => {\n let passed = DEFAULT_COUNT;\n let failed = DEFAULT_COUNT;\n\n for (const test of testManager.getTests()) {\n try {\n await test.fn();\n console.log(formatSuccessMessage(test));\n passed++;\n clearAllMocks();\n } catch (error) {\n console.log(formatFailureMessage(test, error));\n failed++;\n }\n }\n\n console.log(getTestResultMsg(RESULT_TITLE.TESTS, passed, failed));\n\n testManager.clearTests();\n\n return {passed, failed};\n};\n","import {testManager} from \"./src/testManager.js\";\nimport {clearAllMocks, isMocked, mock, unmock, mockStore} from './src/mock/store.js';\nimport {expect} from \"./src/expect.js\";\nimport {run} from \"./src/testRunner\";\n\nexport const test = (description, fn) => testManager.test(description, fn);\ntest.each = (cases) => testManager.testEach(cases);\n\nexport const describe = (suiteName, fn) => testManager.describe(suiteName, fn);\n\nexport const beforeEach = (fn) => testManager.beforeEach(fn);\n\nexport {expect, run};\n\nexport {mock, clearAllMocks, unmock, isMocked, mockStore};\n"],"names":[],"mappings":";;AAAO,MAAM,YAAY,GAAG;AAC5B,EAAE,KAAK,EAAE,SAET,CAAC;;AAEM,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,mBAAmB,GAAG,KAAK;;AAEjC,MAAM,KAAK,GAAG,EAAE;;AAEhB,MAAM,aAAa,GAAG,CAAC;;AAEvB,MAAM,MAAM,GAAG;AACtB,EAAE,KAAK,EAAE,SAAS;AAClB,EAAE,KAAK,EAAE,UAAU;AACnB,EAAE,GAAG,EAAE,UAAU;AACjB,EAGE,IAAI,EAAE;AACR,CAAC;;ACrBD,MAAM,WAAW,CAAC;AAClB,EAAE,MAAM,GAAG,EAAE;AACb,EAAE,UAAU,GAAG,EAAE;AACjB,EAAE,cAAc,GAAG,EAAE;;AAErB,EAAE,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE;AACpB,IAAI,IAAI,CAAC,UAAU,CAAC,IA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,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,KAAK,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;;AAEtC,MAAC,QAAQ,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;;AAEjE,MAAC,UAAU,GAAG,CAAC,EAAE,KAAK,WAAW,CAAC,UAAU,CAAC,EAAE;;;;;;;;;;;;;"}
@@ -245,4 +245,4 @@ const describe = (suiteName, fn) => testManager.describe(suiteName, fn);
245
245
  const beforeEach = (fn) => testManager.beforeEach(fn);
246
246
 
247
247
  export { beforeEach, clearAllMocks, describe, expect, isMocked, mock, mockStore, run, test, unmock };
248
- //# sourceMappingURL=index.esm.js.map
248
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../constants.js","../src/testManager.js","../src/mock/store.js","../utils/consoleColor.js","../utils/formatString.js","../src/matchers.js","../src/expect.js","../utils/makeMessage.js","../src/testRunner.js","../index.js"],"sourcesContent":["export const RESULT_TITLE = {\n TESTS: 'Tests: ',\n TOTAL : 'Total Result: '\n};\n\nexport const CHECK = '✓ ';\n\nexport const CROSS = '✗ ';\n\nexport const DIRECTORY_DELIMITER = ' > ';\n\nexport const EMPTY = '';\n\nexport const DEFAULT_COUNT = 0;\n\nexport const COLORS = {\n reset: '\\x1b[0m',\n green: '\\x1b[32m',\n red: '\\x1b[31m',\n yellow: '\\x1b[33m',\n cyan: '\\x1b[36m',\n gray: '\\x1b[90m',\n bold: '\\x1b[1m'\n};\n\nexport const MOCK = {\n STORE_NAME: 'mockStore',\n STORE_PATH : '@dannysir/js-te/src/mock/store.js'\n};\n\nexport const BABEL = {\n MODULE: 'module',\n CONST: 'const',\n HAS: 'has',\n GET: 'get',\n PERIOD: '.',\n};\n\nexport const PATH = {\n NODE_MODULES: 'node_modules',\n TEST_DIRECTORY: 'test',\n TEST_FILE: '.test.js',\n JAVASCRIPT_FILE: '.js',\n BIN: 'bin',\n DIST: 'dist',\n};\n","import {DIRECTORY_DELIMITER} from \"../constants.js\";\n\nclass TestManager {\n #tests = [];\n #testDepth = [];\n #beforeEachArr = [];\n\n describe(str, fn) {\n this.#testDepth.push(str);\n const prevLength = this.#beforeEachArr.length;\n fn();\n this.#beforeEachArr.length = prevLength;\n this.#testDepth.pop();\n }\n\n test(description, fn) {\n const beforeEachHooks = [...this.#beforeEachArr];\n\n const testObj = {\n description,\n fn: async () => {\n for (const hook of beforeEachHooks) {\n await hook();\n }\n await fn();\n },\n path: this.#testDepth.join(DIRECTORY_DELIMITER),\n }\n this.#tests.push(testObj);\n }\n\n testEach(cases) {\n return (description, fn) => {\n cases.forEach(testCase => {\n const args = Array.isArray(testCase) ? testCase : [testCase];\n this.test(this.#formatDescription(args, description), () => fn(...args));\n });\n };\n }\n\n beforeEach(fn) {\n this.#beforeEachArr.push(fn);\n }\n\n getTests() {\n return [...this.#tests];\n }\n\n clearTests() {\n this.#tests = [];\n this.#testDepth = [];\n this.#beforeEachArr = [];\n }\n\n #formatDescription(args, description) {\n let argIndex = 0;\n return description.replace(/%([so])/g, (match, type) => {\n if (argIndex >= args.length) return match;\n\n const arg = args[argIndex++];\n\n switch (type) {\n case 's':\n return arg;\n case 'o':\n return JSON.stringify(arg);\n default:\n return match;\n }\n });\n }\n}\n\nexport const testManager = new TestManager();","export const mockStore = new Map();\n\nexport function clearAllMocks() {\n mockStore.clear();\n}\n\nexport function mock(modulePath, mockExports) {\n mockStore.set(modulePath, mockExports);\n}\n\nexport function unmock(modulePath) {\n mockStore.delete(modulePath);\n}\n\nexport function isMocked(modulePath) {\n return mockStore.has(modulePath);\n}\n","import {COLORS} from \"../constants.js\";\n\nexport const colorize = (text, color) => `${color}${text}${COLORS.reset}`;\n\nexport const green = (text) => colorize(text, COLORS.green + COLORS.bold);\nexport const red = (text) => colorize(text, COLORS.red + COLORS.bold);\nexport const bold = (text) => colorize(text, COLORS.bold);\nexport const yellow = (text) => colorize(text, COLORS.yellow + COLORS.bold);","import {CHECK, CROSS, DIRECTORY_DELIMITER, EMPTY} from \"../constants.js\";\nimport {green, red} from \"./consoleColor.js\";\n\nexport const formatSuccessMessage = (test) => {\n const pathString = test.path === '' ? EMPTY : test.path + DIRECTORY_DELIMITER;\n return green(CHECK) + pathString + test.description;\n};\n\nexport const formatFailureMessage = (test, error) => {\n const messages = [];\n messages.push(red(CROSS) + test.path + test.description);\n messages.push(red(` Error Message : ${error.message}`));\n return messages.join('\\n');\n};\n\nexport const getErrorMsg = (expect, actual) => {\n return `Expected ${JSON.stringify(expect)} but got ${JSON.stringify(actual)}`;\n};\nexport const getThrowErrorMsg = (expect) => {\n return `Expected function to throw an error containing \"${expect}\", but it did not throw`;\n};","\nimport {getErrorMsg, getThrowErrorMsg} from \"../utils/formatString.js\";\n\nconst runArgFnc = (actual) => {\n if (typeof actual === 'function') {\n return actual();\n }\n return actual;\n};\n\nexport const toBe = (actual, expected) => {\n const value = runArgFnc(actual);\n if (value !== expected) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toEqual = (actual, expected) => {\n const value = runArgFnc(actual);\n if (JSON.stringify(value) !== JSON.stringify(expected)) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toThrow = (actual, expected) => {\n try {\n runArgFnc(actual);\n } catch (e) {\n if (!e.message.includes(expected)) {\n throw new Error(getErrorMsg(expected, e.message));\n }\n return;\n }\n throw new Error(getThrowErrorMsg(expected));\n};\n\nexport const toBeTruthy = (actual) => {\n const value = runArgFnc(actual);\n if (!value) {\n throw new Error(getErrorMsg(true, value));\n }\n};\n\nexport const toBeFalsy = (actual) => {\n const value = runArgFnc(actual);\n if (value) {\n throw new Error(getErrorMsg(false, value));\n }\n};\n","import {toBe, toBeFalsy, toBeTruthy, toEqual, toThrow} from \"./matchers.js\";\n\nexport const expect = (actual) => {\n return {\n toBe(expected) {\n toBe(actual, expected);\n },\n toEqual(expected) {\n toEqual(actual, expected);\n },\n toThrow(expected) {\n toThrow(actual, expected);\n },\n toBeTruthy() {\n toBeTruthy(actual);\n },\n toBeFalsy() {\n toBeFalsy(actual);\n }\n }\n};\n","import {bold, green, red} from \"./consoleColor.js\";\n\nexport const getTestResultMsg = (title, success, fail) => {\n let msg = '\\n';\n\n msg += title;\n msg += green(success + ' passed') + ', ';\n if (fail) {\n msg += red(fail + ' failed') + ', ';\n }\n msg += bold(success + fail + ' total');\n\n return msg;\n};","import {DEFAULT_COUNT, RESULT_TITLE} from \"../constants.js\";\nimport {testManager} from \"./testManager.js\";\nimport {formatFailureMessage, formatSuccessMessage} from \"../utils/formatString.js\";\nimport {getTestResultMsg} from \"../utils/makeMessage.js\";\nimport {clearAllMocks} from \"./mock/store.js\";\n\nexport const run = async () => {\n let passed = DEFAULT_COUNT;\n let failed = DEFAULT_COUNT;\n\n for (const test of testManager.getTests()) {\n try {\n await test.fn();\n console.log(formatSuccessMessage(test));\n passed++;\n clearAllMocks();\n } catch (error) {\n console.log(formatFailureMessage(test, error));\n failed++;\n }\n }\n\n console.log(getTestResultMsg(RESULT_TITLE.TESTS, passed, failed));\n\n testManager.clearTests();\n\n return {passed, failed};\n};\n","import {testManager} from \"./src/testManager.js\";\nimport {clearAllMocks, isMocked, mock, unmock, mockStore} from './src/mock/store.js';\nimport {expect} from \"./src/expect.js\";\nimport {run} from \"./src/testRunner\";\n\nexport const test = (description, fn) => testManager.test(description, fn);\ntest.each = (cases) => testManager.testEach(cases);\n\nexport const describe = (suiteName, fn) => testManager.describe(suiteName, fn);\n\nexport const beforeEach = (fn) => testManager.beforeEach(fn);\n\nexport {expect, run};\n\nexport {mock, clearAllMocks, unmock, isMocked, mockStore};\n"],"names":[],"mappings":"AAAO,MAAM,YAAY,GAAG;AAC5B,EAAE,KAAK,EAAE,SAET,CAAC;;AAEM,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,mBAAmB,GAAG,KAAK;;AAEjC,MAAM,KAAK,GA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C,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACpD,MAAM,MAAM,EAAE;AACd,IAAI;AACJ,EAAE;;AAEF,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;;AAEnE,EAAE,WAAW,CAAC,UAAU,EAAE;;AAE1B,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;AACzB;;ACtBY,MAAC,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,KAAK,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;AACzE,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,KAAK,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;;AAEtC,MAAC,QAAQ,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;;AAEjE,MAAC,UAAU,GAAG,CAAC,EAAE,KAAK,WAAW,CAAC,UAAU,CAAC,EAAE;;;;"}
package/package.json CHANGED
@@ -1,24 +1,23 @@
1
1
  {
2
2
  "name": "@dannysir/js-te",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "JavaScript test library",
5
- "main": "./dist/index.cjs.js",
6
- "module": "./dist/index.esm.js",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "type": "module",
7
8
  "exports": {
8
9
  ".": {
9
- "import": "./dist/index.esm.js",
10
- "require": "./dist/index.cjs.js"
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.cjs"
11
12
  },
12
- "./src/mock/store.js": {
13
- "import": "./dist/mock/store.esm.js",
14
- "require": "./dist/mock/store.cjs.js"
15
- }
13
+ "./src/mock/store.js": "./src/mock/store.js"
16
14
  },
17
15
  "bin": {
18
16
  "js-te": "./bin/cli.js"
19
17
  },
20
18
  "scripts": {
21
- "build": "rollup -c",
19
+ "clean": "rimraf dist",
20
+ "build": "npm run clean && rollup -c",
22
21
  "test": "node bin/cli.js",
23
22
  "prepublishOnly": "npm run build"
24
23
  },
@@ -50,5 +49,12 @@
50
49
  "@rollup/plugin-node-resolve": "^16.0.3",
51
50
  "rimraf": "^6.1.2",
52
51
  "rollup": "^4.53.3"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/dannysir/js-te-package"
56
+ },
57
+ "bugs": {
58
+ "url": "https://github.com/dannysir/js-te-package/issues"
53
59
  }
54
60
  }
@@ -0,0 +1,28 @@
1
+ import fs from 'fs';
2
+ import {transformSync} from "@babel/core";
3
+ import {BABEL} from "../../constants.js";
4
+ import {createMockCollectorPlugin} from "../../babelCollectMocks.js";
5
+
6
+ export const collectMockedPaths = (testFiles) => {
7
+ const mockedPaths = new Set();
8
+
9
+ for (const testFile of testFiles) {
10
+ const code = fs.readFileSync(testFile, 'utf-8');
11
+
12
+ try {
13
+ transformSync(code, {
14
+ filename: testFile,
15
+ plugins: [createMockCollectorPlugin(mockedPaths)],
16
+ parserOpts: {
17
+ sourceType: BABEL.MODULE,
18
+ plugins: ['dynamicImport']
19
+ }
20
+ });
21
+ } catch (error) {
22
+ // 파싱 에러는 무시 (어차피 테스트 실행 시 에러 발생)
23
+ console.warn(`Warning: Failed to scan ${testFile} for mocks`);
24
+ }
25
+ }
26
+
27
+ return mockedPaths;
28
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../constants.js","../src/testManager.js","../src/mock/store.js","../utils/consoleColor.js","../utils/formatString.js","../src/matchers.js","../src/expect.js","../utils/makeMessage.js","../src/testRunner.js","../index.js"],"sourcesContent":["export const RESULT_TITLE = {\n TESTS: 'Tests: ',\n TOTAL : 'Total Result: '\n};\n\nexport const CHECK = '✓ ';\n\nexport const CROSS = '✗ ';\n\nexport const DIRECTORY_DELIMITER = ' > ';\n\nexport const EMPTY = '';\n\nexport const DEFAULT_COUNT = 0;\n\nexport const COLORS = {\n reset: '\\x1b[0m',\n green: '\\x1b[32m',\n red: '\\x1b[31m',\n yellow: '\\x1b[33m',\n cyan: '\\x1b[36m',\n gray: '\\x1b[90m',\n bold: '\\x1b[1m'\n};\n\nexport const MOCK = {\n STORE_NAME: 'mockStore',\n STORE_PATH : '@dannysir/js-te/src/mock/store.js'\n};\n\nexport const BABEL = {\n MODULE: 'module',\n CONST: 'const',\n HAS: 'has',\n GET: 'get',\n PERIOD: '.',\n};\n\nexport const PATH = {\n NODE_MODULES: 'node_modules',\n TEST_DIRECTORY: 'test',\n TEST_FILE: '.test.js',\n JAVASCRIPT_FILE: '.js',\n BIN: 'bin',\n DIST: 'dist',\n};\n","import {DIRECTORY_DELIMITER} from \"../constants.js\";\n\nclass TestManager {\n #tests = [];\n #testDepth = [];\n #beforeEachArr = [];\n\n describe(str, fn) {\n this.#testDepth.push(str);\n const prevLength = this.#beforeEachArr.length;\n fn();\n this.#beforeEachArr.length = prevLength;\n this.#testDepth.pop();\n }\n\n test(description, fn) {\n const beforeEachHooks = [...this.#beforeEachArr];\n\n const testObj = {\n description,\n fn: async () => {\n for (const hook of beforeEachHooks) {\n await hook();\n }\n await fn();\n },\n path: this.#testDepth.join(DIRECTORY_DELIMITER),\n }\n this.#tests.push(testObj);\n }\n\n testEach(cases) {\n return (description, fn) => {\n cases.forEach(testCase => {\n const args = Array.isArray(testCase) ? testCase : [testCase];\n this.test(this.#formatDescription(args, description), () => fn(...args));\n });\n };\n }\n\n beforeEach(fn) {\n this.#beforeEachArr.push(fn);\n }\n\n getTests() {\n return [...this.#tests];\n }\n\n clearTests() {\n this.#tests = [];\n this.#testDepth = [];\n this.#beforeEachArr = [];\n }\n\n #formatDescription(args, description) {\n let argIndex = 0;\n return description.replace(/%([so])/g, (match, type) => {\n if (argIndex >= args.length) return match;\n\n const arg = args[argIndex++];\n\n switch (type) {\n case 's':\n return arg;\n case 'o':\n return JSON.stringify(arg);\n default:\n return match;\n }\n });\n }\n}\n\nexport const testManager = new TestManager();","export const mockStore = new Map();\n\nexport function clearAllMocks() {\n mockStore.clear();\n}\n\nexport function mock(modulePath, mockExports) {\n mockStore.set(modulePath, mockExports);\n}\n\nexport function unmock(modulePath) {\n mockStore.delete(modulePath);\n}\n\nexport function isMocked(modulePath) {\n return mockStore.has(modulePath);\n}\n","import {COLORS} from \"../constants.js\";\n\nexport const colorize = (text, color) => `${color}${text}${COLORS.reset}`;\n\nexport const green = (text) => colorize(text, COLORS.green + COLORS.bold);\nexport const red = (text) => colorize(text, COLORS.red + COLORS.bold);\nexport const bold = (text) => colorize(text, COLORS.bold);\nexport const yellow = (text) => colorize(text, COLORS.yellow + COLORS.bold);","import {CHECK, CROSS, DIRECTORY_DELIMITER, EMPTY} from \"../constants.js\";\nimport {green, red} from \"./consoleColor.js\";\n\nexport const formatSuccessMessage = (test) => {\n const pathString = test.path === '' ? EMPTY : test.path + DIRECTORY_DELIMITER;\n return green(CHECK) + pathString + test.description;\n};\n\nexport const formatFailureMessage = (test, error) => {\n const messages = [];\n messages.push(red(CROSS) + test.path + test.description);\n messages.push(red(` Error Message : ${error.message}`));\n return messages.join('\\n');\n};\n\nexport const getErrorMsg = (expect, actual) => {\n return `Expected ${JSON.stringify(expect)} but got ${JSON.stringify(actual)}`;\n};\nexport const getThrowErrorMsg = (expect) => {\n return `Expected function to throw an error containing \"${expect}\", but it did not throw`;\n};","\nimport {getErrorMsg, getThrowErrorMsg} from \"../utils/formatString.js\";\n\nconst runArgFnc = (actual) => {\n if (typeof actual === 'function') {\n return actual();\n }\n return actual;\n};\n\nexport const toBe = (actual, expected) => {\n const value = runArgFnc(actual);\n if (value !== expected) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toEqual = (actual, expected) => {\n const value = runArgFnc(actual);\n if (JSON.stringify(value) !== JSON.stringify(expected)) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toThrow = (actual, expected) => {\n try {\n runArgFnc(actual);\n } catch (e) {\n if (!e.message.includes(expected)) {\n throw new Error(getErrorMsg(expected, e.message));\n }\n return;\n }\n throw new Error(getThrowErrorMsg(expected));\n};\n\nexport const toBeTruthy = (actual) => {\n const value = runArgFnc(actual);\n if (!value) {\n throw new Error(getErrorMsg(true, value));\n }\n};\n\nexport const toBeFalsy = (actual) => {\n const value = runArgFnc(actual);\n if (value) {\n throw new Error(getErrorMsg(false, value));\n }\n};\n","import {toBe, toBeFalsy, toBeTruthy, toEqual, toThrow} from \"./matchers.js\";\n\nexport const expect = (actual) => {\n return {\n toBe(expected) {\n toBe(actual, expected);\n },\n toEqual(expected) {\n toEqual(actual, expected);\n },\n toThrow(expected) {\n toThrow(actual, expected);\n },\n toBeTruthy() {\n toBeTruthy(actual);\n },\n toBeFalsy() {\n toBeFalsy(actual);\n }\n }\n};\n","import {bold, green, red} from \"./consoleColor.js\";\n\nexport const getTestResultMsg = (title, success, fail) => {\n let msg = '\\n';\n\n msg += title;\n msg += green(success + ' passed') + ', ';\n if (fail) {\n msg += red(fail + ' failed') + ', ';\n }\n msg += bold(success + fail + ' total');\n\n return msg;\n};","import {DEFAULT_COUNT, RESULT_TITLE} from \"../constants.js\";\nimport {testManager} from \"./testManager.js\";\nimport {formatFailureMessage, formatSuccessMessage} from \"../utils/formatString.js\";\nimport {getTestResultMsg} from \"../utils/makeMessage.js\";\nimport {clearAllMocks} from \"./mock/store.js\";\n\nexport const run = async () => {\n let passed = DEFAULT_COUNT;\n let failed = DEFAULT_COUNT;\n\n for (const test of testManager.getTests()) {\n try {\n await test.fn();\n console.log(formatSuccessMessage(test));\n passed++;\n clearAllMocks();\n } catch (error) {\n console.log(formatFailureMessage(test, error));\n failed++;\n }\n }\n\n console.log(getTestResultMsg(RESULT_TITLE.TESTS, passed, failed));\n\n testManager.clearTests();\n\n return {passed, failed};\n};\n","import {testManager} from \"./src/testManager.js\";\nimport {clearAllMocks, isMocked, mock, unmock, mockStore} from './src/mock/store.js';\nimport {expect} from \"./src/expect.js\";\nimport {run} from \"./src/testRunner\";\n\nexport const test = (description, fn) => testManager.test(description, fn);\ntest.each = (cases) => testManager.testEach(cases);\n\nexport const describe = (suiteName, fn) => testManager.describe(suiteName, fn);\n\nexport const beforeEach = (fn) => testManager.beforeEach(fn);\n\nexport {expect, run};\n\nexport {mock, clearAllMocks, unmock, isMocked, mockStore};\n"],"names":[],"mappings":";;AAAO,MAAM,YAAY,GAAG;AAC5B,EAAE,KAAK,EAAE,SAET,CAAC;;AAEM,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,mBAAmB,GAAG,KAAK;;AAEjC,MAAM,KAAK,GAAG,EAAE;;AAEhB,MAAM,aAAa,GAAG,CAAC;;AAEvB,MAAM,MAAM,GAAG;AACtB,EAAE,KAAK,EAAE,SAAS;AAClB,EAAE,KAAK,EAAE,UAAU;AACnB,EAAE,GAAG,EAAE,UAAU;AACjB,EAGE,IAAI,EAAE;AACR,CAAC;;ACrBD,MAAM,WAAW,CAAC;AAClB,EAAE,MAAM,GAAG,EAAE;AACb,EAAE,UAAU,GAAG,EAAE;AACjB,EAAE,cAAc,GAAG,EAAE;;AAErB,EAAE,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE;AACpB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7B,IAAI,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM;AACjD,IAAI,EAAE,EAAE;AACR,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,UAAU;AAC3C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;AACzB,EAAE;;AAEF,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE;AACxB,IAAI,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;;AAEpD,IAAI,MAAM,OAAO,GAAG;AACpB,MAAM,WAAW;AACjB,MAAM,EAAE,EAAE,YAAY;AACtB,QAAQ,KAAK,MAAM,IAAI,IAAI,eAA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AM,GAAG,aAAa;AAC5B,EAAE,IAAI,MAAM,GAAG,aAAa;;AAE5B,EAAE,KAAK,MAAM,IAAI,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE;AAC7C,IAAI,IAAI;AACR,MAAM,MAAM,IAAI,CAAC,EAAE,EAAE;AACrB,MAAM,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAC7C,MAAM,MAAM,EAAE;AACd,MAAM,aAAa,EAAE;AACrB,IAAI,CAAC,CAAC,OAAO,KAAK,EAAE;AACpB,MAAM,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACpD,MAAM,MAAM,EAAE;AACd,IAAI;AACJ,EAAE;;AAEF,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;;AAEnE,EAAE,WAAW,CAAC,UAAU,EAAE;;AAE1B,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC;AACzB;;ACtBY,MAAC,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,KAAK,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;AACzE,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,KAAK,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;;AAEtC,MAAC,QAAQ,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;;AAEjE,MAAC,UAAU,GAAG,CAAC,EAAE,KAAK,WAAW,CAAC,UAAU,CAAC,EAAE;;;;;;;;;;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.js","sources":["../constants.js","../src/testManager.js","../src/mock/store.js","../utils/consoleColor.js","../utils/formatString.js","../src/matchers.js","../src/expect.js","../utils/makeMessage.js","../src/testRunner.js","../index.js"],"sourcesContent":["export const RESULT_TITLE = {\n TESTS: 'Tests: ',\n TOTAL : 'Total Result: '\n};\n\nexport const CHECK = '✓ ';\n\nexport const CROSS = '✗ ';\n\nexport const DIRECTORY_DELIMITER = ' > ';\n\nexport const EMPTY = '';\n\nexport const DEFAULT_COUNT = 0;\n\nexport const COLORS = {\n reset: '\\x1b[0m',\n green: '\\x1b[32m',\n red: '\\x1b[31m',\n yellow: '\\x1b[33m',\n cyan: '\\x1b[36m',\n gray: '\\x1b[90m',\n bold: '\\x1b[1m'\n};\n\nexport const MOCK = {\n STORE_NAME: 'mockStore',\n STORE_PATH : '@dannysir/js-te/src/mock/store.js'\n};\n\nexport const BABEL = {\n MODULE: 'module',\n CONST: 'const',\n HAS: 'has',\n GET: 'get',\n PERIOD: '.',\n};\n\nexport const PATH = {\n NODE_MODULES: 'node_modules',\n TEST_DIRECTORY: 'test',\n TEST_FILE: '.test.js',\n JAVASCRIPT_FILE: '.js',\n BIN: 'bin',\n DIST: 'dist',\n};\n","import {DIRECTORY_DELIMITER} from \"../constants.js\";\n\nclass TestManager {\n #tests = [];\n #testDepth = [];\n #beforeEachArr = [];\n\n describe(str, fn) {\n this.#testDepth.push(str);\n const prevLength = this.#beforeEachArr.length;\n fn();\n this.#beforeEachArr.length = prevLength;\n this.#testDepth.pop();\n }\n\n test(description, fn) {\n const beforeEachHooks = [...this.#beforeEachArr];\n\n const testObj = {\n description,\n fn: async () => {\n for (const hook of beforeEachHooks) {\n await hook();\n }\n await fn();\n },\n path: this.#testDepth.join(DIRECTORY_DELIMITER),\n }\n this.#tests.push(testObj);\n }\n\n testEach(cases) {\n return (description, fn) => {\n cases.forEach(testCase => {\n const args = Array.isArray(testCase) ? testCase : [testCase];\n this.test(this.#formatDescription(args, description), () => fn(...args));\n });\n };\n }\n\n beforeEach(fn) {\n this.#beforeEachArr.push(fn);\n }\n\n getTests() {\n return [...this.#tests];\n }\n\n clearTests() {\n this.#tests = [];\n this.#testDepth = [];\n this.#beforeEachArr = [];\n }\n\n #formatDescription(args, description) {\n let argIndex = 0;\n return description.replace(/%([so])/g, (match, type) => {\n if (argIndex >= args.length) return match;\n\n const arg = args[argIndex++];\n\n switch (type) {\n case 's':\n return arg;\n case 'o':\n return JSON.stringify(arg);\n default:\n return match;\n }\n });\n }\n}\n\nexport const testManager = new TestManager();","export const mockStore = new Map();\n\nexport function clearAllMocks() {\n mockStore.clear();\n}\n\nexport function mock(modulePath, mockExports) {\n mockStore.set(modulePath, mockExports);\n}\n\nexport function unmock(modulePath) {\n mockStore.delete(modulePath);\n}\n\nexport function isMocked(modulePath) {\n return mockStore.has(modulePath);\n}\n","import {COLORS} from \"../constants.js\";\n\nexport const colorize = (text, color) => `${color}${text}${COLORS.reset}`;\n\nexport const green = (text) => colorize(text, COLORS.green + COLORS.bold);\nexport const red = (text) => colorize(text, COLORS.red + COLORS.bold);\nexport const bold = (text) => colorize(text, COLORS.bold);\nexport const yellow = (text) => colorize(text, COLORS.yellow + COLORS.bold);","import {CHECK, CROSS, DIRECTORY_DELIMITER, EMPTY} from \"../constants.js\";\nimport {green, red} from \"./consoleColor.js\";\n\nexport const formatSuccessMessage = (test) => {\n const pathString = test.path === '' ? EMPTY : test.path + DIRECTORY_DELIMITER;\n return green(CHECK) + pathString + test.description;\n};\n\nexport const formatFailureMessage = (test, error) => {\n const messages = [];\n messages.push(red(CROSS) + test.path + test.description);\n messages.push(red(` Error Message : ${error.message}`));\n return messages.join('\\n');\n};\n\nexport const getErrorMsg = (expect, actual) => {\n return `Expected ${JSON.stringify(expect)} but got ${JSON.stringify(actual)}`;\n};\nexport const getThrowErrorMsg = (expect) => {\n return `Expected function to throw an error containing \"${expect}\", but it did not throw`;\n};","\nimport {getErrorMsg, getThrowErrorMsg} from \"../utils/formatString.js\";\n\nconst runArgFnc = (actual) => {\n if (typeof actual === 'function') {\n return actual();\n }\n return actual;\n};\n\nexport const toBe = (actual, expected) => {\n const value = runArgFnc(actual);\n if (value !== expected) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toEqual = (actual, expected) => {\n const value = runArgFnc(actual);\n if (JSON.stringify(value) !== JSON.stringify(expected)) {\n throw new Error(getErrorMsg(expected, value));\n }\n};\n\nexport const toThrow = (actual, expected) => {\n try {\n runArgFnc(actual);\n } catch (e) {\n if (!e.message.includes(expected)) {\n throw new Error(getErrorMsg(expected, e.message));\n }\n return;\n }\n throw new Error(getThrowErrorMsg(expected));\n};\n\nexport const toBeTruthy = (actual) => {\n const value = runArgFnc(actual);\n if (!value) {\n throw new Error(getErrorMsg(true, value));\n }\n};\n\nexport const toBeFalsy = (actual) => {\n const value = runArgFnc(actual);\n if (value) {\n throw new Error(getErrorMsg(false, value));\n }\n};\n","import {toBe, toBeFalsy, toBeTruthy, toEqual, toThrow} from \"./matchers.js\";\n\nexport const expect = (actual) => {\n return {\n toBe(expected) {\n toBe(actual, expected);\n },\n toEqual(expected) {\n toEqual(actual, expected);\n },\n toThrow(expected) {\n toThrow(actual, expected);\n },\n toBeTruthy() {\n toBeTruthy(actual);\n },\n toBeFalsy() {\n toBeFalsy(actual);\n }\n }\n};\n","import {bold, green, red} from \"./consoleColor.js\";\n\nexport const getTestResultMsg = (title, success, fail) => {\n let msg = '\\n';\n\n msg += title;\n msg += green(success + ' passed') + ', ';\n if (fail) {\n msg += red(fail + ' failed') + ', ';\n }\n msg += bold(success + fail + ' total');\n\n return msg;\n};","import {DEFAULT_COUNT, RESULT_TITLE} from \"../constants.js\";\nimport {testManager} from \"./testManager.js\";\nimport {formatFailureMessage, formatSuccessMessage} from \"../utils/formatString.js\";\nimport {getTestResultMsg} from \"../utils/makeMessage.js\";\nimport {clearAllMocks} from \"./mock/store.js\";\n\nexport const run = async () => {\n let passed = DEFAULT_COUNT;\n let failed = DEFAULT_COUNT;\n\n for (const test of testManager.getTests()) {\n try {\n await test.fn();\n console.log(formatSuccessMessage(test));\n passed++;\n clearAllMocks();\n } catch (error) {\n console.log(formatFailureMessage(test, error));\n failed++;\n }\n }\n\n console.log(getTestResultMsg(RESULT_TITLE.TESTS, passed, failed));\n\n testManager.clearTests();\n\n return {passed, failed};\n};\n","import {testManager} from \"./src/testManager.js\";\nimport {clearAllMocks, isMocked, mock, unmock, mockStore} from './src/mock/store.js';\nimport {expect} from \"./src/expect.js\";\nimport {run} from \"./src/testRunner\";\n\nexport const test = (description, fn) => testManager.test(description, fn);\ntest.each = (cases) => testManager.testEach(cases);\n\nexport const describe = (suiteName, fn) => testManager.describe(suiteName, fn);\n\nexport const beforeEach = (fn) => testManager.beforeEach(fn);\n\nexport {expect, run};\n\nexport {mock, clearAllMocks, unmock, isMocked, mockStore};\n"],"names":[],"mappings":"AAAO,MAAM,YAAY,GAAG;AAC5B,EAAE,KAAK,EAAE,SAET,CAAC;;AAEM,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,KAAK,GAAG,IAAI;;AAElB,MAAM,mBAAmB,GAAG,KAAK;;AAEjC,MAAM,KAAK,GAAG,EAAE;;AAEhB,MAAM,aAAa,GAAG,CAAC;;AAEvB,MAAM,MAAM,GAAG;AACtB,EAAE,KAAK,EAAE,SAAS;AAClB,EAAE,KAAK,EAAE,UAAU;AACnB,EAAE,GAAG,EAAE,UAAU;AACjB,EAGE,IAAI,EAAE;AACR,CAAC;;ACrBD,MAAM,WAAW,CAAC;AAClB,EAAE,MAAM,GAAG,EAAE;AACb,EAAE,UAAU,GAAG,EAAE;AACjB,EAAE,cAAc,GAAG,EAAE;;AAErB,EAAE,QAAQ,CAAC,GAAG,EAAE,EAAE,EAAE;AACpB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC;AAC7B,IAAI,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,MAAM;AACjD,IAAI,EAAE,EAAE;AACR,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,UAAU;AAC3C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE;AACzB,EAAE;;AAEF,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,EAAE;AACx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