@nestia/e2e 0.4.1 → 0.4.2
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/DynamicExecutor.d.ts +4 -3
- package/lib/DynamicExecutor.js +1 -1
- package/lib/DynamicExecutor.js.map +1 -1
- package/lib/TestValidator.d.ts +2 -2
- package/lib/TestValidator.js +32 -3
- package/lib/TestValidator.js.map +1 -1
- package/package.json +3 -3
- package/src/ArrayUtil.ts +98 -98
- package/src/DynamicExecutor.ts +7 -2
- package/src/GaffComparator.ts +69 -69
- package/src/RandomGenerator.ts +161 -161
- package/src/StopWatch.ts +38 -38
- package/src/TestValidator.ts +339 -339
- package/src/index.ts +4 -4
- package/src/internal/json_equal_to.ts +34 -34
- package/src/module.ts +6 -6
package/lib/DynamicExecutor.d.ts
CHANGED
|
@@ -56,9 +56,10 @@ export declare namespace DynamicExecutor {
|
|
|
56
56
|
*
|
|
57
57
|
* @param name Function name
|
|
58
58
|
* @param closure Function to be executed
|
|
59
|
+
* @param parameters Parameters, result of options.parameters function.
|
|
59
60
|
* @returns Wrapper function
|
|
60
61
|
*/
|
|
61
|
-
wrapper?: (name: string, closure: Closure<Parameters, Ret
|
|
62
|
+
wrapper?: (name: string, closure: Closure<Parameters, Ret>, paramters: Parameters) => Promise<any>;
|
|
62
63
|
/**
|
|
63
64
|
* Whether to show elapsed time on `console` or not.
|
|
64
65
|
*
|
|
@@ -122,7 +123,7 @@ export declare namespace DynamicExecutor {
|
|
|
122
123
|
* @param options Options of dynamic executor
|
|
123
124
|
* @returns Runner of dynamic functions with specific location
|
|
124
125
|
*/
|
|
125
|
-
const assert: <Arguments extends any[]>(options: IOptions<Arguments
|
|
126
|
+
const assert: <Arguments extends any[]>(options: IOptions<Arguments>) => (path: string) => Promise<IReport>;
|
|
126
127
|
/**
|
|
127
128
|
* Prepare dynamic executor in loose mode.
|
|
128
129
|
*
|
|
@@ -133,5 +134,5 @@ export declare namespace DynamicExecutor {
|
|
|
133
134
|
* @param options Options of dynamic executor
|
|
134
135
|
* @returns Runner of dynamic functions with specific location
|
|
135
136
|
*/
|
|
136
|
-
const validate: <Arguments extends any[]>(options: IOptions<Arguments
|
|
137
|
+
const validate: <Arguments extends any[]>(options: IOptions<Arguments>) => (path: string) => Promise<IReport>;
|
|
137
138
|
}
|
package/lib/DynamicExecutor.js
CHANGED
|
@@ -268,7 +268,7 @@ var DynamicExecutor;
|
|
|
268
268
|
switch (_a.label) {
|
|
269
269
|
case 0:
|
|
270
270
|
if (!(options.wrapper !== undefined)) return [3 /*break*/, 2];
|
|
271
|
-
return [4 /*yield*/, options.wrapper(key, closure)];
|
|
271
|
+
return [4 /*yield*/, options.wrapper(key, closure, options.parameters(key))];
|
|
272
272
|
case 1:
|
|
273
273
|
_a.sent();
|
|
274
274
|
return [3 /*break*/, 4];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicExecutor.js","sourceRoot":"","sources":["../src/DynamicExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,0CAAoB;AACpB,8CAA4B;AAE5B,yCAAwC;AAExC;;;;;;;;;;;;GAYG;AACH,IAAiB,eAAe,
|
|
1
|
+
{"version":3,"file":"DynamicExecutor.js","sourceRoot":"","sources":["../src/DynamicExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,0CAAoB;AACpB,8CAA4B;AAE5B,yCAAwC;AAExC;;;;;;;;;;;;GAYG;AACH,IAAiB,eAAe,CAiQ/B;AAjQD,WAAiB,eAAe;;IAuH9B;;;;;;;;;OASG;IACU,sBA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,KAAG,uBAAH,KAAG,CAAY,IAAI,CAAC,CAAE,CAC3D,CAAC;gDACF,IAAI,MAAM,KAAK,IAAI;oDAAE,MAAM,KAAG,CAAC;;;;;;;;;gCA3CN,KAAA,SAAA,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;;;;gCAAxC,KAAA,mBAAc,EAAb,GAAG,QAAA,EAAE,OAAO,QAAA;8DAAZ,GAAG,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;qBA8CzB;YA/CD,CA+CC;QAhDD,CAgDC;IAjDD,CAiDC,CAAC;AAKN,CAAC,EAjQgB,eAAe,+BAAf,eAAe,QAiQ/B"}
|
package/lib/TestValidator.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare namespace TestValidator {
|
|
|
62
62
|
*
|
|
63
63
|
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
|
|
64
64
|
*/
|
|
65
|
-
const search: (title: string) => <Entity extends IEntity<any>,
|
|
65
|
+
const search: (title: string) => <Entity extends IEntity<any>, Request>(getter: (input: Request) => Promise<Entity[]>) => (total: Entity[], sampleCount?: number) => <Values extends any[]>(props: ISearchProps<Entity, Values, Request>) => Promise<void>;
|
|
66
66
|
interface ISearchProps<Entity extends IEntity<any>, Values extends any[], Request> {
|
|
67
67
|
fields: string[];
|
|
68
68
|
values(entity: Entity): Values;
|
|
@@ -81,7 +81,7 @@ export declare namespace TestValidator {
|
|
|
81
81
|
* @param title Title of error message when sorting is invalid
|
|
82
82
|
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
83
83
|
*/
|
|
84
|
-
const sort: (title: string) => <T extends object, Fields extends string,
|
|
84
|
+
const sort: (title: string) => <T extends object, Fields extends string, Sortable extends (`-${Fields}` | `+${Fields}`)[] = (`-${Fields}` | `+${Fields}`)[]>(getter: (sortable: Sortable) => Promise<T[]>) => (...fields: Fields[]) => (comp: (x: T, y: T) => number, filter?: ((elem: T) => boolean) | undefined) => (direction: "+" | "-", trace?: boolean) => Promise<void>;
|
|
85
85
|
type Sortable<Literal extends string> = Array<`-${Literal}` | `+${Literal}`>;
|
|
86
86
|
}
|
|
87
87
|
interface IEntity<Type extends string | number | bigint> {
|
package/lib/TestValidator.js
CHANGED
|
@@ -46,6 +46,31 @@ var __values = (this && this.__values) || function(o) {
|
|
|
46
46
|
};
|
|
47
47
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
48
|
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
};
|
|
49
74
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
75
|
exports.TestValidator = void 0;
|
|
51
76
|
var ranges_1 = require("tstl/ranges");
|
|
@@ -358,10 +383,14 @@ var TestValidator;
|
|
|
358
383
|
/**
|
|
359
384
|
* @param direction "+" means ascending order, and "-" means descending order
|
|
360
385
|
*/
|
|
361
|
-
return function (
|
|
362
|
-
|
|
363
|
-
|
|
386
|
+
return function (direction_1) {
|
|
387
|
+
var args_1 = [];
|
|
388
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
389
|
+
args_1[_i - 1] = arguments[_i];
|
|
390
|
+
}
|
|
391
|
+
return __awaiter(_this, __spreadArray([direction_1], __read(args_1), false), void 0, function (direction, trace) {
|
|
364
392
|
var data, reversed;
|
|
393
|
+
if (trace === void 0) { trace = true; }
|
|
365
394
|
return __generator(this, function (_a) {
|
|
366
395
|
switch (_a.label) {
|
|
367
396
|
case 0: return [4 /*yield*/, getter(fields.map(function (field) { return "".concat(direction).concat(field); }))];
|
package/lib/TestValidator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAwC;AAExC,qDAAoD;AACpD,0DAAyD;AAEzD;;;;;;GAMG;AACH,IAAiB,aAAa,CAqT7B;AArTD,WAAiB,aAAa;;IAC5B;;;;;OAKG;IACU,uBAAS,GACpB,UAAC,KAAa;QACd,OAAA,UACE,SAAY;YAEZ,IAAM,OAAO,GAAG;gBACd,OAAA,iBAAU,KAAK,2CAAwC;YAAvD,CAAuD,CAAC;YAE1D,SAAS;YACT,IAAI,OAAO,SAAS,KAAK,SAAS,EAAE,CAAC;gBACnC,IAAI,SAAS,KAAK,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnD,OAAO,SAAgB,CAAC;YAC1B,CAAC;YAED,UAAU;YACV,IAAM,MAAM,GAA+B,SAAS,E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G,CAAC,UAAC,MAAM,IAAK,OAAA,MAAM,CAAC,EAAE,EAAT,CAAS,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAhB,CAAgB,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAC,KAAU;IAC5B,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAa,CAAC,IAAI,KAAK,UAAU;QACzC,OAAQ,KAAa,CAAC,KAAK,KAAK,UAAU,CAC3C,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/e2e",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "E2E test utilify functions",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"rimraf": "^4.1.2",
|
|
38
38
|
"ts-node": "^10.9.1",
|
|
39
39
|
"ts-patch": "^3.1.0",
|
|
40
|
-
"typescript": "^5.
|
|
41
|
-
"typia": "^5.3
|
|
40
|
+
"typescript": "^5.4.2",
|
|
41
|
+
"typia": "^5.5.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"chalk": "^4.1.2",
|
package/src/ArrayUtil.ts
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility functions for arrays.
|
|
3
|
-
*
|
|
4
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
5
|
-
*/
|
|
6
|
-
export namespace ArrayUtil {
|
|
7
|
-
export const asyncFilter =
|
|
8
|
-
<Input>(elements: readonly Input[]) =>
|
|
9
|
-
async (
|
|
10
|
-
pred: (
|
|
11
|
-
elem: Input,
|
|
12
|
-
index: number,
|
|
13
|
-
array: readonly Input[],
|
|
14
|
-
) => Promise<boolean>,
|
|
15
|
-
): Promise<Input[]> => {
|
|
16
|
-
const ret: Input[] = [];
|
|
17
|
-
await asyncForEach(elements)(async (elem, index, array) => {
|
|
18
|
-
const flag: boolean = await pred(elem, index, array);
|
|
19
|
-
if (flag === true) ret.push(elem);
|
|
20
|
-
});
|
|
21
|
-
return ret;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export const asyncForEach =
|
|
25
|
-
<Input>(elements: readonly Input[]) =>
|
|
26
|
-
async (
|
|
27
|
-
closure: (
|
|
28
|
-
elem: Input,
|
|
29
|
-
index: number,
|
|
30
|
-
array: readonly Input[],
|
|
31
|
-
) => Promise<any>,
|
|
32
|
-
): Promise<void> => {
|
|
33
|
-
await asyncRepeat(elements.length)((index) =>
|
|
34
|
-
closure(elements[index], index, elements),
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const asyncMap =
|
|
39
|
-
<Input>(elements: readonly Input[]) =>
|
|
40
|
-
async <Output>(
|
|
41
|
-
closure: (
|
|
42
|
-
elem: Input,
|
|
43
|
-
index: number,
|
|
44
|
-
array: readonly Input[],
|
|
45
|
-
) => Promise<Output>,
|
|
46
|
-
): Promise<Output[]> => {
|
|
47
|
-
const ret: Output[] = [];
|
|
48
|
-
await asyncForEach(elements)(async (elem, index, array) => {
|
|
49
|
-
const output: Output = await closure(elem, index, array);
|
|
50
|
-
ret.push(output);
|
|
51
|
-
});
|
|
52
|
-
return ret;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const asyncRepeat =
|
|
56
|
-
(count: number) =>
|
|
57
|
-
async <T>(closure: (index: number) => Promise<T>): Promise<T[]> => {
|
|
58
|
-
const indexes: number[] = new Array(count)
|
|
59
|
-
.fill(1)
|
|
60
|
-
.map((_, index) => index);
|
|
61
|
-
|
|
62
|
-
const output: T[] = [];
|
|
63
|
-
for (const index of indexes) output.push(await closure(index));
|
|
64
|
-
|
|
65
|
-
return output;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const has =
|
|
69
|
-
<T>(elements: readonly T[]) =>
|
|
70
|
-
(pred: (elem: T) => boolean): boolean =>
|
|
71
|
-
elements.find(pred) !== undefined;
|
|
72
|
-
|
|
73
|
-
export const repeat =
|
|
74
|
-
(count: number) =>
|
|
75
|
-
<T>(closure: (index: number) => T): T[] =>
|
|
76
|
-
new Array(count).fill("").map((_, index) => closure(index));
|
|
77
|
-
|
|
78
|
-
export const flat = <T>(matrix: T[][]): T[] => ([] as T[]).concat(...matrix);
|
|
79
|
-
|
|
80
|
-
export const subsets = <T>(array: T[]): T[][] => {
|
|
81
|
-
const check: boolean[] = new Array(array.length).fill(false);
|
|
82
|
-
const output: T[][] = [];
|
|
83
|
-
|
|
84
|
-
const dfs = (depth: number): void => {
|
|
85
|
-
if (depth === check.length)
|
|
86
|
-
output.push(array.filter((_v, idx) => check[idx]));
|
|
87
|
-
else {
|
|
88
|
-
check[depth] = true;
|
|
89
|
-
dfs(depth + 1);
|
|
90
|
-
|
|
91
|
-
check[depth] = false;
|
|
92
|
-
dfs(depth + 1);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
dfs(0);
|
|
96
|
-
return output;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for arrays.
|
|
3
|
+
*
|
|
4
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
5
|
+
*/
|
|
6
|
+
export namespace ArrayUtil {
|
|
7
|
+
export const asyncFilter =
|
|
8
|
+
<Input>(elements: readonly Input[]) =>
|
|
9
|
+
async (
|
|
10
|
+
pred: (
|
|
11
|
+
elem: Input,
|
|
12
|
+
index: number,
|
|
13
|
+
array: readonly Input[],
|
|
14
|
+
) => Promise<boolean>,
|
|
15
|
+
): Promise<Input[]> => {
|
|
16
|
+
const ret: Input[] = [];
|
|
17
|
+
await asyncForEach(elements)(async (elem, index, array) => {
|
|
18
|
+
const flag: boolean = await pred(elem, index, array);
|
|
19
|
+
if (flag === true) ret.push(elem);
|
|
20
|
+
});
|
|
21
|
+
return ret;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const asyncForEach =
|
|
25
|
+
<Input>(elements: readonly Input[]) =>
|
|
26
|
+
async (
|
|
27
|
+
closure: (
|
|
28
|
+
elem: Input,
|
|
29
|
+
index: number,
|
|
30
|
+
array: readonly Input[],
|
|
31
|
+
) => Promise<any>,
|
|
32
|
+
): Promise<void> => {
|
|
33
|
+
await asyncRepeat(elements.length)((index) =>
|
|
34
|
+
closure(elements[index], index, elements),
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const asyncMap =
|
|
39
|
+
<Input>(elements: readonly Input[]) =>
|
|
40
|
+
async <Output>(
|
|
41
|
+
closure: (
|
|
42
|
+
elem: Input,
|
|
43
|
+
index: number,
|
|
44
|
+
array: readonly Input[],
|
|
45
|
+
) => Promise<Output>,
|
|
46
|
+
): Promise<Output[]> => {
|
|
47
|
+
const ret: Output[] = [];
|
|
48
|
+
await asyncForEach(elements)(async (elem, index, array) => {
|
|
49
|
+
const output: Output = await closure(elem, index, array);
|
|
50
|
+
ret.push(output);
|
|
51
|
+
});
|
|
52
|
+
return ret;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const asyncRepeat =
|
|
56
|
+
(count: number) =>
|
|
57
|
+
async <T>(closure: (index: number) => Promise<T>): Promise<T[]> => {
|
|
58
|
+
const indexes: number[] = new Array(count)
|
|
59
|
+
.fill(1)
|
|
60
|
+
.map((_, index) => index);
|
|
61
|
+
|
|
62
|
+
const output: T[] = [];
|
|
63
|
+
for (const index of indexes) output.push(await closure(index));
|
|
64
|
+
|
|
65
|
+
return output;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const has =
|
|
69
|
+
<T>(elements: readonly T[]) =>
|
|
70
|
+
(pred: (elem: T) => boolean): boolean =>
|
|
71
|
+
elements.find(pred) !== undefined;
|
|
72
|
+
|
|
73
|
+
export const repeat =
|
|
74
|
+
(count: number) =>
|
|
75
|
+
<T>(closure: (index: number) => T): T[] =>
|
|
76
|
+
new Array(count).fill("").map((_, index) => closure(index));
|
|
77
|
+
|
|
78
|
+
export const flat = <T>(matrix: T[][]): T[] => ([] as T[]).concat(...matrix);
|
|
79
|
+
|
|
80
|
+
export const subsets = <T>(array: T[]): T[][] => {
|
|
81
|
+
const check: boolean[] = new Array(array.length).fill(false);
|
|
82
|
+
const output: T[][] = [];
|
|
83
|
+
|
|
84
|
+
const dfs = (depth: number): void => {
|
|
85
|
+
if (depth === check.length)
|
|
86
|
+
output.push(array.filter((_v, idx) => check[idx]));
|
|
87
|
+
else {
|
|
88
|
+
check[depth] = true;
|
|
89
|
+
dfs(depth + 1);
|
|
90
|
+
|
|
91
|
+
check[depth] = false;
|
|
92
|
+
dfs(depth + 1);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
dfs(0);
|
|
96
|
+
return output;
|
|
97
|
+
};
|
|
98
|
+
}
|
package/src/DynamicExecutor.ts
CHANGED
|
@@ -66,9 +66,14 @@ export namespace DynamicExecutor {
|
|
|
66
66
|
*
|
|
67
67
|
* @param name Function name
|
|
68
68
|
* @param closure Function to be executed
|
|
69
|
+
* @param parameters Parameters, result of options.parameters function.
|
|
69
70
|
* @returns Wrapper function
|
|
70
71
|
*/
|
|
71
|
-
wrapper?: (
|
|
72
|
+
wrapper?: (
|
|
73
|
+
name: string,
|
|
74
|
+
closure: Closure<Parameters, Ret>,
|
|
75
|
+
paramters: Parameters,
|
|
76
|
+
) => Promise<any>;
|
|
72
77
|
|
|
73
78
|
/**
|
|
74
79
|
* Whether to show elapsed time on `console` or not.
|
|
@@ -228,7 +233,7 @@ export namespace DynamicExecutor {
|
|
|
228
233
|
|
|
229
234
|
const func = async () => {
|
|
230
235
|
if (options.wrapper !== undefined)
|
|
231
|
-
await options.wrapper(key, closure);
|
|
236
|
+
await options.wrapper(key, closure, options.parameters(key));
|
|
232
237
|
else await closure(...options.parameters(key));
|
|
233
238
|
};
|
|
234
239
|
const label: string = chalk.greenBright(key);
|
package/src/GaffComparator.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gaff comparator.
|
|
3
|
-
*
|
|
4
|
-
* `GaffComparator` is a set of comparator functions for `Array.sort()` function,
|
|
5
|
-
* which can be used with {@link TestValidator.sort} function. If you want to see
|
|
6
|
-
* how to use them, see the below example link.
|
|
7
|
-
*
|
|
8
|
-
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
9
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
-
*/
|
|
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));
|
|
23
|
-
|
|
24
|
-
const idx: number = a.findIndex((v, i) => v !== b[i]);
|
|
25
|
-
return idx !== -1 ? compare(a[idx], b[idx]) : 0;
|
|
26
|
-
};
|
|
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);
|
|
41
|
-
|
|
42
|
-
const idx: number = a.findIndex((v, i) => v !== b[i]);
|
|
43
|
-
return idx !== -1 ? a[idx] - b[idx] : 0;
|
|
44
|
-
};
|
|
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));
|
|
57
|
-
|
|
58
|
-
const idx: number = a.findIndex((v, i) => v !== b[i]);
|
|
59
|
-
return idx !== -1 ? a[idx] - b[idx] : 0;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
function compare(x: string, y: string) {
|
|
63
|
-
return x.localeCompare(y);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function wrap<T>(elem: T | T[]): T[] {
|
|
67
|
-
return Array.isArray(elem) ? elem : [elem];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Gaff comparator.
|
|
3
|
+
*
|
|
4
|
+
* `GaffComparator` is a set of comparator functions for `Array.sort()` function,
|
|
5
|
+
* which can be used with {@link TestValidator.sort} function. If you want to see
|
|
6
|
+
* how to use them, see the below example link.
|
|
7
|
+
*
|
|
8
|
+
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
9
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
+
*/
|
|
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));
|
|
23
|
+
|
|
24
|
+
const idx: number = a.findIndex((v, i) => v !== b[i]);
|
|
25
|
+
return idx !== -1 ? compare(a[idx], b[idx]) : 0;
|
|
26
|
+
};
|
|
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);
|
|
41
|
+
|
|
42
|
+
const idx: number = a.findIndex((v, i) => v !== b[i]);
|
|
43
|
+
return idx !== -1 ? a[idx] - b[idx] : 0;
|
|
44
|
+
};
|
|
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));
|
|
57
|
+
|
|
58
|
+
const idx: number = a.findIndex((v, i) => v !== b[i]);
|
|
59
|
+
return idx !== -1 ? a[idx] - b[idx] : 0;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function compare(x: string, y: string) {
|
|
63
|
+
return x.localeCompare(y);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function wrap<T>(elem: T | T[]): T[] {
|
|
67
|
+
return Array.isArray(elem) ? elem : [elem];
|
|
68
|
+
}
|
|
69
|
+
}
|