@nest-yalc-2/app 2.2.2 → 2.2.5
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/package.json +5 -3
- package/src/__tests__/app-bootstrap-base.helper.spec.ts +86 -38
- package/src/__tests__/app-bootstrap-standalone.helper.spec.ts +35 -35
- package/src/__tests__/app-bootstrap.helper.spec.ts +162 -98
- package/src/__tests__/app-config.service.spec.ts +55 -55
- package/src/__tests__/app-context.service.spec.ts +28 -28
- package/src/__tests__/app.events.spec.ts +12 -12
- package/src/__tests__/app.helper.spec.ts +71 -204
- package/src/__tests__/base-app-module.helper.spec.ts +295 -231
- package/src/__tests__/base-app.controller.spec.ts +90 -90
- package/src/__tests__/base-app.service.spec.ts +39 -39
- package/src/__tests__/cls.module.spec.ts +33 -33
- package/src/__tests__/life-cycle-handler.service.spec.ts +57 -48
- package/src/__tests__/unwrap-result.interceptor.spec.ts +52 -52
- package/src/app-bootstrap-base.helper.ts +206 -206
- package/src/app-bootstrap-standalone.helper.ts +67 -67
- package/src/app-bootstrap.helper.js +9 -9
- package/src/app-bootstrap.helper.ts +279 -279
- package/src/app-config.service.ts +61 -61
- package/src/app-context.module.ts +6 -6
- package/src/app-context.service.ts +16 -16
- package/src/app-imports.factory.js +2 -2
- package/src/app-imports.factory.js.map +1 -1
- package/src/app-imports.factory.ts +321 -321
- package/src/app.events.ts +8 -8
- package/src/app.helper.ts +73 -73
- package/src/base-app-module.helper.d.ts +2 -2
- package/src/base-app-module.helper.js +8 -5
- package/src/base-app-module.helper.js.map +1 -1
- package/src/base-app-module.helper.ts +457 -453
- package/src/base-app.controller.ts +51 -51
- package/src/base-app.interface.ts +55 -55
- package/src/base-app.service.ts +33 -33
- package/src/cls.module.d.ts +2 -1
- package/src/cls.module.js.map +1 -1
- package/src/cls.module.ts +76 -75
- package/src/conf.type.ts +22 -22
- package/src/def.const.ts +33 -33
- package/src/global.enum.ts +6 -6
- package/src/life-cycle-handler.service.ts +66 -66
- package/src/unwrap-result.interceptor.ts +32 -32
- package/src/yalc-controller.interface.ts +6 -6
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { describe, expect, it } from '@jest/globals';
|
|
2
|
-
import { AppEvents } from '../app.events.js';
|
|
3
|
-
|
|
4
|
-
describe('AppEvents enum', () => {
|
|
5
|
-
it('should expose the expected event names', () => {
|
|
6
|
-
expect(AppEvents.BEFORE_ALL_ROUTES).toBe('app.before_all_routes');
|
|
7
|
-
expect(AppEvents.AFTER_ALL_ROUTES).toBe('app.after_all_routes');
|
|
8
|
-
expect(AppEvents.BEFORE_GQL_CONTEXT_MIDDLEWARE).toBe(
|
|
9
|
-
'app.before_gql_context_middleware',
|
|
10
|
-
);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { AppEvents } from '../app.events.js';
|
|
3
|
+
|
|
4
|
+
describe('AppEvents enum', () => {
|
|
5
|
+
it('should expose the expected event names', () => {
|
|
6
|
+
expect(AppEvents.BEFORE_ALL_ROUTES).toBe('app.before_all_routes');
|
|
7
|
+
expect(AppEvents.AFTER_ALL_ROUTES).toBe('app.after_all_routes');
|
|
8
|
+
expect(AppEvents.BEFORE_GQL_CONTEXT_MIDDLEWARE).toBe(
|
|
9
|
+
'app.before_gql_context_middleware',
|
|
10
|
+
);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
@@ -1,204 +1,71 @@
|
|
|
1
|
-
import { jest } from '@jest/globals';
|
|
2
|
-
import '
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
getBootstrappedApps().forEach((app) => app.closeApp());
|
|
74
|
-
getBootstrappedApps().clear();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('should run executeStandaloneFunction', async () => {
|
|
78
|
-
const mockedFunction = jest.fn(async (service: any) => {
|
|
79
|
-
return service;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
await executeStandaloneFunction(
|
|
83
|
-
mockedModule,
|
|
84
|
-
mockedServiceFunction,
|
|
85
|
-
mockedFunction,
|
|
86
|
-
{},
|
|
87
|
-
{ closeApp: true },
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
expect(mockedFunction).toHaveBeenCalledTimes(1);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('should run executeStandaloneFunction without close app', async () => {
|
|
94
|
-
const mockedFunction = jest.fn(async (service: any) => {
|
|
95
|
-
return service;
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
await executeStandaloneFunction(
|
|
99
|
-
mockedModule,
|
|
100
|
-
mockedServiceFunction,
|
|
101
|
-
mockedFunction,
|
|
102
|
-
{},
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
expect(mockedFunction).toHaveBeenCalledTimes(1);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should run executeStandaloneFunction with class module', async () => {
|
|
109
|
-
const mockedFunction = jest.fn(async (service: any) => {
|
|
110
|
-
return service;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
class TestModule {
|
|
114
|
-
constructor() {}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
await executeStandaloneFunction(
|
|
118
|
-
TestModule,
|
|
119
|
-
mockedServiceFunction,
|
|
120
|
-
mockedFunction,
|
|
121
|
-
{},
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
expect(mockedFunction).toHaveBeenCalledTimes(1);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should trigger an error if we bootstrap multiple servers', async () => {
|
|
128
|
-
await new AppBootstrap('test1', TestModule1).initApp();
|
|
129
|
-
|
|
130
|
-
let error: any = null;
|
|
131
|
-
try {
|
|
132
|
-
await new AppBootstrap('test2', TestModule2, {}).initApp();
|
|
133
|
-
} catch (e: any) {
|
|
134
|
-
// eslint-disable-next-line no-console
|
|
135
|
-
console.log(e);
|
|
136
|
-
error = e;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
await expect(error).not.toBe(null);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should not trigger an error when the first app cannot be initialized because of an error', async () => {
|
|
143
|
-
try {
|
|
144
|
-
await new AppBootstrap('brokenModule', BrokenModule).initApp();
|
|
145
|
-
} catch (e: any) {
|
|
146
|
-
// nothing
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
let error: any = null;
|
|
150
|
-
try {
|
|
151
|
-
await new AppBootstrap('test2', TestModule2, {}).initApp();
|
|
152
|
-
} catch (e: any) {
|
|
153
|
-
// eslint-disable-next-line no-console
|
|
154
|
-
console.log(e);
|
|
155
|
-
error = e;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
await expect(error).toBe(null);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should not trigger an error if we bootstrap multiple servers with the skip option', async () => {
|
|
162
|
-
await new AppBootstrap('test1', TestModule1, {
|
|
163
|
-
skipMultiServerCheck: true,
|
|
164
|
-
}).initApp();
|
|
165
|
-
|
|
166
|
-
let error: any = null;
|
|
167
|
-
try {
|
|
168
|
-
await new AppBootstrap('test2', TestModule2, {
|
|
169
|
-
skipMultiServerCheck: true,
|
|
170
|
-
}).initApp();
|
|
171
|
-
} catch (e: any) {
|
|
172
|
-
// eslint-disable-next-line no-console
|
|
173
|
-
console.log(e);
|
|
174
|
-
error = e;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
await expect(error).toBe(null);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('should not trigger an error if we bootstrap multiple servers with the env variable', async () => {
|
|
181
|
-
process.env.APP_SKIP_MULTISERVER_CHECK = 'true';
|
|
182
|
-
|
|
183
|
-
await new AppBootstrap('test1', TestModule1).initApp();
|
|
184
|
-
|
|
185
|
-
let error: any = null;
|
|
186
|
-
try {
|
|
187
|
-
await new AppBootstrap('test2', TestModule2).initApp();
|
|
188
|
-
} catch (e: any) {
|
|
189
|
-
// eslint-disable-next-line no-console
|
|
190
|
-
console.log(e);
|
|
191
|
-
error = e;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
await expect(error).toBe(null);
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('should get the main bootstrapped app', async () => {
|
|
198
|
-
const app = await new AppBootstrap('test1', TestModule1).initApp();
|
|
199
|
-
|
|
200
|
-
const mainApp = getMainBootstrappedApp();
|
|
201
|
-
|
|
202
|
-
expect(mainApp === app).toBe(true);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
1
|
+
import { describe, expect, it, jest, beforeEach } from '@jest/globals';
|
|
2
|
+
import { StandaloneAppBootstrap } from '../app-bootstrap-standalone.helper.js';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
executeFunctionForApp,
|
|
6
|
+
curriedExecuteStandaloneFunction,
|
|
7
|
+
executeStandaloneFunction,
|
|
8
|
+
isDynamicModule,
|
|
9
|
+
} from '../app.helper.js';
|
|
10
|
+
|
|
11
|
+
describe('app.helper', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
jest.restoreAllMocks();
|
|
14
|
+
jest.spyOn(StandaloneAppBootstrap.prototype, 'initApp').mockResolvedValue({
|
|
15
|
+
getApp: jest.fn().mockReturnValue({
|
|
16
|
+
init: jest.fn(),
|
|
17
|
+
resolve: jest.fn().mockResolvedValue({}),
|
|
18
|
+
}),
|
|
19
|
+
} as any);
|
|
20
|
+
jest.spyOn(StandaloneAppBootstrap.prototype, 'getApp').mockReturnValue({
|
|
21
|
+
init: jest.fn(),
|
|
22
|
+
resolve: jest.fn().mockResolvedValue({}),
|
|
23
|
+
} as any);
|
|
24
|
+
jest.spyOn(StandaloneAppBootstrap.prototype, 'closeApp').mockResolvedValue({} as any);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should evaluate isDynamicModule', () => {
|
|
28
|
+
expect(isDynamicModule({ module: {} })).toBe(true);
|
|
29
|
+
expect(isDynamicModule({})).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should execute function for app', async () => {
|
|
33
|
+
const mockApp = {
|
|
34
|
+
getApp: jest.fn().mockReturnValue({
|
|
35
|
+
init: jest.fn(),
|
|
36
|
+
resolve: jest.fn().mockResolvedValue({}),
|
|
37
|
+
} as any),
|
|
38
|
+
closeApp: jest.fn(),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const mockFn = jest.fn().mockResolvedValue({});
|
|
42
|
+
|
|
43
|
+
await executeFunctionForApp(mockApp as any, {}, mockFn as any, { closeApp: true });
|
|
44
|
+
|
|
45
|
+
expect(mockApp.getApp).toHaveBeenCalled();
|
|
46
|
+
expect(mockFn).toHaveBeenCalled();
|
|
47
|
+
expect(mockApp.closeApp).toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should create curried function', async () => {
|
|
51
|
+
class DummyModule {}
|
|
52
|
+
const curried = await curriedExecuteStandaloneFunction(DummyModule, { skipMultiServerCheck: true } as any);
|
|
53
|
+
expect(typeof curried).toBe('function');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should create curried function with dynamic module', async () => {
|
|
57
|
+
const dynamicModule = { module: { name: 'DynamicDummy' } };
|
|
58
|
+
const curried = await curriedExecuteStandaloneFunction(dynamicModule, { skipMultiServerCheck: true } as any);
|
|
59
|
+
expect(typeof curried).toBe('function');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should execute standalone function', async () => {
|
|
63
|
+
class DummyModule {}
|
|
64
|
+
class DummyService {}
|
|
65
|
+
const mockFn = jest.fn().mockResolvedValue({});
|
|
66
|
+
|
|
67
|
+
await executeStandaloneFunction(DummyModule, DummyService, mockFn, { skipMultiServerCheck: true } as any);
|
|
68
|
+
|
|
69
|
+
expect(mockFn).toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
});
|