@hz-9/a5-core 0.2.0-alpha.1
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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/all.d.ts +676 -0
- package/dist/const/index.d.ts +38 -0
- package/dist/const/index.js +46 -0
- package/dist/core/__import-reflect-metadata.d.ts +1 -0
- package/dist/core/__import-reflect-metadata.js +4 -0
- package/dist/core/a5-application.d.ts +154 -0
- package/dist/core/a5-application.js +315 -0
- package/dist/core/a5-console-logger.d.ts +163 -0
- package/dist/core/a5-console-logger.js +354 -0
- package/dist/core/a5-factory.d.ts +21 -0
- package/dist/core/a5-factory.js +49 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +24 -0
- package/dist/interface/base.d.ts +18 -0
- package/dist/interface/base.js +3 -0
- package/dist/interface/http.d.ts +16 -0
- package/dist/interface/http.js +3 -0
- package/dist/interface/index.d.ts +3 -0
- package/dist/interface/index.js +20 -0
- package/dist/interface/provide-token.d.ts +21 -0
- package/dist/interface/provide-token.js +3 -0
- package/dist/middleware/a5-console-logger.middleware.d.ts +9 -0
- package/dist/middleware/a5-console-logger.middleware.js +58 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +18 -0
- package/dist/module/config/index.d.ts +18 -0
- package/dist/module/config/index.js +36 -0
- package/dist/module/config/interface.d.ts +9 -0
- package/dist/module/config/interface.js +15 -0
- package/dist/module/index.d.ts +2 -0
- package/dist/module/index.js +19 -0
- package/dist/module/log/index.d.ts +18 -0
- package/dist/module/log/index.js +44 -0
- package/dist/module/log/interface.d.ts +9 -0
- package/dist/module/log/interface.js +15 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +18 -0
- package/dist/plugins/nanoid.d.ts +1 -0
- package/dist/plugins/nanoid.js +6 -0
- package/dist/test/integration/core/a5-factory.integration.spec.d.ts +1 -0
- package/dist/test/integration/core/a5-factory.integration.spec.js +99 -0
- package/dist/test/integration/core/with-logger-module.integration.spec.d.ts +1 -0
- package/dist/test/integration/core/with-logger-module.integration.spec.js +401 -0
- package/dist/test/unit/core/a5-application.unit.spec.d.ts +1 -0
- package/dist/test/unit/core/a5-application.unit.spec.js +450 -0
- package/dist/test/unit/core/a5-console-logger.unit.spec.d.ts +1 -0
- package/dist/test/unit/core/a5-console-logger.unit.spec.js +998 -0
- package/dist/test/unit/middleware/a5-console-logger.middleware.unit.spec.d.ts +1 -0
- package/dist/test/unit/middleware/a5-console-logger.middleware.unit.spec.js +379 -0
- package/dist/test/unit/util/a5.util.unit.spec.d.ts +1 -0
- package/dist/test/unit/util/a5.util.unit.spec.js +109 -0
- package/dist/test/unit/util/color.util.unit.spec.d.ts +1 -0
- package/dist/test/unit/util/color.util.unit.spec.js +277 -0
- package/dist/test/unit/util/logo.util.unit.spec.d.ts +1 -0
- package/dist/test/unit/util/logo.util.unit.spec.js +202 -0
- package/dist/test/unit/util/run-env.util.unit.spec.d.ts +1 -0
- package/dist/test/unit/util/run-env.util.unit.spec.js +183 -0
- package/dist/util/a5.util.d.ts +27 -0
- package/dist/util/a5.util.js +41 -0
- package/dist/util/color.util.d.ts +26 -0
- package/dist/util/color.util.js +62 -0
- package/dist/util/index.d.ts +5 -0
- package/dist/util/index.js +22 -0
- package/dist/util/load-package.util.d.ts +29 -0
- package/dist/util/load-package.util.js +71 -0
- package/dist/util/logo.util.d.ts +31 -0
- package/dist/util/logo.util.js +59 -0
- package/dist/util/run-env.util.d.ts +28 -0
- package/dist/util/run-env.util.js +48 -0
- package/logo +7 -0
- package/package.json +96 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const color_util_1 = require("../../../util/color.util");
|
|
4
|
+
describe('ColorUtil Unit Test', () => {
|
|
5
|
+
const originalEnv = process.env;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
jest.resetModules();
|
|
8
|
+
process.env = { ...originalEnv };
|
|
9
|
+
});
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
process.env = originalEnv;
|
|
12
|
+
});
|
|
13
|
+
describe('[[Static Public Properties]]', () => {
|
|
14
|
+
describe('[[Properties]]', () => {
|
|
15
|
+
describe('isColorAllowed', () => {
|
|
16
|
+
it('should return true when NO_COLOR is not set', () => {
|
|
17
|
+
delete process.env.NO_COLOR;
|
|
18
|
+
expect(color_util_1.ColorUtil.isColorAllowed).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
it('should return false when NO_COLOR is set to non-empty string', () => {
|
|
21
|
+
process.env.NO_COLOR = '1';
|
|
22
|
+
expect(color_util_1.ColorUtil.isColorAllowed).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it('should return false when NO_COLOR is set to empty string', () => {
|
|
25
|
+
process.env.NO_COLOR = '';
|
|
26
|
+
expect(color_util_1.ColorUtil.isColorAllowed).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
it('should return false when NO_COLOR is set to truthy value', () => {
|
|
29
|
+
process.env.NO_COLOR = 'true';
|
|
30
|
+
expect(color_util_1.ColorUtil.isColorAllowed).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
it('should return false when NO_COLOR is set to any value', () => {
|
|
33
|
+
process.env.NO_COLOR = 'disable';
|
|
34
|
+
expect(color_util_1.ColorUtil.isColorAllowed).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
describe('[[Static Public Methods]]', () => {
|
|
40
|
+
describe('bold', () => {
|
|
41
|
+
describe('text', () => {
|
|
42
|
+
it('should wrap text with bold ANSI codes when color is allowed', () => {
|
|
43
|
+
delete process.env.NO_COLOR;
|
|
44
|
+
const result = color_util_1.ColorUtil.bold('test');
|
|
45
|
+
expect(result).toBe('\x1B[1mtest\x1B[0m');
|
|
46
|
+
});
|
|
47
|
+
it('should return plain text when color is not allowed', () => {
|
|
48
|
+
process.env.NO_COLOR = '1';
|
|
49
|
+
const result = color_util_1.ColorUtil.bold('test');
|
|
50
|
+
expect(result).toBe('test');
|
|
51
|
+
});
|
|
52
|
+
it('should handle empty string', () => {
|
|
53
|
+
delete process.env.NO_COLOR;
|
|
54
|
+
const result = color_util_1.ColorUtil.bold('');
|
|
55
|
+
expect(result).toBe('\x1B[1m\x1B[0m');
|
|
56
|
+
});
|
|
57
|
+
it('should handle text with special characters', () => {
|
|
58
|
+
delete process.env.NO_COLOR;
|
|
59
|
+
const result = color_util_1.ColorUtil.bold('test!@#$%^&*()');
|
|
60
|
+
expect(result).toBe('\x1B[1mtest!@#$%^&*()\x1B[0m');
|
|
61
|
+
});
|
|
62
|
+
it('should handle multiline text', () => {
|
|
63
|
+
delete process.env.NO_COLOR;
|
|
64
|
+
const result = color_util_1.ColorUtil.bold('line1\nline2');
|
|
65
|
+
expect(result).toBe('\x1B[1mline1\nline2\x1B[0m');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('red', () => {
|
|
70
|
+
describe('text', () => {
|
|
71
|
+
it('should wrap text with red ANSI codes when color is allowed', () => {
|
|
72
|
+
delete process.env.NO_COLOR;
|
|
73
|
+
const result = color_util_1.ColorUtil.red('test');
|
|
74
|
+
expect(result).toBe('\x1B[31mtest\x1B[39m');
|
|
75
|
+
});
|
|
76
|
+
it('should return plain text when color is not allowed', () => {
|
|
77
|
+
process.env.NO_COLOR = '1';
|
|
78
|
+
const result = color_util_1.ColorUtil.red('test');
|
|
79
|
+
expect(result).toBe('test');
|
|
80
|
+
});
|
|
81
|
+
it('should handle empty string', () => {
|
|
82
|
+
delete process.env.NO_COLOR;
|
|
83
|
+
const result = color_util_1.ColorUtil.red('');
|
|
84
|
+
expect(result).toBe('\x1B[31m\x1B[39m');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
describe('green', () => {
|
|
89
|
+
describe('text', () => {
|
|
90
|
+
it('should wrap text with green ANSI codes when color is allowed', () => {
|
|
91
|
+
delete process.env.NO_COLOR;
|
|
92
|
+
const result = color_util_1.ColorUtil.green('test');
|
|
93
|
+
expect(result).toBe('\x1B[32mtest\x1B[39m');
|
|
94
|
+
});
|
|
95
|
+
it('should return plain text when color is not allowed', () => {
|
|
96
|
+
process.env.NO_COLOR = '1';
|
|
97
|
+
const result = color_util_1.ColorUtil.green('test');
|
|
98
|
+
expect(result).toBe('test');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('yellow', () => {
|
|
103
|
+
describe('text', () => {
|
|
104
|
+
it('should wrap text with yellow ANSI codes when color is allowed', () => {
|
|
105
|
+
delete process.env.NO_COLOR;
|
|
106
|
+
const result = color_util_1.ColorUtil.yellow('test');
|
|
107
|
+
expect(result).toBe('\x1B[33mtest\x1B[39m');
|
|
108
|
+
});
|
|
109
|
+
it('should return plain text when color is not allowed', () => {
|
|
110
|
+
process.env.NO_COLOR = '1';
|
|
111
|
+
const result = color_util_1.ColorUtil.yellow('test');
|
|
112
|
+
expect(result).toBe('test');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
describe('blue', () => {
|
|
117
|
+
describe('text', () => {
|
|
118
|
+
it('should wrap text with blue ANSI codes when color is allowed', () => {
|
|
119
|
+
delete process.env.NO_COLOR;
|
|
120
|
+
const result = color_util_1.ColorUtil.blue('test');
|
|
121
|
+
expect(result).toBe('\x1B[34mtest\x1B[39m');
|
|
122
|
+
});
|
|
123
|
+
it('should return plain text when color is not allowed', () => {
|
|
124
|
+
process.env.NO_COLOR = '1';
|
|
125
|
+
const result = color_util_1.ColorUtil.blue('test');
|
|
126
|
+
expect(result).toBe('test');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
describe('magenta', () => {
|
|
131
|
+
describe('text', () => {
|
|
132
|
+
it('should wrap text with magenta ANSI codes when color is allowed', () => {
|
|
133
|
+
delete process.env.NO_COLOR;
|
|
134
|
+
const result = color_util_1.ColorUtil.magenta('test');
|
|
135
|
+
expect(result).toBe('\x1B[35mtest\x1B[39m');
|
|
136
|
+
});
|
|
137
|
+
it('should return plain text when color is not allowed', () => {
|
|
138
|
+
process.env.NO_COLOR = '1';
|
|
139
|
+
const result = color_util_1.ColorUtil.magenta('test');
|
|
140
|
+
expect(result).toBe('test');
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
describe('cyan', () => {
|
|
145
|
+
describe('text', () => {
|
|
146
|
+
it('should wrap text with cyan ANSI codes when color is allowed', () => {
|
|
147
|
+
delete process.env.NO_COLOR;
|
|
148
|
+
const result = color_util_1.ColorUtil.cyan('test');
|
|
149
|
+
expect(result).toBe('\x1B[36mtest\x1B[39m');
|
|
150
|
+
});
|
|
151
|
+
it('should return plain text when color is not allowed', () => {
|
|
152
|
+
process.env.NO_COLOR = '1';
|
|
153
|
+
const result = color_util_1.ColorUtil.cyan('test');
|
|
154
|
+
expect(result).toBe('test');
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('redBright', () => {
|
|
159
|
+
describe('text', () => {
|
|
160
|
+
it('should wrap text with bright red ANSI codes when color is allowed', () => {
|
|
161
|
+
delete process.env.NO_COLOR;
|
|
162
|
+
const result = color_util_1.ColorUtil.redBright('test');
|
|
163
|
+
expect(result).toBe('\x1B[91mtest\x1B[39m');
|
|
164
|
+
});
|
|
165
|
+
it('should return plain text when color is not allowed', () => {
|
|
166
|
+
process.env.NO_COLOR = '1';
|
|
167
|
+
const result = color_util_1.ColorUtil.redBright('test');
|
|
168
|
+
expect(result).toBe('test');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
describe('greenBright', () => {
|
|
173
|
+
describe('text', () => {
|
|
174
|
+
it('should wrap text with bright green ANSI codes when color is allowed', () => {
|
|
175
|
+
delete process.env.NO_COLOR;
|
|
176
|
+
const result = color_util_1.ColorUtil.greenBright('test');
|
|
177
|
+
expect(result).toBe('\x1B[92mtest\x1B[39m');
|
|
178
|
+
});
|
|
179
|
+
it('should return plain text when color is not allowed', () => {
|
|
180
|
+
process.env.NO_COLOR = '1';
|
|
181
|
+
const result = color_util_1.ColorUtil.greenBright('test');
|
|
182
|
+
expect(result).toBe('test');
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
describe('yellowBright', () => {
|
|
187
|
+
describe('text', () => {
|
|
188
|
+
it('should wrap text with bright yellow ANSI codes when color is allowed', () => {
|
|
189
|
+
delete process.env.NO_COLOR;
|
|
190
|
+
const result = color_util_1.ColorUtil.yellowBright('test');
|
|
191
|
+
expect(result).toBe('\x1B[93mtest\x1B[39m');
|
|
192
|
+
});
|
|
193
|
+
it('should return plain text when color is not allowed', () => {
|
|
194
|
+
process.env.NO_COLOR = '1';
|
|
195
|
+
const result = color_util_1.ColorUtil.yellowBright('test');
|
|
196
|
+
expect(result).toBe('test');
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('blueBright', () => {
|
|
201
|
+
describe('text', () => {
|
|
202
|
+
it('should wrap text with bright blue ANSI codes when color is allowed', () => {
|
|
203
|
+
delete process.env.NO_COLOR;
|
|
204
|
+
const result = color_util_1.ColorUtil.blueBright('test');
|
|
205
|
+
expect(result).toBe('\x1B[94mtest\x1B[39m');
|
|
206
|
+
});
|
|
207
|
+
it('should return plain text when color is not allowed', () => {
|
|
208
|
+
process.env.NO_COLOR = '1';
|
|
209
|
+
const result = color_util_1.ColorUtil.blueBright('test');
|
|
210
|
+
expect(result).toBe('test');
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
describe('magentaBright', () => {
|
|
215
|
+
describe('text', () => {
|
|
216
|
+
it('should wrap text with bright magenta ANSI codes when color is allowed', () => {
|
|
217
|
+
delete process.env.NO_COLOR;
|
|
218
|
+
const result = color_util_1.ColorUtil.magentaBright('test');
|
|
219
|
+
expect(result).toBe('\x1B[95mtest\x1B[39m');
|
|
220
|
+
});
|
|
221
|
+
it('should return plain text when color is not allowed', () => {
|
|
222
|
+
process.env.NO_COLOR = '1';
|
|
223
|
+
const result = color_util_1.ColorUtil.magentaBright('test');
|
|
224
|
+
expect(result).toBe('test');
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
describe('cyanBright', () => {
|
|
229
|
+
describe('text', () => {
|
|
230
|
+
it('should wrap text with bright cyan ANSI codes when color is allowed', () => {
|
|
231
|
+
delete process.env.NO_COLOR;
|
|
232
|
+
const result = color_util_1.ColorUtil.cyanBright('test');
|
|
233
|
+
expect(result).toBe('\x1B[96mtest\x1B[39m');
|
|
234
|
+
});
|
|
235
|
+
it('should return plain text when color is not allowed', () => {
|
|
236
|
+
process.env.NO_COLOR = '1';
|
|
237
|
+
const result = color_util_1.ColorUtil.cyanBright('test');
|
|
238
|
+
expect(result).toBe('test');
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
describe('clear', () => {
|
|
243
|
+
describe('text', () => {
|
|
244
|
+
it('should remove ANSI color codes from text', () => {
|
|
245
|
+
const coloredText = '\x1B[31mred text\x1B[39m';
|
|
246
|
+
const result = color_util_1.ColorUtil.clear(coloredText);
|
|
247
|
+
expect(result).toBe('red text');
|
|
248
|
+
});
|
|
249
|
+
it('should remove multiple ANSI color codes from text', () => {
|
|
250
|
+
const coloredText = '\x1B[31mred\x1B[39m \x1B[32mgreen\x1B[39m';
|
|
251
|
+
const result = color_util_1.ColorUtil.clear(coloredText);
|
|
252
|
+
expect(result).toBe('red green');
|
|
253
|
+
});
|
|
254
|
+
it('should handle text without ANSI codes', () => {
|
|
255
|
+
const plainText = 'plain text';
|
|
256
|
+
const result = color_util_1.ColorUtil.clear(plainText);
|
|
257
|
+
expect(result).toBe('plain text');
|
|
258
|
+
});
|
|
259
|
+
it('should handle empty string', () => {
|
|
260
|
+
const result = color_util_1.ColorUtil.clear('');
|
|
261
|
+
expect(result).toBe('');
|
|
262
|
+
});
|
|
263
|
+
it('should remove complex ANSI codes', () => {
|
|
264
|
+
const complexText = '\x1B[1;31mBold Red\x1B[0m';
|
|
265
|
+
const result = color_util_1.ColorUtil.clear(complexText);
|
|
266
|
+
expect(result).toBe('Bold Red');
|
|
267
|
+
});
|
|
268
|
+
it('should handle text with mixed content', () => {
|
|
269
|
+
const mixedText = 'normal \x1B[31mred\x1B[39m normal';
|
|
270
|
+
const result = color_util_1.ColorUtil.clear(mixedText);
|
|
271
|
+
expect(result).toBe('normal red normal');
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
//# sourceMappingURL=color.util.unit.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_console_1 = __importDefault(require("node:console"));
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const color_util_1 = require("../../../util/color.util");
|
|
10
|
+
const logo_util_1 = require("../../../util/logo.util");
|
|
11
|
+
describe('LogoUtil Unit Test', () => {
|
|
12
|
+
const toClearLines = (lines) => lines.map(([text]) => color_util_1.ColorUtil.clear(text));
|
|
13
|
+
const logoContent = node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../../../logo'), { encoding: 'utf8' });
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
// @ts-expect-error: Accessing private property for testing
|
|
17
|
+
logo_util_1.LogoUtil._content = undefined;
|
|
18
|
+
});
|
|
19
|
+
describe('[[Public Static Properties]]', () => {
|
|
20
|
+
describe('content', () => {
|
|
21
|
+
it('should read and return the logo content from file', () => {
|
|
22
|
+
expect(logo_util_1.LogoUtil.content).toBe(logoContent);
|
|
23
|
+
});
|
|
24
|
+
it('should cache the logo content after first read', () => {
|
|
25
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockReturnValue(logoContent);
|
|
26
|
+
const content1 = logo_util_1.LogoUtil.content;
|
|
27
|
+
const content2 = logo_util_1.LogoUtil.content;
|
|
28
|
+
expect(content1).toBe(logoContent);
|
|
29
|
+
expect(content2).toBe(logoContent);
|
|
30
|
+
expect(fsSpy).toHaveBeenCalledTimes(1);
|
|
31
|
+
fsSpy.mockRestore();
|
|
32
|
+
});
|
|
33
|
+
it('should not read file multiple times', () => {
|
|
34
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockReturnValue(logoContent);
|
|
35
|
+
const content1 = logo_util_1.LogoUtil.content;
|
|
36
|
+
const content2 = logo_util_1.LogoUtil.content;
|
|
37
|
+
const content3 = logo_util_1.LogoUtil.content;
|
|
38
|
+
expect(content1).toBe(logoContent);
|
|
39
|
+
expect(content2).toBe(logoContent);
|
|
40
|
+
expect(content3).toBe(logoContent);
|
|
41
|
+
expect(fsSpy).toHaveBeenCalledTimes(1);
|
|
42
|
+
fsSpy.mockRestore();
|
|
43
|
+
});
|
|
44
|
+
it('should handle file read errors gracefully', () => {
|
|
45
|
+
// @ts-expect-error: Reset private property
|
|
46
|
+
logo_util_1.LogoUtil._content = undefined;
|
|
47
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockImplementation(() => {
|
|
48
|
+
throw new Error('File not found');
|
|
49
|
+
});
|
|
50
|
+
expect(() => logo_util_1.LogoUtil.content).toThrow('File not found');
|
|
51
|
+
fsSpy.mockRestore();
|
|
52
|
+
});
|
|
53
|
+
it('should handle missing logo file', () => {
|
|
54
|
+
// @ts-expect-error: Reset private property
|
|
55
|
+
logo_util_1.LogoUtil._content = undefined;
|
|
56
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockImplementation(() => {
|
|
57
|
+
const error = new Error('ENOENT: no such file or directory');
|
|
58
|
+
// @ts-expect-error: Add code property
|
|
59
|
+
error.code = 'ENOENT';
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
expect(() => logo_util_1.LogoUtil.content).toThrow();
|
|
63
|
+
fsSpy.mockRestore();
|
|
64
|
+
});
|
|
65
|
+
it('should handle empty logo file', () => {
|
|
66
|
+
// @ts-expect-error: Reset private property
|
|
67
|
+
logo_util_1.LogoUtil._content = undefined;
|
|
68
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockReturnValue('');
|
|
69
|
+
expect(logo_util_1.LogoUtil.content).toBe('');
|
|
70
|
+
fsSpy.mockRestore();
|
|
71
|
+
});
|
|
72
|
+
it('should handle logo file with special characters', () => {
|
|
73
|
+
// @ts-expect-error: Reset private property
|
|
74
|
+
logo_util_1.LogoUtil._content = undefined;
|
|
75
|
+
const specialContent = 'Logo with 特殊字符 and émojis 🚀';
|
|
76
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockReturnValue(specialContent);
|
|
77
|
+
expect(logo_util_1.LogoUtil.content).toBe(specialContent);
|
|
78
|
+
fsSpy.mockRestore();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('[[Public Static Methods]]', () => {
|
|
83
|
+
describe('print', () => {
|
|
84
|
+
describe('onlyLogo', () => {
|
|
85
|
+
it('should print only logo when onlyLogo is true', () => {
|
|
86
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
87
|
+
logo_util_1.LogoUtil.print(true);
|
|
88
|
+
const logoLines = toClearLines(logSpy.mock.calls);
|
|
89
|
+
const packageJsonContent = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../../../package.json'), { encoding: 'utf8' }));
|
|
90
|
+
expect(logoLines.join('')).not.toContain(packageJsonContent.version);
|
|
91
|
+
logSpy.mockRestore();
|
|
92
|
+
});
|
|
93
|
+
it('should print logo with version when onlyLogo is false', () => {
|
|
94
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
95
|
+
logo_util_1.LogoUtil.print(false);
|
|
96
|
+
const logoLines = toClearLines(logSpy.mock.calls);
|
|
97
|
+
const packageJsonContent = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../../../package.json'), { encoding: 'utf8' }));
|
|
98
|
+
expect(logoLines.join('')).toContain(packageJsonContent.version);
|
|
99
|
+
logSpy.mockRestore();
|
|
100
|
+
});
|
|
101
|
+
it('should print logo with version when onlyLogo is undefined', () => {
|
|
102
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
103
|
+
logo_util_1.LogoUtil.print();
|
|
104
|
+
const logoLines = toClearLines(logSpy.mock.calls);
|
|
105
|
+
const packageJsonContent = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../../../package.json'), { encoding: 'utf8' }));
|
|
106
|
+
expect(logoLines.join('')).toContain(packageJsonContent.version);
|
|
107
|
+
logSpy.mockRestore();
|
|
108
|
+
});
|
|
109
|
+
it('should handle onlyLogo as other truthy values', () => {
|
|
110
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
111
|
+
logo_util_1.LogoUtil.print('truthy string');
|
|
112
|
+
const logoLines = toClearLines(logSpy.mock.calls);
|
|
113
|
+
const packageJsonContent = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../../../package.json'), { encoding: 'utf8' }));
|
|
114
|
+
expect(logoLines.join('')).not.toContain(packageJsonContent.version);
|
|
115
|
+
logSpy.mockRestore();
|
|
116
|
+
});
|
|
117
|
+
it('should handle onlyLogo as other falsy values', () => {
|
|
118
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
119
|
+
logo_util_1.LogoUtil.print(0);
|
|
120
|
+
const logoLines = toClearLines(logSpy.mock.calls);
|
|
121
|
+
const packageJsonContent = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.resolve(__dirname, '../../../../package.json'), { encoding: 'utf8' }));
|
|
122
|
+
expect(logoLines.join('')).toContain(packageJsonContent.version);
|
|
123
|
+
logSpy.mockRestore();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('[[No Properties]]', () => {
|
|
127
|
+
it('should use console.log for output', () => {
|
|
128
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
129
|
+
logo_util_1.LogoUtil.print();
|
|
130
|
+
expect(logSpy).toHaveBeenCalled();
|
|
131
|
+
logSpy.mockRestore();
|
|
132
|
+
});
|
|
133
|
+
it('should apply magenta color to logo', () => {
|
|
134
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
135
|
+
const magentaSpy = jest.spyOn(color_util_1.ColorUtil, 'magenta');
|
|
136
|
+
logo_util_1.LogoUtil.print();
|
|
137
|
+
expect(magentaSpy).toHaveBeenCalled();
|
|
138
|
+
logSpy.mockRestore();
|
|
139
|
+
magentaSpy.mockRestore();
|
|
140
|
+
});
|
|
141
|
+
it('should add empty lines before and after logo', () => {
|
|
142
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
143
|
+
logo_util_1.LogoUtil.print();
|
|
144
|
+
const { calls } = logSpy.mock;
|
|
145
|
+
expect(calls[0][0]).toBe('');
|
|
146
|
+
expect(calls[calls.length - 1][0]).toBe('');
|
|
147
|
+
logSpy.mockRestore();
|
|
148
|
+
});
|
|
149
|
+
it('should read package.json for version information', () => {
|
|
150
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync');
|
|
151
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
152
|
+
logo_util_1.LogoUtil.print();
|
|
153
|
+
expect(fsSpy).toHaveBeenCalledWith(expect.stringContaining('package.json'), { encoding: 'utf8' });
|
|
154
|
+
logSpy.mockRestore();
|
|
155
|
+
fsSpy.mockRestore();
|
|
156
|
+
});
|
|
157
|
+
it('should handle missing package.json gracefully', () => {
|
|
158
|
+
const originalReadFileSync = node_fs_1.default.readFileSync;
|
|
159
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockImplementation((filePath, options) => {
|
|
160
|
+
if (typeof filePath === 'string' && filePath.includes('package.json')) {
|
|
161
|
+
throw new Error('File not found');
|
|
162
|
+
}
|
|
163
|
+
return originalReadFileSync(filePath, options);
|
|
164
|
+
});
|
|
165
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
166
|
+
expect(() => logo_util_1.LogoUtil.print()).toThrow();
|
|
167
|
+
logSpy.mockRestore();
|
|
168
|
+
fsSpy.mockRestore();
|
|
169
|
+
});
|
|
170
|
+
it('should handle invalid package.json format', () => {
|
|
171
|
+
const originalReadFileSync = node_fs_1.default.readFileSync;
|
|
172
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockImplementation((filePath, options) => {
|
|
173
|
+
if (typeof filePath === 'string' && filePath.includes('package.json')) {
|
|
174
|
+
return 'invalid json content';
|
|
175
|
+
}
|
|
176
|
+
return originalReadFileSync(filePath, options);
|
|
177
|
+
});
|
|
178
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
179
|
+
expect(() => logo_util_1.LogoUtil.print()).toThrow();
|
|
180
|
+
logSpy.mockRestore();
|
|
181
|
+
fsSpy.mockRestore();
|
|
182
|
+
});
|
|
183
|
+
it('should handle package.json without version field', () => {
|
|
184
|
+
const originalReadFileSync = node_fs_1.default.readFileSync;
|
|
185
|
+
const fsSpy = jest.spyOn(node_fs_1.default, 'readFileSync').mockImplementation((filePath, options) => {
|
|
186
|
+
if (typeof filePath === 'string' && filePath.includes('package.json')) {
|
|
187
|
+
return JSON.stringify({ name: 'test-package' });
|
|
188
|
+
}
|
|
189
|
+
return originalReadFileSync(filePath, options);
|
|
190
|
+
});
|
|
191
|
+
const logSpy = jest.spyOn(node_console_1.default, 'log').mockImplementation();
|
|
192
|
+
logo_util_1.LogoUtil.print();
|
|
193
|
+
const logoLines = toClearLines(logSpy.mock.calls);
|
|
194
|
+
expect(logoLines.join('')).toContain('undefined');
|
|
195
|
+
logSpy.mockRestore();
|
|
196
|
+
fsSpy.mockRestore();
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
//# sourceMappingURL=logo.util.unit.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const run_env_util_1 = require("../../../util/run-env.util");
|
|
4
|
+
describe('RunEnvUtil Unit Test', () => {
|
|
5
|
+
const originalEnv = process.env;
|
|
6
|
+
const originalPkg = process.pkg;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
jest.resetModules();
|
|
9
|
+
process.env = { ...originalEnv };
|
|
10
|
+
delete process.pkg;
|
|
11
|
+
});
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
process.env = originalEnv;
|
|
14
|
+
if (originalPkg) {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
16
|
+
;
|
|
17
|
+
process.pkg = originalPkg;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
delete process.pkg;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
describe('[[Static Public Properties]]', () => {
|
|
24
|
+
describe('[[Properties]]', () => {
|
|
25
|
+
describe('isDev', () => {
|
|
26
|
+
it('should return true when NODE_ENV is development', () => {
|
|
27
|
+
process.env.NODE_ENV = 'development';
|
|
28
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
it('should return true when NODE_ENV is dev', () => {
|
|
31
|
+
process.env.NODE_ENV = 'dev';
|
|
32
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
it('should return false when NODE_ENV is production', () => {
|
|
35
|
+
process.env.NODE_ENV = 'production';
|
|
36
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
it('should return false when NODE_ENV is prod', () => {
|
|
39
|
+
process.env.NODE_ENV = 'prod';
|
|
40
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
it('should return true and set NODE_ENV to development when NODE_ENV is not set', () => {
|
|
43
|
+
delete process.env.NODE_ENV;
|
|
44
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(true);
|
|
45
|
+
expect(process.env.NODE_ENV).toBe('development');
|
|
46
|
+
});
|
|
47
|
+
it('should return false when NODE_ENV is test', () => {
|
|
48
|
+
process.env.NODE_ENV = 'test';
|
|
49
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
it('should return false when NODE_ENV is staging', () => {
|
|
52
|
+
process.env.NODE_ENV = 'staging';
|
|
53
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
it('should return false when NODE_ENV is empty string', () => {
|
|
56
|
+
process.env.NODE_ENV = '';
|
|
57
|
+
expect(run_env_util_1.RunEnvUtil.isDev).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
describe('isProd', () => {
|
|
61
|
+
it('should return true when NODE_ENV is production', () => {
|
|
62
|
+
process.env.NODE_ENV = 'production';
|
|
63
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
it('should return true when NODE_ENV is prod', () => {
|
|
66
|
+
process.env.NODE_ENV = 'prod';
|
|
67
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('should return false when NODE_ENV is development', () => {
|
|
70
|
+
process.env.NODE_ENV = 'development';
|
|
71
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
it('should return false when NODE_ENV is dev', () => {
|
|
74
|
+
process.env.NODE_ENV = 'dev';
|
|
75
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
it('should return false when NODE_ENV is test', () => {
|
|
78
|
+
process.env.NODE_ENV = 'test';
|
|
79
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
it('should return false when NODE_ENV is not set', () => {
|
|
82
|
+
delete process.env.NODE_ENV;
|
|
83
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
it('should return false when NODE_ENV is empty string', () => {
|
|
86
|
+
process.env.NODE_ENV = '';
|
|
87
|
+
expect(run_env_util_1.RunEnvUtil.isProd).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
describe('inPKG', () => {
|
|
91
|
+
it('should return true when process.pkg is a non-null object', () => {
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
93
|
+
;
|
|
94
|
+
process.pkg = { snapshot: true };
|
|
95
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
it('should return false when process.pkg does not exist', () => {
|
|
98
|
+
delete process.pkg;
|
|
99
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
it('should return false when process.pkg is null', () => {
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
103
|
+
;
|
|
104
|
+
process.pkg = null;
|
|
105
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
it('should return false when process.pkg is undefined', () => {
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
109
|
+
;
|
|
110
|
+
process.pkg = undefined;
|
|
111
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
it('should return false when process.pkg is not an object', () => {
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
115
|
+
;
|
|
116
|
+
process.pkg = 'string';
|
|
117
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
it('should return false when process.pkg is a number', () => {
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
121
|
+
;
|
|
122
|
+
process.pkg = 123;
|
|
123
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
it('should return true when process.pkg is an empty object', () => {
|
|
126
|
+
// eslint-disable-next-line @typescript-eslint/no-extra-semi
|
|
127
|
+
;
|
|
128
|
+
process.pkg = {};
|
|
129
|
+
expect(run_env_util_1.RunEnvUtil.inPKG).toBe(true);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
describe('inVSCodeDebugger', () => {
|
|
133
|
+
it('should return true when VSCODE_INSPECTOR_OPTIONS is set', () => {
|
|
134
|
+
process.env.VSCODE_INSPECTOR_OPTIONS = 'some-value';
|
|
135
|
+
expect(run_env_util_1.RunEnvUtil.inVSCodeDebugger).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
it('should return false when VSCODE_INSPECTOR_OPTIONS is not set', () => {
|
|
138
|
+
delete process.env.VSCODE_INSPECTOR_OPTIONS;
|
|
139
|
+
expect(run_env_util_1.RunEnvUtil.inVSCodeDebugger).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
it('should return false when VSCODE_INSPECTOR_OPTIONS is undefined', () => {
|
|
142
|
+
process.env.VSCODE_INSPECTOR_OPTIONS = undefined;
|
|
143
|
+
expect(run_env_util_1.RunEnvUtil.inVSCodeDebugger).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
it('should return true when VSCODE_INSPECTOR_OPTIONS is empty string', () => {
|
|
146
|
+
process.env.VSCODE_INSPECTOR_OPTIONS = '';
|
|
147
|
+
expect(run_env_util_1.RunEnvUtil.inVSCodeDebugger).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
it('should return true when VSCODE_INSPECTOR_OPTIONS is set to any string', () => {
|
|
150
|
+
process.env.VSCODE_INSPECTOR_OPTIONS = 'debug-port=9229';
|
|
151
|
+
expect(run_env_util_1.RunEnvUtil.inVSCodeDebugger).toBe(true);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('inJest', () => {
|
|
155
|
+
it('should return true when JEST_WORKER_ID is set', () => {
|
|
156
|
+
process.env.JEST_WORKER_ID = '1';
|
|
157
|
+
expect(run_env_util_1.RunEnvUtil.inJest).toBe(true);
|
|
158
|
+
});
|
|
159
|
+
it('should return false when JEST_WORKER_ID is not set', () => {
|
|
160
|
+
delete process.env.JEST_WORKER_ID;
|
|
161
|
+
expect(run_env_util_1.RunEnvUtil.inJest).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
it('should return false when JEST_WORKER_ID is undefined', () => {
|
|
164
|
+
process.env.JEST_WORKER_ID = undefined;
|
|
165
|
+
expect(run_env_util_1.RunEnvUtil.inJest).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
it('should return true when JEST_WORKER_ID is empty string', () => {
|
|
168
|
+
process.env.JEST_WORKER_ID = '';
|
|
169
|
+
expect(run_env_util_1.RunEnvUtil.inJest).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
it('should return true when JEST_WORKER_ID is set to any string', () => {
|
|
172
|
+
process.env.JEST_WORKER_ID = 'worker-1';
|
|
173
|
+
expect(run_env_util_1.RunEnvUtil.inJest).toBe(true);
|
|
174
|
+
});
|
|
175
|
+
it('should return true when JEST_WORKER_ID is set to zero', () => {
|
|
176
|
+
process.env.JEST_WORKER_ID = '0';
|
|
177
|
+
expect(run_env_util_1.RunEnvUtil.inJest).toBe(true);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=run-env.util.unit.spec.js.map
|