@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.
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/DynamicExecutor.js +2 -3
- package/lib/DynamicExecutor.js.map +1 -1
- package/lib/GaffComparator.js.map +1 -1
- package/lib/RandomGenerator.js +3 -5
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/StopWatch.d.ts +3 -3
- package/lib/StopWatch.js +7 -7
- package/lib/StopWatch.js.map +1 -1
- package/lib/TestValidator.d.ts +1 -1
- package/lib/TestValidator.js +2 -5
- package/lib/TestValidator.js.map +1 -1
- package/lib/internal/json_equal_to.js +2 -6
- package/lib/internal/json_equal_to.js.map +1 -1
- package/package.json +5 -7
- package/src/ArrayUtil.ts +79 -80
- package/src/DynamicExecutor.ts +212 -223
- package/src/GaffComparator.ts +50 -50
- package/src/RandomGenerator.ts +132 -136
- package/src/StopWatch.ts +28 -28
- package/src/TestValidator.ts +294 -296
- package/src/internal/json_equal_to.ts +32 -36
package/src/DynamicExecutor.ts
CHANGED
|
@@ -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
|
-
*
|
|
36
|
+
* Prefix of function name.
|
|
37
|
+
*
|
|
38
|
+
* Every prefixed function will be executed.
|
|
23
39
|
*
|
|
24
|
-
*
|
|
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
|
-
|
|
28
|
-
(...args: Arguments): Promise<Ret>;
|
|
29
|
-
}
|
|
42
|
+
prefix: string;
|
|
30
43
|
|
|
31
44
|
/**
|
|
32
|
-
*
|
|
45
|
+
* Get parameters of a function.
|
|
46
|
+
*
|
|
47
|
+
* @param name Function name
|
|
48
|
+
* @returns Parameters
|
|
33
49
|
*/
|
|
34
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Whether to show elapsed time on `console` or not.
|
|
75
|
+
*
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
showElapsedTime?: boolean;
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
*
|
|
93
|
+
* Location path of dynamic functions.
|
|
93
94
|
*/
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Location path of dynamic functions.
|
|
97
|
-
*/
|
|
98
|
-
location: string;
|
|
95
|
+
location: string;
|
|
99
96
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Execution results of dynamic functions.
|
|
99
|
+
*/
|
|
100
|
+
executions: IReport.IExecution[];
|
|
104
101
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Location path of the function.
|
|
119
|
+
*/
|
|
120
|
+
location: string;
|
|
124
121
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Error when occured.
|
|
124
|
+
*/
|
|
125
|
+
error: Error | null;
|
|
129
126
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
*
|
|
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
|
|
145
|
-
* @returns Runner of dynamic functions with specific location
|
|
149
|
+
* @param path Location of prefixed functions
|
|
146
150
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
*
|
|
167
|
+
* Run dynamic executor.
|
|
159
168
|
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
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
|
-
|
|
168
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
185
|
+
const executor = execute(options)(report)(assert);
|
|
186
|
+
const iterator = iterate(options.extension ?? "js")(executor);
|
|
187
|
+
await iterator(path);
|
|
191
188
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
report.time = Date.now() - report.time;
|
|
190
|
+
return report;
|
|
191
|
+
};
|
|
195
192
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
)
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
204
|
+
if (stats.isDirectory() === true) {
|
|
205
|
+
await visitor(location);
|
|
206
|
+
continue;
|
|
207
|
+
} else if (file.substr(-3) !== `.${extension}`) continue;
|
|
216
208
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
209
|
+
const modulo: Module<Arguments> = await import(location);
|
|
210
|
+
await executor(location, modulo);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return visitor;
|
|
214
|
+
};
|
|
223
215
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
269
|
+
interface Module<Arguments extends any[]> {
|
|
270
|
+
[key: string]: Closure<Arguments>;
|
|
271
|
+
}
|
|
283
272
|
}
|
package/src/GaffComparator.ts
CHANGED
|
@@ -9,61 +9,61 @@
|
|
|
9
9
|
* @author Jeongho Nam - https://github.com/samchon
|
|
10
10
|
*/
|
|
11
11
|
export namespace GaffComparator {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
function compare(x: string, y: string) {
|
|
63
|
+
return x.localeCompare(y);
|
|
64
|
+
}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
function wrap<T>(elem: T | T[]): T[] {
|
|
67
|
+
return Array.isArray(elem) ? elem : [elem];
|
|
68
|
+
}
|
|
69
69
|
}
|