@dannysir/js-te 0.3.0 → 0.3.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 +13 -7
- package/bin/cli.js +14 -62
- package/dist/index.cjs +166 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +166 -102
- package/dist/index.mjs.map +1 -1
- package/index.js +90 -0
- package/package.json +4 -6
- package/src/babelPlugins/babelCollectMocks.js +35 -0
- package/src/babelPlugins/babelTransformImport.js +184 -0
- package/src/babelPlugins/utils/getModuleInfo.js +21 -0
- package/src/babelPlugins/utils/pathHelper.js +56 -0
- package/src/babelPlugins/utils/wrapperCreator.js +121 -0
- package/src/cli/runTests.js +22 -0
- package/src/cli/setupEnvironment.js +32 -0
- package/src/cli/setupFiles.js +15 -0
- package/src/constants/babel.js +12 -0
- package/src/constants/index.js +29 -0
- package/src/constants/view.js +9 -0
- package/src/matchers.js +1 -2
- package/src/mock/collectMocks.js +2 -3
- package/src/mock/store.js +4 -4
- package/src/testManager.js +31 -12
- package/{utils → src/utils}/consoleColor.js +2 -2
- package/{bin → src}/utils/findFiles.js +16 -5
- package/{utils → src/utils}/formatString.js +15 -5
- package/src/utils/messages.js +26 -0
- package/{bin → src}/utils/transformFiles.js +9 -4
- package/babelTransformImport.js +0 -317
- package/constants.js +0 -46
- package/src/testRunner.js +0 -28
- package/utils/makeMessage.js +0 -14
package/dist/index.mjs
CHANGED
|
@@ -1,21 +1,85 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const COLORS = {
|
|
2
|
+
reset: '\x1b[0m',
|
|
3
|
+
green: '\x1b[32m',
|
|
4
|
+
red: '\x1b[31m',
|
|
5
|
+
bold: '\x1b[1m'
|
|
6
|
+
};
|
|
3
7
|
|
|
4
|
-
const
|
|
8
|
+
const colorize = (text, color) => `${color}${text}${COLORS.reset}`;
|
|
5
9
|
|
|
6
|
-
const
|
|
10
|
+
const green = (text) => colorize(text, COLORS.green + COLORS.bold);
|
|
11
|
+
const red = (text) => colorize(text, COLORS.red + COLORS.bold);
|
|
12
|
+
const bold = (text) => colorize(text, COLORS.bold);
|
|
7
13
|
|
|
8
|
-
const
|
|
14
|
+
const RESULT_MSG = {
|
|
15
|
+
TESTS: 'Tests: ',
|
|
16
|
+
CHECK: '✓ ',
|
|
17
|
+
CROSS: '✗ ',
|
|
18
|
+
DIRECTORY_DELIMITER: ' > ',
|
|
19
|
+
EMPTY: '',
|
|
20
|
+
};
|
|
9
21
|
|
|
10
|
-
const
|
|
22
|
+
const NUM = {
|
|
23
|
+
ZERO: 0};
|
|
11
24
|
|
|
12
|
-
const
|
|
25
|
+
const formatSuccessMessage = (test) => {
|
|
26
|
+
const pathString = test.path === '' ? RESULT_MSG.EMPTY : test.path + RESULT_MSG.DIRECTORY_DELIMITER;
|
|
27
|
+
return green(RESULT_MSG.CHECK) + pathString + test.description;
|
|
28
|
+
};
|
|
13
29
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
red:
|
|
18
|
-
|
|
30
|
+
const formatFailureMessage = (test, error) => {
|
|
31
|
+
const messages = [];
|
|
32
|
+
messages.push(red(RESULT_MSG.CROSS) + test.path + test.description);
|
|
33
|
+
messages.push(red(` Error Message : ${error.message}`));
|
|
34
|
+
return messages.join('\n');
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getErrorMsg = (expect, actual) => {
|
|
38
|
+
return `Expected ${JSON.stringify(expect)} but got ${JSON.stringify(actual)}`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getThrowErrorMsg = (expect) => {
|
|
42
|
+
return `Expected function to throw an error containing "${expect}", but it did not throw`;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const placeHolder = {
|
|
46
|
+
's': (value) => value,
|
|
47
|
+
'o': (value) => JSON.stringify(value),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getMatcherForReplace = () => {
|
|
51
|
+
return new RegExp(`%([${Object.keys(placeHolder).join('')}])`, 'g')
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const mockStore = new Map();
|
|
55
|
+
|
|
56
|
+
const clearAllMocks = () => {
|
|
57
|
+
mockStore.clear();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const mock = (modulePath, mockExports) => {
|
|
61
|
+
mockStore.set(modulePath, mockExports);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const unmock = (modulePath) => {
|
|
65
|
+
mockStore.delete(modulePath);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const isMocked = (modulePath) => {
|
|
69
|
+
return mockStore.has(modulePath);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const getTestResultMsg = (title, success, fail) => {
|
|
73
|
+
let msg = '\n';
|
|
74
|
+
|
|
75
|
+
msg += title;
|
|
76
|
+
msg += green(success + ' passed') + ', ';
|
|
77
|
+
if (fail) {
|
|
78
|
+
msg += red(fail + ' failed') + ', ';
|
|
79
|
+
}
|
|
80
|
+
msg += bold(success + fail + ' total');
|
|
81
|
+
|
|
82
|
+
return msg;
|
|
19
83
|
};
|
|
20
84
|
|
|
21
85
|
class TestManager {
|
|
@@ -42,7 +106,7 @@ class TestManager {
|
|
|
42
106
|
}
|
|
43
107
|
await fn();
|
|
44
108
|
},
|
|
45
|
-
path: this.#testDepth.join(DIRECTORY_DELIMITER),
|
|
109
|
+
path: this.#testDepth.join(RESULT_MSG.DIRECTORY_DELIMITER),
|
|
46
110
|
};
|
|
47
111
|
this.#tests.push(testObj);
|
|
48
112
|
}
|
|
@@ -70,70 +134,43 @@ class TestManager {
|
|
|
70
134
|
this.#beforeEachArr = [];
|
|
71
135
|
}
|
|
72
136
|
|
|
137
|
+
async run() {
|
|
138
|
+
let passed = NUM.ZERO;
|
|
139
|
+
let failed = NUM.ZERO;
|
|
140
|
+
|
|
141
|
+
for (const test of testManager.getTests()) {
|
|
142
|
+
try {
|
|
143
|
+
await test.fn();
|
|
144
|
+
console.log(formatSuccessMessage(test));
|
|
145
|
+
passed++;
|
|
146
|
+
clearAllMocks();
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.log(formatFailureMessage(test, error));
|
|
149
|
+
failed++;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.log(getTestResultMsg(RESULT_MSG.TESTS, passed, failed));
|
|
154
|
+
|
|
155
|
+
testManager.clearTests();
|
|
156
|
+
|
|
157
|
+
return {passed, failed};
|
|
158
|
+
}
|
|
159
|
+
|
|
73
160
|
#formatDescription(args, description) {
|
|
74
161
|
let argIndex = 0;
|
|
75
|
-
return description.replace(
|
|
162
|
+
return description.replace(getMatcherForReplace(), (match, type) => {
|
|
76
163
|
if (argIndex >= args.length) return match;
|
|
77
164
|
|
|
78
|
-
const
|
|
165
|
+
const formatter = placeHolder[type];
|
|
79
166
|
|
|
80
|
-
|
|
81
|
-
case 's':
|
|
82
|
-
return arg;
|
|
83
|
-
case 'o':
|
|
84
|
-
return JSON.stringify(arg);
|
|
85
|
-
default:
|
|
86
|
-
return match;
|
|
87
|
-
}
|
|
167
|
+
return formatter ? formatter(args[argIndex++]) : match;
|
|
88
168
|
});
|
|
89
169
|
}
|
|
90
170
|
}
|
|
91
171
|
|
|
92
172
|
const testManager = new TestManager();
|
|
93
173
|
|
|
94
|
-
const mockStore = new Map();
|
|
95
|
-
|
|
96
|
-
function clearAllMocks() {
|
|
97
|
-
mockStore.clear();
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function mock(modulePath, mockExports) {
|
|
101
|
-
mockStore.set(modulePath, mockExports);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function unmock(modulePath) {
|
|
105
|
-
mockStore.delete(modulePath);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function isMocked(modulePath) {
|
|
109
|
-
return mockStore.has(modulePath);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const colorize = (text, color) => `${color}${text}${COLORS.reset}`;
|
|
113
|
-
|
|
114
|
-
const green = (text) => colorize(text, COLORS.green + COLORS.bold);
|
|
115
|
-
const red = (text) => colorize(text, COLORS.red + COLORS.bold);
|
|
116
|
-
const bold = (text) => colorize(text, COLORS.bold);
|
|
117
|
-
|
|
118
|
-
const formatSuccessMessage = (test) => {
|
|
119
|
-
const pathString = test.path === '' ? EMPTY : test.path + DIRECTORY_DELIMITER;
|
|
120
|
-
return green(CHECK) + pathString + test.description;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
const formatFailureMessage = (test, error) => {
|
|
124
|
-
const messages = [];
|
|
125
|
-
messages.push(red(CROSS) + test.path + test.description);
|
|
126
|
-
messages.push(red(` Error Message : ${error.message}`));
|
|
127
|
-
return messages.join('\n');
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const getErrorMsg = (expect, actual) => {
|
|
131
|
-
return `Expected ${JSON.stringify(expect)} but got ${JSON.stringify(actual)}`;
|
|
132
|
-
};
|
|
133
|
-
const getThrowErrorMsg = (expect) => {
|
|
134
|
-
return `Expected function to throw an error containing "${expect}", but it did not throw`;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
174
|
const runArgFnc = (actual) => {
|
|
138
175
|
if (typeof actual === 'function') {
|
|
139
176
|
return actual();
|
|
@@ -201,48 +238,75 @@ const expect = (actual) => {
|
|
|
201
238
|
}
|
|
202
239
|
};
|
|
203
240
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return msg;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const run = async () => {
|
|
218
|
-
let passed = DEFAULT_COUNT;
|
|
219
|
-
let failed = DEFAULT_COUNT;
|
|
220
|
-
|
|
221
|
-
for (const test of testManager.getTests()) {
|
|
222
|
-
try {
|
|
223
|
-
await test.fn();
|
|
224
|
-
console.log(formatSuccessMessage(test));
|
|
225
|
-
passed++;
|
|
226
|
-
clearAllMocks();
|
|
227
|
-
} catch (error) {
|
|
228
|
-
console.log(formatFailureMessage(test, error));
|
|
229
|
-
failed++;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
console.log(getTestResultMsg(RESULT_TITLE.TESTS, passed, failed));
|
|
234
|
-
|
|
235
|
-
testManager.clearTests();
|
|
236
|
-
|
|
237
|
-
return {passed, failed};
|
|
238
|
-
};
|
|
239
|
-
|
|
241
|
+
/**
|
|
242
|
+
* 테스트 케이스를 정의합니다.
|
|
243
|
+
* @param {string} description - 테스트 설명
|
|
244
|
+
* @param {Function} fn - 테스트 함수
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* test('더하기 테스트', () => {
|
|
248
|
+
* expect(1 + 2).toBe(3);
|
|
249
|
+
* });
|
|
250
|
+
*/
|
|
240
251
|
const test = (description, fn) => testManager.test(description, fn);
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* 배열 형태의 테스트 케이스를 반복 실행합니다.
|
|
255
|
+
* @param {Array<Array>} cases - 테스트 케이스 배열
|
|
256
|
+
* @returns {Function} 테스트 실행 함수
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* test.each([
|
|
260
|
+
* [1, 2, 3],
|
|
261
|
+
* [2, 3, 5],
|
|
262
|
+
* ])('add(%s, %s) = %s', (a, b, expected) => {
|
|
263
|
+
* expect(a + b).toBe(expected);
|
|
264
|
+
* });
|
|
265
|
+
*/
|
|
241
266
|
test.each = (cases) => testManager.testEach(cases);
|
|
242
267
|
|
|
268
|
+
/**
|
|
269
|
+
* 테스트 그룹을 정의합니다. 중첩 가능합니다.
|
|
270
|
+
* @param {string} suiteName - 그룹 이름
|
|
271
|
+
* @param {Function} fn - 그룹 내부 테스트들을 정의하는 함수
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* describe('계산기', () => {
|
|
275
|
+
* test('더하기', () => {
|
|
276
|
+
* expect(1 + 1).toBe(2);
|
|
277
|
+
* });
|
|
278
|
+
* });
|
|
279
|
+
*/
|
|
243
280
|
const describe = (suiteName, fn) => testManager.describe(suiteName, fn);
|
|
244
281
|
|
|
282
|
+
/**
|
|
283
|
+
* 각 테스트 실행 전에 실행될 함수를 등록합니다.
|
|
284
|
+
* @param {Function} fn - 전처리 함수
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* describe('카운터 테스트', () => {
|
|
288
|
+
* let counter;
|
|
289
|
+
*
|
|
290
|
+
* beforeEach(() => {
|
|
291
|
+
* counter = 0;
|
|
292
|
+
* });
|
|
293
|
+
*
|
|
294
|
+
* test('초기값은 0', () => {
|
|
295
|
+
* expect(counter).toBe(0);
|
|
296
|
+
* });
|
|
297
|
+
* });
|
|
298
|
+
*/
|
|
245
299
|
const beforeEach = (fn) => testManager.beforeEach(fn);
|
|
246
300
|
|
|
301
|
+
/**
|
|
302
|
+
* 등록된 모든 테스트를 실행합니다.
|
|
303
|
+
* @returns {Promise<{passed: number, failed: number}>} 테스트 결과
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* const { passed, failed } = await run();
|
|
307
|
+
* console.log(`${passed} passed, ${failed} failed`);
|
|
308
|
+
*/
|
|
309
|
+
const run = () => testManager.run();
|
|
310
|
+
|
|
247
311
|
export { beforeEach, clearAllMocks, describe, expect, isMocked, mock, mockStore, run, test, unmock };
|
|
248
312
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +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,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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,EAAE,OAAO,GAAG;AACZ,CAAC;;ACPW,MAAC,GAAG,GAAG,YAAY;AAC/B,EAAE,IAAI,MAAM,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
|
+
{"version":3,"file":"index.mjs","sources":["../src/constants/view.js","../src/utils/consoleColor.js","../src/constants/index.js","../src/utils/formatString.js","../src/mock/store.js","../src/utils/messages.js","../src/testManager.js","../src/matchers.js","../src/expect.js","../index.js"],"sourcesContent":["export 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","import {COLORS} from \"../constants/view.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);\n","export 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 DANNYSIR_JS_TE: '@dannysir/js-te',\n};\n\nexport const RESULT_MSG = {\n TESTS: 'Tests: ',\n TOTAL: 'Total Result: ',\n CHECK: '✓ ',\n CROSS: '✗ ',\n DIRECTORY_DELIMITER: ' > ',\n EMPTY: '',\n};\n\nexport const NUM = {\n ZERO: 0,\n ONE: 1,\n};\n\nexport const MODULE_TYPE = {\n MODULE: 'module',\n ESM: 'esm',\n CJS: 'cjs',\n};\n","import {green, red} from \"./consoleColor.js\";\nimport {RESULT_MSG} from \"../constants/index.js\";\n\nexport const formatSuccessMessage = (test) => {\n const pathString = test.path === '' ? RESULT_MSG.EMPTY : test.path + RESULT_MSG.DIRECTORY_DELIMITER;\n return green(RESULT_MSG.CHECK) + pathString + test.description;\n};\n\nexport const formatFailureMessage = (test, error) => {\n const messages = [];\n messages.push(red(RESULT_MSG.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};\n\nexport const getThrowErrorMsg = (expect) => {\n return `Expected function to throw an error containing \"${expect}\", but it did not throw`;\n};\n\nexport const placeHolder = {\n 's': (value) => value,\n 'o': (value) => JSON.stringify(value),\n};\n\nexport const getMatcherForReplace = () => {\n return new RegExp(`%([${Object.keys(placeHolder).join('')}])`, 'g')\n};\n","export const mockStore = new Map();\n\nexport const clearAllMocks = () => {\n mockStore.clear();\n}\n\nexport const mock = (modulePath, mockExports) => {\n mockStore.set(modulePath, mockExports);\n}\n\nexport const unmock = (modulePath) => {\n mockStore.delete(modulePath);\n}\n\nexport const isMocked = (modulePath) => {\n return mockStore.has(modulePath);\n}\n","import {bold, green, red, yellow} 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};\n\nexport const getFileCountString = (n) => {\n return `\\nFound ${green(n)} test file(s)`;\n};\n\nexport const getFilePath = (path) => {\n return `\\n${yellow(path)}\\n`;\n};\n\nexport const getErrorMsgInLogic = (error) => {\n return red(`\\n✗ Test execution failed\\n Error: ${error}\\n`)\n};\n","import {formatFailureMessage, formatSuccessMessage, getMatcherForReplace, placeHolder} from \"./utils/formatString.js\";\nimport {clearAllMocks} from \"./mock/store.js\";\nimport {NUM, RESULT_MSG} from \"./constants/index.js\";\nimport {getTestResultMsg} from \"./utils/messages.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(RESULT_MSG.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 async run() {\n let passed = NUM.ZERO;\n let failed = NUM.ZERO;\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_MSG.TESTS, passed, failed));\n\n testManager.clearTests();\n\n return {passed, failed};\n }\n\n #formatDescription(args, description) {\n let argIndex = 0;\n return description.replace(getMatcherForReplace(), (match, type) => {\n if (argIndex >= args.length) return match;\n\n const formatter = placeHolder[type];\n\n return formatter ? formatter(args[argIndex++]) : match;\n });\n }\n}\n\nexport const testManager = new TestManager();","import {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 {testManager} from \"./src/testManager.js\";\nimport {clearAllMocks, isMocked, mock, unmock, mockStore} from './src/mock/store.js';\nimport {expect} from \"./src/expect.js\";\n\n/**\n * 테스트 케이스를 정의합니다.\n * @param {string} description - 테스트 설명\n * @param {Function} fn - 테스트 함수\n *\n * @example\n * test('더하기 테스트', () => {\n * expect(1 + 2).toBe(3);\n * });\n */\nexport const test = (description, fn) => testManager.test(description, fn);\n\n/**\n * 배열 형태의 테스트 케이스를 반복 실행합니다.\n * @param {Array<Array>} cases - 테스트 케이스 배열\n * @returns {Function} 테스트 실행 함수\n *\n * @example\n * test.each([\n * [1, 2, 3],\n * [2, 3, 5],\n * ])('add(%s, %s) = %s', (a, b, expected) => {\n * expect(a + b).toBe(expected);\n * });\n */\ntest.each = (cases) => testManager.testEach(cases);\n\n/**\n * 테스트 그룹을 정의합니다. 중첩 가능합니다.\n * @param {string} suiteName - 그룹 이름\n * @param {Function} fn - 그룹 내부 테스트들을 정의하는 함수\n *\n * @example\n * describe('계산기', () => {\n * test('더하기', () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\nexport const describe = (suiteName, fn) => testManager.describe(suiteName, fn);\n\n/**\n * 각 테스트 실행 전에 실행될 함수를 등록합니다.\n * @param {Function} fn - 전처리 함수\n *\n * @example\n * describe('카운터 테스트', () => {\n * let counter;\n *\n * beforeEach(() => {\n * counter = 0;\n * });\n *\n * test('초기값은 0', () => {\n * expect(counter).toBe(0);\n * });\n * });\n */\nexport const beforeEach = (fn) => testManager.beforeEach(fn);\n\n/**\n * 등록된 모든 테스트를 실행합니다.\n * @returns {Promise<{passed: number, failed: number}>} 테스트 결과\n *\n * @example\n * const { passed, failed } = await run();\n * console.log(`${passed} passed, ${failed} failed`);\n */\nexport const run = () => testManager.run();\n\n/**\n * 값을 검증하는 matcher 함수들을 반환합니다.\n * @function\n * @param {*} actual - 검증할 값\n * @returns {Object} matcher 함수들\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect([1, 2, 3]).toEqual([1, 2, 3]);\n * expect(() => { throw new Error('error') }).toThrow('error');\n * expect(true).toBeTruthy();\n * expect(false).toBeFalsy();\n */\nexport {expect};\n\nexport {mock, clearAllMocks, unmock, isMocked, mockStore};\n"],"names":[],"mappings":"AAAO,MAAM,MAAM,GAAG;AACtB,EAAE,KAAK,EAAE,SAAS;AAClB,EAAE,KAAK,EAAE,UAAU;AACnB,EAAE,GAAG,EAAE,UAAU;AACjB,EAGE,IAAI,EAAE;AACR,CAAC;;ACNM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;;AAElE,MAAM,KAAK,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC;AAClE,MAAM,GAAG,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC;AAC9D,MAAM,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC;;ACIlD,MAAM,UAAU,GAAG;AAC1B,EAAE,KAAK,EAAE,SAAS;AAClB,EACE,KAAK,EAAE,IAAI;AACb,EAAE,KAAK,EAAE,IAAI;AACb,EAAE,mBAAmB,EAAE,KAAK;AAC5B,EAAE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MAAM,CAAC;AACxB,IAAI,CAAC;AACL,IAAI,SAAS,GAAG;AAChB,MAAM,SAAS,CAAC,MAAM,CAAC;AACvB,IAAI;AACJ;AACA;;AChBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,WAAW,EAAE,EAAE,KAAK,WAAW,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;;AAEzE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,CAAC,IAAI,GAAG,CAAC,KAAK,KAAK,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,QAAQ,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,WAAW,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE;;AAE7E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,UAAU,GAAG,CAAC,EAAE,KAAK,WAAW,CAAC,UAAU,CAAC,EAAE;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,MAAM,WAAW,CAAC,GAAG;;;;"}
|
package/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {testManager} from "./src/testManager.js";
|
|
2
|
+
import {clearAllMocks, isMocked, mock, unmock, mockStore} from './src/mock/store.js';
|
|
3
|
+
import {expect} from "./src/expect.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 테스트 케이스를 정의합니다.
|
|
7
|
+
* @param {string} description - 테스트 설명
|
|
8
|
+
* @param {Function} fn - 테스트 함수
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* test('더하기 테스트', () => {
|
|
12
|
+
* expect(1 + 2).toBe(3);
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
export const test = (description, fn) => testManager.test(description, fn);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 배열 형태의 테스트 케이스를 반복 실행합니다.
|
|
19
|
+
* @param {Array<Array>} cases - 테스트 케이스 배열
|
|
20
|
+
* @returns {Function} 테스트 실행 함수
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* test.each([
|
|
24
|
+
* [1, 2, 3],
|
|
25
|
+
* [2, 3, 5],
|
|
26
|
+
* ])('add(%s, %s) = %s', (a, b, expected) => {
|
|
27
|
+
* expect(a + b).toBe(expected);
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
test.each = (cases) => testManager.testEach(cases);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 테스트 그룹을 정의합니다. 중첩 가능합니다.
|
|
34
|
+
* @param {string} suiteName - 그룹 이름
|
|
35
|
+
* @param {Function} fn - 그룹 내부 테스트들을 정의하는 함수
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* describe('계산기', () => {
|
|
39
|
+
* test('더하기', () => {
|
|
40
|
+
* expect(1 + 1).toBe(2);
|
|
41
|
+
* });
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
export const describe = (suiteName, fn) => testManager.describe(suiteName, fn);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 각 테스트 실행 전에 실행될 함수를 등록합니다.
|
|
48
|
+
* @param {Function} fn - 전처리 함수
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* describe('카운터 테스트', () => {
|
|
52
|
+
* let counter;
|
|
53
|
+
*
|
|
54
|
+
* beforeEach(() => {
|
|
55
|
+
* counter = 0;
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* test('초기값은 0', () => {
|
|
59
|
+
* expect(counter).toBe(0);
|
|
60
|
+
* });
|
|
61
|
+
* });
|
|
62
|
+
*/
|
|
63
|
+
export const beforeEach = (fn) => testManager.beforeEach(fn);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 등록된 모든 테스트를 실행합니다.
|
|
67
|
+
* @returns {Promise<{passed: number, failed: number}>} 테스트 결과
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* const { passed, failed } = await run();
|
|
71
|
+
* console.log(`${passed} passed, ${failed} failed`);
|
|
72
|
+
*/
|
|
73
|
+
export const run = () => testManager.run();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 값을 검증하는 matcher 함수들을 반환합니다.
|
|
77
|
+
* @function
|
|
78
|
+
* @param {*} actual - 검증할 값
|
|
79
|
+
* @returns {Object} matcher 함수들
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* expect(1 + 1).toBe(2);
|
|
83
|
+
* expect([1, 2, 3]).toEqual([1, 2, 3]);
|
|
84
|
+
* expect(() => { throw new Error('error') }).toThrow('error');
|
|
85
|
+
* expect(true).toBeTruthy();
|
|
86
|
+
* expect(false).toBeFalsy();
|
|
87
|
+
*/
|
|
88
|
+
export {expect};
|
|
89
|
+
|
|
90
|
+
export {mock, clearAllMocks, unmock, isMocked, mockStore};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dannysir/js-te",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "JavaScript test library",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"./src/mock/store.js": "./src/mock/store.js"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
|
-
"js-te": "
|
|
16
|
+
"js-te": "bin/cli.js"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"clean": "rimraf dist",
|
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
"files": [
|
|
25
25
|
"bin/",
|
|
26
26
|
"dist/",
|
|
27
|
-
"utils/",
|
|
28
27
|
"src/",
|
|
29
|
-
"
|
|
30
|
-
"constants.js"
|
|
28
|
+
"index.js"
|
|
31
29
|
],
|
|
32
30
|
"keywords": [
|
|
33
31
|
"javascript",
|
|
@@ -52,7 +50,7 @@
|
|
|
52
50
|
},
|
|
53
51
|
"repository": {
|
|
54
52
|
"type": "git",
|
|
55
|
-
"url": "git+https://github.com/dannysir/js-te-package"
|
|
53
|
+
"url": "git+https://github.com/dannysir/js-te-package.git"
|
|
56
54
|
},
|
|
57
55
|
"bugs": {
|
|
58
56
|
"url": "https://github.com/dannysir/js-te-package/issues"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
import {BABEL} from "../constants/babel.js";
|
|
4
|
+
|
|
5
|
+
export const createMockCollectorPlugin = (mockedPaths) => {
|
|
6
|
+
return ({types: t}) => {
|
|
7
|
+
return {
|
|
8
|
+
visitor: {
|
|
9
|
+
CallExpression(nodePath, state) {
|
|
10
|
+
if (!t.isIdentifier(nodePath.node.callee, {name: 'mock'})) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const args = nodePath.node.arguments;
|
|
15
|
+
if (args.length < 1 || !t.isStringLiteral(args[0])) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const mockPath = args[0].value;
|
|
20
|
+
const currentFilePath = state.filename || process.cwd();
|
|
21
|
+
const currentDir = path.dirname(currentFilePath);
|
|
22
|
+
|
|
23
|
+
let absolutePath;
|
|
24
|
+
if (mockPath.startsWith(BABEL.PERIOD)) {
|
|
25
|
+
absolutePath = path.resolve(currentDir, mockPath);
|
|
26
|
+
} else {
|
|
27
|
+
absolutePath = mockPath;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
mockedPaths.add(absolutePath);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
};
|