@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,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
var TestService_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const supertest_1 = __importDefault(require("supertest"));
|
|
21
|
+
const a5_console_logger_1 = require("../../../core/a5-console-logger");
|
|
22
|
+
const a5_factory_1 = require("../../../core/a5-factory");
|
|
23
|
+
const a5_console_logger_middleware_1 = require("../../../middleware/a5-console-logger.middleware");
|
|
24
|
+
const index_1 = require("../../../module/log/index");
|
|
25
|
+
const color_util_1 = require("../../../util/color.util");
|
|
26
|
+
let TestController = class TestController {
|
|
27
|
+
get() {
|
|
28
|
+
return 'this is a get request';
|
|
29
|
+
}
|
|
30
|
+
post() {
|
|
31
|
+
return 'this is a post request';
|
|
32
|
+
}
|
|
33
|
+
put() {
|
|
34
|
+
return 'this is a put request';
|
|
35
|
+
}
|
|
36
|
+
patch() {
|
|
37
|
+
return 'this is a patch request';
|
|
38
|
+
}
|
|
39
|
+
delete() {
|
|
40
|
+
return 'this is a delete request';
|
|
41
|
+
}
|
|
42
|
+
all(req) {
|
|
43
|
+
return `this is a ${req.method.toLowerCase()} request to all route`;
|
|
44
|
+
}
|
|
45
|
+
uploadFile(body) {
|
|
46
|
+
return 'file uploaded successfully';
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, common_1.Get)(),
|
|
51
|
+
__metadata("design:type", Function),
|
|
52
|
+
__metadata("design:paramtypes", []),
|
|
53
|
+
__metadata("design:returntype", String)
|
|
54
|
+
], TestController.prototype, "get", null);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, common_1.Post)(),
|
|
57
|
+
__metadata("design:type", Function),
|
|
58
|
+
__metadata("design:paramtypes", []),
|
|
59
|
+
__metadata("design:returntype", String)
|
|
60
|
+
], TestController.prototype, "post", null);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, common_1.Put)(),
|
|
63
|
+
__metadata("design:type", Function),
|
|
64
|
+
__metadata("design:paramtypes", []),
|
|
65
|
+
__metadata("design:returntype", String)
|
|
66
|
+
], TestController.prototype, "put", null);
|
|
67
|
+
__decorate([
|
|
68
|
+
(0, common_1.Patch)(),
|
|
69
|
+
__metadata("design:type", Function),
|
|
70
|
+
__metadata("design:paramtypes", []),
|
|
71
|
+
__metadata("design:returntype", String)
|
|
72
|
+
], TestController.prototype, "patch", null);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, common_1.Delete)(),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", []),
|
|
77
|
+
__metadata("design:returntype", String)
|
|
78
|
+
], TestController.prototype, "delete", null);
|
|
79
|
+
__decorate([
|
|
80
|
+
(0, common_1.All)('all'),
|
|
81
|
+
__param(0, (0, common_1.Req)()),
|
|
82
|
+
__metadata("design:type", Function),
|
|
83
|
+
__metadata("design:paramtypes", [Object]),
|
|
84
|
+
__metadata("design:returntype", String)
|
|
85
|
+
], TestController.prototype, "all", null);
|
|
86
|
+
__decorate([
|
|
87
|
+
(0, common_1.Put)('upload'),
|
|
88
|
+
__param(0, (0, common_1.Body)()),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", [Object]),
|
|
91
|
+
__metadata("design:returntype", String)
|
|
92
|
+
], TestController.prototype, "uploadFile", null);
|
|
93
|
+
TestController = __decorate([
|
|
94
|
+
(0, common_1.Controller)()
|
|
95
|
+
], TestController);
|
|
96
|
+
let TestService = TestService_1 = class TestService {
|
|
97
|
+
constructor() {
|
|
98
|
+
this.logger = new common_1.Logger(TestService_1.name);
|
|
99
|
+
}
|
|
100
|
+
testLog() {
|
|
101
|
+
this.logger.log('Test log message');
|
|
102
|
+
}
|
|
103
|
+
testError() {
|
|
104
|
+
this.logger.error('Test error message');
|
|
105
|
+
}
|
|
106
|
+
testErrorWithStack() {
|
|
107
|
+
const error = new Error();
|
|
108
|
+
this.logger.error('Test error message', error.stack);
|
|
109
|
+
}
|
|
110
|
+
testWarn() {
|
|
111
|
+
this.logger.warn('Test warn message');
|
|
112
|
+
}
|
|
113
|
+
testDebug() {
|
|
114
|
+
this.logger.debug('Test debug message');
|
|
115
|
+
}
|
|
116
|
+
testVerbose() {
|
|
117
|
+
this.logger.verbose('Test verbose message');
|
|
118
|
+
}
|
|
119
|
+
testFatal() {
|
|
120
|
+
this.logger.fatal('Test fatal message');
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
TestService = TestService_1 = __decorate([
|
|
124
|
+
(0, common_1.Injectable)()
|
|
125
|
+
], TestService);
|
|
126
|
+
describe('Default for A5ConsoleLogger', () => {
|
|
127
|
+
const toClearLines = (lines) => lines.map(([text]) => color_util_1.ColorUtil.clear(text.trim()));
|
|
128
|
+
const originalEnv = process.env;
|
|
129
|
+
// eslint-disable-next-line init-declarations
|
|
130
|
+
let processStdoutWriteSpy;
|
|
131
|
+
// eslint-disable-next-line init-declarations
|
|
132
|
+
let processStderrWriteSpy;
|
|
133
|
+
beforeEach(async () => {
|
|
134
|
+
jest.resetModules();
|
|
135
|
+
process.env = { ...originalEnv };
|
|
136
|
+
processStdoutWriteSpy = jest.spyOn(process.stdout, 'write').mockImplementation();
|
|
137
|
+
processStderrWriteSpy = jest.spyOn(process.stderr, 'write').mockImplementation();
|
|
138
|
+
jest.clearAllMocks();
|
|
139
|
+
});
|
|
140
|
+
afterEach(async () => {
|
|
141
|
+
process.env = originalEnv;
|
|
142
|
+
processStdoutWriteSpy.mockRestore();
|
|
143
|
+
processStderrWriteSpy.mockRestore();
|
|
144
|
+
jest.restoreAllMocks();
|
|
145
|
+
});
|
|
146
|
+
describe('[[Module]]', () => {
|
|
147
|
+
it('default', async () => {
|
|
148
|
+
let AppModule = class AppModule {
|
|
149
|
+
};
|
|
150
|
+
AppModule = __decorate([
|
|
151
|
+
(0, common_1.Module)({})
|
|
152
|
+
], AppModule);
|
|
153
|
+
// Create application using A5Factory
|
|
154
|
+
const app = await a5_factory_1.A5Factory.create(AppModule, { printLogo: false });
|
|
155
|
+
await app.close();
|
|
156
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
157
|
+
expect(lines.length).toBe(4);
|
|
158
|
+
const [line0, line1, line2, line3] = lines;
|
|
159
|
+
expect(line0.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} WARN \[A5Application \] Not loaded A5 Logger Provider, using 'A5ConsoleLogger'$/);
|
|
160
|
+
expect(line1.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Factory \] Starting A5 application...$/);
|
|
161
|
+
expect(line2.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[InstanceLoader\] AppModule dependencies initialized$/);
|
|
162
|
+
expect(line3.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Application \] A5 application successfully started$/);
|
|
163
|
+
});
|
|
164
|
+
it('no content', async () => {
|
|
165
|
+
let AppModule = class AppModule {
|
|
166
|
+
};
|
|
167
|
+
AppModule = __decorate([
|
|
168
|
+
(0, common_1.Module)({
|
|
169
|
+
providers: [
|
|
170
|
+
{
|
|
171
|
+
provide: index_1.GLOBAL_PROVIDE_TOKEN_A5_LOG_LOGGER,
|
|
172
|
+
useValue: new a5_console_logger_1.A5ConsoleLogger(),
|
|
173
|
+
},
|
|
174
|
+
],
|
|
175
|
+
})
|
|
176
|
+
], AppModule);
|
|
177
|
+
// Create application using A5Factory
|
|
178
|
+
const app = await a5_factory_1.A5Factory.create(AppModule, { printLogo: false });
|
|
179
|
+
await app.close();
|
|
180
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
181
|
+
expect(lines.length).toBe(5);
|
|
182
|
+
const [line0, line1, line2, line3, line4] = lines;
|
|
183
|
+
expect(line0.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Application \] Loaded A5 Logger Provider, using 'A5ConsoleLogger'$/);
|
|
184
|
+
expect(line1.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} DEBUG \[A5Application \] 'A5ConsoleLogger' context is empty, automatically filled with 'A5Application' as default context$/);
|
|
185
|
+
expect(line2.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Factory \] Starting A5 application...$/);
|
|
186
|
+
expect(line3.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[InstanceLoader\] AppModule dependencies initialized$/);
|
|
187
|
+
expect(line4.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Application \] A5 application successfully started$/);
|
|
188
|
+
});
|
|
189
|
+
it('has context', async () => {
|
|
190
|
+
let AppModule = class AppModule {
|
|
191
|
+
};
|
|
192
|
+
AppModule = __decorate([
|
|
193
|
+
(0, common_1.Module)({
|
|
194
|
+
providers: [
|
|
195
|
+
{
|
|
196
|
+
provide: index_1.GLOBAL_PROVIDE_TOKEN_A5_LOG_LOGGER,
|
|
197
|
+
useValue: new a5_console_logger_1.A5ConsoleLogger({
|
|
198
|
+
context: 'Custom',
|
|
199
|
+
}),
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
})
|
|
203
|
+
], AppModule);
|
|
204
|
+
const app = await a5_factory_1.A5Factory.create(AppModule, {
|
|
205
|
+
printLogo: false,
|
|
206
|
+
});
|
|
207
|
+
expect(app.options.logger).toBeInstanceOf(a5_console_logger_1.A5ConsoleLogger);
|
|
208
|
+
await app.close();
|
|
209
|
+
// 验证完整的日志输出格式(移除 ANSI 颜色代码后验证)
|
|
210
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
211
|
+
expect(lines.length).toBe(4);
|
|
212
|
+
const [line0, line1, line2, line3] = lines;
|
|
213
|
+
expect(line0.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[Custom \] Loaded A5 Logger Provider, using 'A5ConsoleLogger'$/);
|
|
214
|
+
expect(line1.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Factory \] Starting A5 application...$/);
|
|
215
|
+
expect(line2.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[InstanceLoader\] AppModule dependencies initialized$/);
|
|
216
|
+
expect(line3.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Application \] A5 application successfully started$/);
|
|
217
|
+
});
|
|
218
|
+
it('has context and timestamp', async () => {
|
|
219
|
+
let AppModule = class AppModule {
|
|
220
|
+
};
|
|
221
|
+
AppModule = __decorate([
|
|
222
|
+
(0, common_1.Module)({
|
|
223
|
+
providers: [
|
|
224
|
+
{
|
|
225
|
+
provide: index_1.GLOBAL_PROVIDE_TOKEN_A5_LOG_LOGGER,
|
|
226
|
+
useValue: new a5_console_logger_1.A5ConsoleLogger({
|
|
227
|
+
context: 'Custom',
|
|
228
|
+
timestamp: true,
|
|
229
|
+
}),
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
})
|
|
233
|
+
], AppModule);
|
|
234
|
+
const app = await a5_factory_1.A5Factory.create(AppModule, {
|
|
235
|
+
printLogo: false,
|
|
236
|
+
});
|
|
237
|
+
expect(app.options.logger).toBeInstanceOf(a5_console_logger_1.A5ConsoleLogger);
|
|
238
|
+
await app.close();
|
|
239
|
+
// 验证完整的日志输出格式(移除 ANSI 颜色代码后验证)
|
|
240
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
241
|
+
expect(lines.length).toBe(4);
|
|
242
|
+
const [line0, line1, line2, line3] = lines;
|
|
243
|
+
expect(line0.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[Custom \] Loaded A5 Logger Provider, using 'A5ConsoleLogger' \+\d+ms$/);
|
|
244
|
+
expect(line1.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Factory \] Starting A5 application... \+\d+ms$/);
|
|
245
|
+
expect(line2.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[InstanceLoader\] AppModule dependencies initialized \+\d+ms$/);
|
|
246
|
+
expect(line3.trim()).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[A5Application \] A5 application successfully started \+\d+ms$/);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
describe('[[Logger]]', () => {
|
|
250
|
+
// eslint-disable-next-line init-declarations
|
|
251
|
+
let app;
|
|
252
|
+
// eslint-disable-next-line init-declarations
|
|
253
|
+
let testService;
|
|
254
|
+
beforeEach(async () => {
|
|
255
|
+
let AppModule = class AppModule {
|
|
256
|
+
};
|
|
257
|
+
AppModule = __decorate([
|
|
258
|
+
(0, common_1.Module)({
|
|
259
|
+
providers: [TestService],
|
|
260
|
+
})
|
|
261
|
+
], AppModule);
|
|
262
|
+
app = await a5_factory_1.A5Factory.create(AppModule, {
|
|
263
|
+
printLogo: false,
|
|
264
|
+
});
|
|
265
|
+
testService = app.nestApp.get(TestService);
|
|
266
|
+
});
|
|
267
|
+
afterEach(async () => {
|
|
268
|
+
await app.close();
|
|
269
|
+
});
|
|
270
|
+
it('log message', async () => {
|
|
271
|
+
testService.testLog();
|
|
272
|
+
expect(processStdoutWriteSpy).toHaveBeenCalled();
|
|
273
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
274
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[TestService \] Test log message$/);
|
|
275
|
+
});
|
|
276
|
+
it('error message', async () => {
|
|
277
|
+
testService.testError();
|
|
278
|
+
expect(processStderrWriteSpy).toHaveBeenCalled();
|
|
279
|
+
const lines = toClearLines(processStderrWriteSpy.mock.calls);
|
|
280
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} ERROR \[TestService \] Test error message$/);
|
|
281
|
+
});
|
|
282
|
+
it('error message with stack', async () => {
|
|
283
|
+
testService.testErrorWithStack();
|
|
284
|
+
expect(processStderrWriteSpy).toHaveBeenCalled();
|
|
285
|
+
const lines = toClearLines(processStderrWriteSpy.mock.calls);
|
|
286
|
+
expect(lines[lines.length - 2]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} ERROR \[TestService \] Test error message$/);
|
|
287
|
+
expect(lines[lines.length - 1]).toMatch(/at TestService.testErrorWithStack \(/);
|
|
288
|
+
});
|
|
289
|
+
it('warn message', async () => {
|
|
290
|
+
testService.testWarn();
|
|
291
|
+
expect(processStdoutWriteSpy).toHaveBeenCalled();
|
|
292
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
293
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} WARN \[TestService \] Test warn message$/);
|
|
294
|
+
});
|
|
295
|
+
it('debug message', async () => {
|
|
296
|
+
testService.testDebug();
|
|
297
|
+
expect(processStdoutWriteSpy).toHaveBeenCalled();
|
|
298
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
299
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} DEBUG \[TestService \] Test debug message$/);
|
|
300
|
+
});
|
|
301
|
+
it('verbose message', async () => {
|
|
302
|
+
testService.testVerbose();
|
|
303
|
+
expect(processStdoutWriteSpy).toHaveBeenCalled();
|
|
304
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
305
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} VERBOSE \[TestService \] Test verbose message$/);
|
|
306
|
+
});
|
|
307
|
+
it('fatal message', async () => {
|
|
308
|
+
testService.testFatal();
|
|
309
|
+
expect(processStdoutWriteSpy).toHaveBeenCalled();
|
|
310
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
311
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} FATAL \[TestService \] Test fatal message$/);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
describe('[[LoggerMiddleware]]', () => {
|
|
315
|
+
// eslint-disable-next-line init-declarations
|
|
316
|
+
let app;
|
|
317
|
+
beforeEach(async () => {
|
|
318
|
+
let AppModule = class AppModule {
|
|
319
|
+
configure(consumer) {
|
|
320
|
+
consumer.apply(a5_console_logger_middleware_1.A5ConsoleLoggerMiddleware).forRoutes('*');
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
AppModule = __decorate([
|
|
324
|
+
(0, common_1.Module)({
|
|
325
|
+
controllers: [TestController],
|
|
326
|
+
providers: [a5_console_logger_middleware_1.A5ConsoleLoggerMiddleware],
|
|
327
|
+
})
|
|
328
|
+
], AppModule);
|
|
329
|
+
app = await a5_factory_1.A5Factory.create(AppModule, {
|
|
330
|
+
printLogo: false,
|
|
331
|
+
});
|
|
332
|
+
await app.nestApp.getHttpAdapter().getInstance().ready();
|
|
333
|
+
});
|
|
334
|
+
afterEach(async () => {
|
|
335
|
+
await app.close();
|
|
336
|
+
});
|
|
337
|
+
it('Get request', async () => {
|
|
338
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).get('/').expect(200).expect('this is a get request');
|
|
339
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
340
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "GET \/ HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
341
|
+
});
|
|
342
|
+
it('Post request', async () => {
|
|
343
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).post('/').expect(201).expect('this is a post request');
|
|
344
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
345
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "POST \/ HTTP\/1.1" 201 \d+ \d+ms "-" "-"$/);
|
|
346
|
+
});
|
|
347
|
+
it('Put request', async () => {
|
|
348
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).put('/').expect(200).expect('this is a put request');
|
|
349
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
350
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "PUT \/ HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
351
|
+
});
|
|
352
|
+
it('Patch request', async () => {
|
|
353
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).patch('/').expect(200).expect('this is a patch request');
|
|
354
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
355
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "PATCH \/ HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
356
|
+
});
|
|
357
|
+
it('Delete request', async () => {
|
|
358
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).delete('/').expect(200).expect('this is a delete request');
|
|
359
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
360
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "DELETE \/ HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
361
|
+
});
|
|
362
|
+
it('All request with GET method', async () => {
|
|
363
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).get('/all').expect(200).expect('this is a get request to all route');
|
|
364
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
365
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "GET \/all HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
366
|
+
});
|
|
367
|
+
it('All request with POST method', async () => {
|
|
368
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).post('/all').expect(200).expect('this is a post request to all route');
|
|
369
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
370
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "POST \/all HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
371
|
+
});
|
|
372
|
+
it('All request with PUT method', async () => {
|
|
373
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer()).put('/all').expect(200).expect('this is a put request to all route');
|
|
374
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
375
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "PUT \/all HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
376
|
+
});
|
|
377
|
+
it('All request with DELETE method', async () => {
|
|
378
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer())
|
|
379
|
+
.delete('/all')
|
|
380
|
+
.expect(200)
|
|
381
|
+
.expect('this is a delete request to all route');
|
|
382
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
383
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "DELETE \/all HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
384
|
+
});
|
|
385
|
+
it('Put request for upload file', async () => {
|
|
386
|
+
const fileContent = {
|
|
387
|
+
name: 'test.txt',
|
|
388
|
+
size: 1024,
|
|
389
|
+
content: 'this is file content data for testing file upload functionality',
|
|
390
|
+
};
|
|
391
|
+
await (0, supertest_1.default)(app.nestApp.getHttpServer())
|
|
392
|
+
.put('/upload')
|
|
393
|
+
.send(fileContent)
|
|
394
|
+
.expect(200)
|
|
395
|
+
.expect('file uploaded successfully');
|
|
396
|
+
const lines = toClearLines(processStdoutWriteSpy.mock.calls);
|
|
397
|
+
expect(lines[lines.length - 1]).toMatch(/^\[A5\] \d+ +- \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3} LOG \[HttpRequest \] ::ffff:127.0.0.1 - "PUT \/upload HTTP\/1.1" 200 \d+ \d+ms "-" "-"$/);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
//# sourceMappingURL=with-logger-module.integration.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|