@nestia/e2e 0.3.7 → 0.4.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.
@@ -18,266 +18,255 @@ import { StopWatch } from "./StopWatch";
18
18
  * @author Jeongho Nam - https://github.com/samchon
19
19
  */
20
20
  export namespace DynamicExecutor {
21
+ /**
22
+ * Function type of a prefixed.
23
+ *
24
+ * @template Arguments Type of parameters
25
+ * @template Ret Type of return value
26
+ */
27
+ export interface Closure<Arguments extends any[], Ret = any> {
28
+ (...args: Arguments): Promise<Ret>;
29
+ }
30
+
31
+ /**
32
+ * Options for dynamic executor.
33
+ */
34
+ export interface IOptions<Parameters extends any[], Ret = any> {
21
35
  /**
22
- * Function type of a prefixed.
36
+ * Prefix of function name.
37
+ *
38
+ * Every prefixed function will be executed.
23
39
  *
24
- * @template Arguments Type of parameters
25
- * @template Ret Type of return value
40
+ * In other words, if a function name doesn't start with the prefix, then it would never be executed.
26
41
  */
27
- export interface Closure<Arguments extends any[], Ret = any> {
28
- (...args: Arguments): Promise<Ret>;
29
- }
42
+ prefix: string;
30
43
 
31
44
  /**
32
- * Options for dynamic executor.
45
+ * Get parameters of a function.
46
+ *
47
+ * @param name Function name
48
+ * @returns Parameters
33
49
  */
34
- export interface IOptions<Parameters extends any[], Ret = any> {
35
- /**
36
- * Prefix of function name.
37
- *
38
- * Every prefixed function will be executed.
39
- *
40
- * In other words, if a function name doesn't start with the prefix, then it would never be executed.
41
- */
42
- prefix: string;
43
-
44
- /**
45
- * Get parameters of a function.
46
- *
47
- * @param name Function name
48
- * @returns Parameters
49
- */
50
- parameters: (name: string) => Parameters;
50
+ parameters: (name: string) => Parameters;
51
51
 
52
- /**
53
- * Filter function whether to run or not.
54
- *
55
- * @param name Function name
56
- * @returns Whether to run or not
57
- */
58
- filter?: (name: string) => boolean;
52
+ /**
53
+ * Filter function whether to run or not.
54
+ *
55
+ * @param name Function name
56
+ * @returns Whether to run or not
57
+ */
58
+ filter?: (name: string) => boolean;
59
59
 
60
- /**
61
- * Wrapper of test function.
62
- *
63
- * If you specify this `wrapper` property, every dynamic functions
64
- * loaded and called by this `DynamicExecutor` would be wrapped by
65
- * the `wrapper` function.
66
- *
67
- * @param name Function name
68
- * @param closure Function to be executed
69
- * @returns Wrapper function
70
- */
71
- wrapper?: (
72
- name: string,
73
- closure: Closure<Parameters, Ret>,
74
- ) => Promise<any>;
60
+ /**
61
+ * Wrapper of test function.
62
+ *
63
+ * If you specify this `wrapper` property, every dynamic functions
64
+ * loaded and called by this `DynamicExecutor` would be wrapped by
65
+ * the `wrapper` function.
66
+ *
67
+ * @param name Function name
68
+ * @param closure Function to be executed
69
+ * @returns Wrapper function
70
+ */
71
+ wrapper?: (name: string, closure: Closure<Parameters, Ret>) => Promise<any>;
75
72
 
76
- /**
77
- * Whether to show elapsed time on `console` or not.
78
- *
79
- * @default true
80
- */
81
- showElapsedTime?: boolean;
73
+ /**
74
+ * Whether to show elapsed time on `console` or not.
75
+ *
76
+ * @default true
77
+ */
78
+ showElapsedTime?: boolean;
82
79
 
83
- /**
84
- * Extension of dynamic functions.
85
- *
86
- * @default js
87
- */
88
- extension?: string;
89
- }
80
+ /**
81
+ * Extension of dynamic functions.
82
+ *
83
+ * @default js
84
+ */
85
+ extension?: string;
86
+ }
90
87
 
88
+ /**
89
+ * Report, result of dynamic execution.
90
+ */
91
+ export interface IReport {
91
92
  /**
92
- * Report, result of dynamic execution.
93
+ * Location path of dynamic functions.
93
94
  */
94
- export interface IReport {
95
- /**
96
- * Location path of dynamic functions.
97
- */
98
- location: string;
95
+ location: string;
99
96
 
100
- /**
101
- * Execution results of dynamic functions.
102
- */
103
- executions: IReport.IExecution[];
97
+ /**
98
+ * Execution results of dynamic functions.
99
+ */
100
+ executions: IReport.IExecution[];
104
101
 
105
- /**
106
- * Total elapsed time.
107
- */
108
- time: number;
109
- }
110
- export namespace IReport {
111
- /**
112
- * Execution result of a dynamic function.
113
- */
114
- export interface IExecution {
115
- /**
116
- * Name of function.
117
- */
118
- name: string;
102
+ /**
103
+ * Total elapsed time.
104
+ */
105
+ time: number;
106
+ }
107
+ export namespace IReport {
108
+ /**
109
+ * Execution result of a dynamic function.
110
+ */
111
+ export interface IExecution {
112
+ /**
113
+ * Name of function.
114
+ */
115
+ name: string;
119
116
 
120
- /**
121
- * Location path of the function.
122
- */
123
- location: string;
117
+ /**
118
+ * Location path of the function.
119
+ */
120
+ location: string;
124
121
 
125
- /**
126
- * Error when occured.
127
- */
128
- error: Error | null;
122
+ /**
123
+ * Error when occured.
124
+ */
125
+ error: Error | null;
129
126
 
130
- /**
131
- * Elapsed time.
132
- */
133
- time: number;
134
- }
127
+ /**
128
+ * Elapsed time.
129
+ */
130
+ time: number;
135
131
  }
132
+ }
136
133
 
134
+ /**
135
+ * Prepare dynamic executor in strict mode.
136
+ *
137
+ * In strict mode, if any error occurs, the program will be terminated directly.
138
+ * Otherwise, {@link validate} mode does not terminate when error occurs, but
139
+ * just archive the error log.
140
+ *
141
+ * @param options Options of dynamic executor
142
+ * @returns Runner of dynamic functions with specific location
143
+ */
144
+ export const assert =
145
+ <Arguments extends any[]>(options: IOptions<Arguments>) =>
137
146
  /**
138
- * Prepare dynamic executor in strict mode.
139
- *
140
- * In strict mode, if any error occurs, the program will be terminated directly.
141
- * Otherwise, {@link validate} mode does not terminate when error occurs, but
142
- * just archive the error log.
147
+ * Run dynamic executor.
143
148
  *
144
- * @param options Options of dynamic executor
145
- * @returns Runner of dynamic functions with specific location
149
+ * @param path Location of prefixed functions
146
150
  */
147
- export const assert =
148
- <Arguments extends any[]>(options: IOptions<Arguments>) =>
149
- /**
150
- * Run dynamic executor.
151
- *
152
- * @param path Location of prefixed functions
153
- */
154
- (path: string): Promise<IReport> =>
155
- main(options)(true)(path);
151
+ (path: string): Promise<IReport> =>
152
+ main(options)(true)(path);
156
153
 
154
+ /**
155
+ * Prepare dynamic executor in loose mode.
156
+ *
157
+ * In loose mode, the program would not be terminated even when error occurs.
158
+ * Instead, the error would be archived and returns as a list. Otherwise,
159
+ * {@link assert} mode terminates the program directly when error occurs.
160
+ *
161
+ * @param options Options of dynamic executor
162
+ * @returns Runner of dynamic functions with specific location
163
+ */
164
+ export const validate =
165
+ <Arguments extends any[]>(options: IOptions<Arguments>) =>
157
166
  /**
158
- * Prepare dynamic executor in loose mode.
167
+ * Run dynamic executor.
159
168
  *
160
- * In loose mode, the program would not be terminated even when error occurs.
161
- * Instead, the error would be archived and returns as a list. Otherwise,
162
- * {@link assert} mode terminates the program directly when error occurs.
163
- *
164
- * @param options Options of dynamic executor
165
- * @returns Runner of dynamic functions with specific location
169
+ * @param path Location of prefix functions
170
+ * @returns List of errors
166
171
  */
167
- export const validate =
168
- <Arguments extends any[]>(options: IOptions<Arguments>) =>
169
- /**
170
- * Run dynamic executor.
171
- *
172
- * @param path Location of prefix functions
173
- * @returns List of errors
174
- */
175
- (path: string): Promise<IReport> =>
176
- main(options)(false)(path);
172
+ (path: string): Promise<IReport> =>
173
+ main(options)(false)(path);
177
174
 
178
- const main =
179
- <Arguments extends any[]>(options: IOptions<Arguments>) =>
180
- (assert: boolean) =>
181
- async (path: string) => {
182
- const report: IReport = {
183
- location: path,
184
- time: Date.now(),
185
- executions: [],
186
- };
175
+ const main =
176
+ <Arguments extends any[]>(options: IOptions<Arguments>) =>
177
+ (assert: boolean) =>
178
+ async (path: string) => {
179
+ const report: IReport = {
180
+ location: path,
181
+ time: Date.now(),
182
+ executions: [],
183
+ };
187
184
 
188
- const executor = execute(options)(report)(assert);
189
- const iterator = iterate(options.extension ?? "js")(executor);
190
- await iterator(path);
185
+ const executor = execute(options)(report)(assert);
186
+ const iterator = iterate(options.extension ?? "js")(executor);
187
+ await iterator(path);
191
188
 
192
- report.time = Date.now() - report.time;
193
- return report;
194
- };
189
+ report.time = Date.now() - report.time;
190
+ return report;
191
+ };
195
192
 
196
- const iterate =
197
- (extension: string) =>
198
- <Arguments extends any[]>(
199
- executor: (
200
- path: string,
201
- modulo: Module<Arguments>,
202
- ) => Promise<void>,
203
- ) => {
204
- const visitor = async (path: string): Promise<void> => {
205
- const directory: string[] = await fs.promises.readdir(path);
206
- for (const file of directory) {
207
- const location: string = NodePath.resolve(
208
- `${path}/${file}`,
209
- );
210
- const stats: fs.Stats = await fs.promises.lstat(location);
193
+ const iterate =
194
+ (extension: string) =>
195
+ <Arguments extends any[]>(
196
+ executor: (path: string, modulo: Module<Arguments>) => Promise<void>,
197
+ ) => {
198
+ const visitor = async (path: string): Promise<void> => {
199
+ const directory: string[] = await fs.promises.readdir(path);
200
+ for (const file of directory) {
201
+ const location: string = NodePath.resolve(`${path}/${file}`);
202
+ const stats: fs.Stats = await fs.promises.lstat(location);
211
203
 
212
- if (stats.isDirectory() === true) {
213
- await visitor(location);
214
- continue;
215
- } else if (file.substr(-3) !== `.${extension}`) continue;
204
+ if (stats.isDirectory() === true) {
205
+ await visitor(location);
206
+ continue;
207
+ } else if (file.substr(-3) !== `.${extension}`) continue;
216
208
 
217
- const modulo: Module<Arguments> = await import(location);
218
- await executor(location, modulo);
219
- }
220
- };
221
- return visitor;
222
- };
209
+ const modulo: Module<Arguments> = await import(location);
210
+ await executor(location, modulo);
211
+ }
212
+ };
213
+ return visitor;
214
+ };
223
215
 
224
- const execute =
225
- <Arguments extends any[]>(options: IOptions<Arguments>) =>
226
- (report: IReport) =>
227
- (assert: boolean) =>
228
- async (location: string, modulo: Module<Arguments>): Promise<void> => {
229
- for (const [key, closure] of Object.entries(modulo)) {
230
- if (
231
- key.substring(0, options.prefix.length) !==
232
- options.prefix ||
233
- typeof closure !== "function" ||
234
- (options.filter && options.filter(key) === false)
235
- )
236
- continue;
216
+ const execute =
217
+ <Arguments extends any[]>(options: IOptions<Arguments>) =>
218
+ (report: IReport) =>
219
+ (assert: boolean) =>
220
+ async (location: string, modulo: Module<Arguments>): Promise<void> => {
221
+ for (const [key, closure] of Object.entries(modulo)) {
222
+ if (
223
+ key.substring(0, options.prefix.length) !== options.prefix ||
224
+ typeof closure !== "function" ||
225
+ (options.filter && options.filter(key) === false)
226
+ )
227
+ continue;
237
228
 
238
- const func = async () => {
239
- if (options.wrapper !== undefined)
240
- await options.wrapper(key, closure);
241
- else await closure(...options.parameters(key));
242
- };
243
- const label: string = chalk.greenBright(key);
229
+ const func = async () => {
230
+ if (options.wrapper !== undefined)
231
+ await options.wrapper(key, closure);
232
+ else await closure(...options.parameters(key));
233
+ };
234
+ const label: string = chalk.greenBright(key);
244
235
 
245
- const result: IReport.IExecution = {
246
- name: key,
247
- location,
248
- error: null,
249
- time: Date.now(),
250
- };
251
- report.executions.push(result);
236
+ const result: IReport.IExecution = {
237
+ name: key,
238
+ location,
239
+ error: null,
240
+ time: Date.now(),
241
+ };
242
+ report.executions.push(result);
252
243
 
253
- try {
254
- if (options.showElapsedTime === false) {
255
- await func();
256
- result.time = Date.now() - result.time;
257
- console.log(` - ${label}`);
258
- } else {
259
- result.time = await StopWatch.measure(func);
260
- console.log(
261
- ` - ${label}: ${chalk.yellowBright(
262
- result.time.toLocaleString(),
263
- )} ms`,
264
- );
265
- }
266
- } catch (exp) {
267
- result.time = Date.now() - result.time;
268
- result.error = exp as Error;
244
+ try {
245
+ if (options.showElapsedTime === false) {
246
+ await func();
247
+ result.time = Date.now() - result.time;
248
+ console.log(` - ${label}`);
249
+ } else {
250
+ result.time = (await StopWatch.measure(func))[1];
251
+ console.log(
252
+ ` - ${label}: ${chalk.yellowBright(
253
+ result.time.toLocaleString(),
254
+ )} ms`,
255
+ );
256
+ }
257
+ } catch (exp) {
258
+ result.time = Date.now() - result.time;
259
+ result.error = exp as Error;
269
260
 
270
- console.log(
271
- ` - ${label} -> ${chalk.redBright(
272
- (exp as Error)?.name,
273
- )}`,
274
- );
275
- if (assert === true) throw exp;
276
- }
277
- }
278
- };
261
+ console.log(
262
+ ` - ${label} -> ${chalk.redBright((exp as Error)?.name)}`,
263
+ );
264
+ if (assert === true) throw exp;
265
+ }
266
+ }
267
+ };
279
268
 
280
- interface Module<Arguments extends any[]> {
281
- [key: string]: Closure<Arguments>;
282
- }
269
+ interface Module<Arguments extends any[]> {
270
+ [key: string]: Closure<Arguments>;
271
+ }
283
272
  }
@@ -9,61 +9,61 @@
9
9
  * @author Jeongho Nam - https://github.com/samchon
10
10
  */
11
11
  export namespace GaffComparator {
12
- /**
13
- * String(s) comparator.
14
- *
15
- * @param getter Getter of string(s) from input
16
- * @returns Comparator function
17
- */
18
- export const strings =
19
- <T>(getter: (input: T) => string | string[]) =>
20
- (x: T, y: T) => {
21
- const a: string[] = wrap(getter(x));
22
- const b: string[] = wrap(getter(y));
12
+ /**
13
+ * String(s) comparator.
14
+ *
15
+ * @param getter Getter of string(s) from input
16
+ * @returns Comparator function
17
+ */
18
+ export const strings =
19
+ <T>(getter: (input: T) => string | string[]) =>
20
+ (x: T, y: T) => {
21
+ const a: string[] = wrap(getter(x));
22
+ const b: string[] = wrap(getter(y));
23
23
 
24
- const idx: number = a.findIndex((v, i) => v !== b[i]);
25
- return idx !== -1 ? compare(a[idx], b[idx]) : 0;
26
- };
24
+ const idx: number = a.findIndex((v, i) => v !== b[i]);
25
+ return idx !== -1 ? compare(a[idx], b[idx]) : 0;
26
+ };
27
27
 
28
- /**
29
- * Date(s) comparator.
30
- *
31
- * @param getter Getter of date(s) from input
32
- * @returns Comparator function
33
- */
34
- export const dates =
35
- <T>(getter: (input: T) => string | string[]) =>
36
- (x: T, y: T) => {
37
- const take = (v: T) =>
38
- wrap(getter(v)).map((str) => new Date(str).getTime());
39
- const a: number[] = take(x);
40
- const b: number[] = take(y);
28
+ /**
29
+ * Date(s) comparator.
30
+ *
31
+ * @param getter Getter of date(s) from input
32
+ * @returns Comparator function
33
+ */
34
+ export const dates =
35
+ <T>(getter: (input: T) => string | string[]) =>
36
+ (x: T, y: T) => {
37
+ const take = (v: T) =>
38
+ wrap(getter(v)).map((str) => new Date(str).getTime());
39
+ const a: number[] = take(x);
40
+ const b: number[] = take(y);
41
41
 
42
- const idx: number = a.findIndex((v, i) => v !== b[i]);
43
- return idx !== -1 ? a[idx] - b[idx] : 0;
44
- };
42
+ const idx: number = a.findIndex((v, i) => v !== b[i]);
43
+ return idx !== -1 ? a[idx] - b[idx] : 0;
44
+ };
45
45
 
46
- /**
47
- * Number(s) comparator.
48
- *
49
- * @param closure Getter of number(s) from input
50
- * @returns Comparator function
51
- */
52
- export const numbers =
53
- <T>(closure: (input: T) => number | number[]) =>
54
- (x: T, y: T) => {
55
- const a: number[] = wrap(closure(x));
56
- const b: number[] = wrap(closure(y));
46
+ /**
47
+ * Number(s) comparator.
48
+ *
49
+ * @param closure Getter of number(s) from input
50
+ * @returns Comparator function
51
+ */
52
+ export const numbers =
53
+ <T>(closure: (input: T) => number | number[]) =>
54
+ (x: T, y: T) => {
55
+ const a: number[] = wrap(closure(x));
56
+ const b: number[] = wrap(closure(y));
57
57
 
58
- const idx: number = a.findIndex((v, i) => v !== b[i]);
59
- return idx !== -1 ? a[idx] - b[idx] : 0;
60
- };
58
+ const idx: number = a.findIndex((v, i) => v !== b[i]);
59
+ return idx !== -1 ? a[idx] - b[idx] : 0;
60
+ };
61
61
 
62
- function compare(x: string, y: string) {
63
- return x.localeCompare(y);
64
- }
62
+ function compare(x: string, y: string) {
63
+ return x.localeCompare(y);
64
+ }
65
65
 
66
- function wrap<T>(elem: T | T[]): T[] {
67
- return Array.isArray(elem) ? elem : [elem];
68
- }
66
+ function wrap<T>(elem: T | T[]): T[] {
67
+ return Array.isArray(elem) ? elem : [elem];
68
+ }
69
69
  }