@nestia/e2e 0.4.3 → 0.5.0-dev.20240617-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/README.md +1 -1
- package/lib/DynamicBenchmarker.d.ts +114 -0
- package/lib/DynamicBenchmarker.js +404 -0
- package/lib/DynamicBenchmarker.js.map +1 -0
- package/lib/TestValidator.d.ts +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +1 -0
- package/lib/module.js.map +1 -1
- package/lib/structures/IBenchmarkEvent.d.ts +8 -0
- package/lib/structures/IBenchmarkEvent.js +3 -0
- package/lib/structures/IBenchmarkEvent.js.map +1 -0
- package/lib/structures/IBenchmarkMaster.d.ts +6 -0
- package/lib/structures/IBenchmarkMaster.js +3 -0
- package/lib/structures/IBenchmarkMaster.js.map +1 -0
- package/lib/structures/IBenchmarkServant.d.ts +7 -0
- package/lib/structures/IBenchmarkServant.js +3 -0
- package/lib/structures/IBenchmarkServant.js.map +1 -0
- package/package.json +4 -2
- package/src/ArrayUtil.ts +98 -98
- package/src/DynamicBenchmarker.ts +328 -0
- package/src/DynamicExecutor.ts +277 -277
- package/src/GaffComparator.ts +69 -69
- package/src/StopWatch.ts +38 -38
- package/src/index.ts +4 -4
- package/src/internal/json_equal_to.ts +34 -34
- package/src/module.ts +7 -6
- package/src/structures/IBenchmarkEvent.ts +9 -0
- package/src/structures/IBenchmarkMaster.ts +5 -0
- package/src/structures/IBenchmarkServant.ts +8 -0
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
|
+
}
|
package/src/StopWatch.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Elapsed time measurement utility.
|
|
3
|
-
*
|
|
4
|
-
* @author Sachon
|
|
5
|
-
*/
|
|
6
|
-
export namespace StopWatch {
|
|
7
|
-
/**
|
|
8
|
-
* Type of task.
|
|
9
|
-
*/
|
|
10
|
-
export type Task<T> = () => Promise<T>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param task
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
export const measure = async <T>(task: Task<T>): Promise<[T, number]> => {
|
|
18
|
-
const time: number = Date.now();
|
|
19
|
-
const output: T = await task();
|
|
20
|
-
return [output, Date.now() - time];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @param title
|
|
26
|
-
* @param task
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export const trace =
|
|
30
|
-
(title: string) =>
|
|
31
|
-
async <T>(task: Task<T>): Promise<[T, number]> => {
|
|
32
|
-
process.stdout.write(` - ${title}: `);
|
|
33
|
-
const res: [T, number] = await measure(task);
|
|
34
|
-
|
|
35
|
-
console.log(`${res[1].toLocaleString()} ms`);
|
|
36
|
-
return res;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Elapsed time measurement utility.
|
|
3
|
+
*
|
|
4
|
+
* @author Sachon
|
|
5
|
+
*/
|
|
6
|
+
export namespace StopWatch {
|
|
7
|
+
/**
|
|
8
|
+
* Type of task.
|
|
9
|
+
*/
|
|
10
|
+
export type Task<T> = () => Promise<T>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param task
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export const measure = async <T>(task: Task<T>): Promise<[T, number]> => {
|
|
18
|
+
const time: number = Date.now();
|
|
19
|
+
const output: T = await task();
|
|
20
|
+
return [output, Date.now() - time];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param title
|
|
26
|
+
* @param task
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export const trace =
|
|
30
|
+
(title: string) =>
|
|
31
|
+
async <T>(task: Task<T>): Promise<[T, number]> => {
|
|
32
|
+
process.stdout.write(` - ${title}: `);
|
|
33
|
+
const res: [T, number] = await measure(task);
|
|
34
|
+
|
|
35
|
+
console.log(`${res[1].toLocaleString()} ms`);
|
|
36
|
+
return res;
|
|
37
|
+
};
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as e2e from "./module";
|
|
2
|
-
|
|
3
|
-
export default e2e;
|
|
4
|
-
export * from "./module";
|
|
1
|
+
import * as e2e from "./module";
|
|
2
|
+
|
|
3
|
+
export default e2e;
|
|
4
|
+
export * from "./module";
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
export const json_equal_to =
|
|
2
|
-
(exception: (key: string) => boolean) =>
|
|
3
|
-
<T>(x: T) =>
|
|
4
|
-
(y: T): string[] => {
|
|
5
|
-
const container: string[] = [];
|
|
6
|
-
const iterate =
|
|
7
|
-
(accessor: string) =>
|
|
8
|
-
(x: any) =>
|
|
9
|
-
(y: any): void => {
|
|
10
|
-
if (typeof x !== typeof y) container.push(accessor);
|
|
11
|
-
else if (x instanceof Array)
|
|
12
|
-
if (!(y instanceof Array)) container.push(accessor);
|
|
13
|
-
else array(accessor)(x)(y);
|
|
14
|
-
else if (x instanceof Object) object(accessor)(x)(y);
|
|
15
|
-
else if (x !== y) container.push(accessor);
|
|
16
|
-
};
|
|
17
|
-
const array =
|
|
18
|
-
(accessor: string) =>
|
|
19
|
-
(x: any[]) =>
|
|
20
|
-
(y: any[]): void => {
|
|
21
|
-
if (x.length !== y.length) container.push(`${accessor}.length`);
|
|
22
|
-
x.forEach((xItem, i) => iterate(`${accessor}[${i}]`)(xItem)(y[i]));
|
|
23
|
-
};
|
|
24
|
-
const object =
|
|
25
|
-
(accessor: string) =>
|
|
26
|
-
(x: any) =>
|
|
27
|
-
(y: any): void =>
|
|
28
|
-
Object.keys(x)
|
|
29
|
-
.filter((key) => x[key] !== undefined && !exception(key))
|
|
30
|
-
.forEach((key) => iterate(`${accessor}.${key}`)(x[key])(y[key]));
|
|
31
|
-
|
|
32
|
-
iterate("")(x)(y);
|
|
33
|
-
return container;
|
|
34
|
-
};
|
|
1
|
+
export const json_equal_to =
|
|
2
|
+
(exception: (key: string) => boolean) =>
|
|
3
|
+
<T>(x: T) =>
|
|
4
|
+
(y: T): string[] => {
|
|
5
|
+
const container: string[] = [];
|
|
6
|
+
const iterate =
|
|
7
|
+
(accessor: string) =>
|
|
8
|
+
(x: any) =>
|
|
9
|
+
(y: any): void => {
|
|
10
|
+
if (typeof x !== typeof y) container.push(accessor);
|
|
11
|
+
else if (x instanceof Array)
|
|
12
|
+
if (!(y instanceof Array)) container.push(accessor);
|
|
13
|
+
else array(accessor)(x)(y);
|
|
14
|
+
else if (x instanceof Object) object(accessor)(x)(y);
|
|
15
|
+
else if (x !== y) container.push(accessor);
|
|
16
|
+
};
|
|
17
|
+
const array =
|
|
18
|
+
(accessor: string) =>
|
|
19
|
+
(x: any[]) =>
|
|
20
|
+
(y: any[]): void => {
|
|
21
|
+
if (x.length !== y.length) container.push(`${accessor}.length`);
|
|
22
|
+
x.forEach((xItem, i) => iterate(`${accessor}[${i}]`)(xItem)(y[i]));
|
|
23
|
+
};
|
|
24
|
+
const object =
|
|
25
|
+
(accessor: string) =>
|
|
26
|
+
(x: any) =>
|
|
27
|
+
(y: any): void =>
|
|
28
|
+
Object.keys(x)
|
|
29
|
+
.filter((key) => x[key] !== undefined && !exception(key))
|
|
30
|
+
.forEach((key) => iterate(`${accessor}.${key}`)(x[key])(y[key]));
|
|
31
|
+
|
|
32
|
+
iterate("")(x)(y);
|
|
33
|
+
return container;
|
|
34
|
+
};
|
package/src/module.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./ArrayUtil";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
1
|
+
export * from "./ArrayUtil";
|
|
2
|
+
export * from "./DynamicBenchmarker";
|
|
3
|
+
export * from "./DynamicExecutor";
|
|
4
|
+
export * from "./GaffComparator";
|
|
5
|
+
export * from "./RandomGenerator";
|
|
6
|
+
export * from "./StopWatch";
|
|
7
|
+
export * from "./TestValidator";
|