@nestia/e2e 0.1.0 → 0.1.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/README.md +22 -13
- package/lib/ArrayUtil.d.ts +5 -1
- package/lib/ArrayUtil.js +5 -4
- package/lib/ArrayUtil.js.map +1 -1
- package/lib/DynamicExecutor.d.ts +1 -1
- package/lib/DynamicExecutor.js +1 -1
- package/lib/GaffComparator.js +1 -1
- package/lib/GaffComparator.js.map +1 -1
- package/lib/RandomGenerator.d.ts +2 -2
- package/lib/RandomGenerator.js +2 -0
- package/lib/RandomGenerator.js.map +1 -1
- package/lib/TestValidator.d.ts +3 -0
- package/lib/TestValidator.js +3 -0
- package/lib/TestValidator.js.map +1 -1
- package/package.json +4 -1
- package/src/ArrayUtil.ts +87 -86
- package/src/DynamicExecutor.ts +270 -270
- package/src/GaffComparator.ts +69 -69
- package/src/RandomGenerator.ts +178 -178
- package/src/StopWatch.ts +36 -36
- package/src/TestValidator.ts +145 -142
- package/src/index.ts +4 -4
- package/src/module.ts +6 -6
package/src/TestValidator.ts
CHANGED
|
@@ -1,142 +1,145 @@
|
|
|
1
|
-
import { is_sorted } from "tstl/ranges";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Test validator.
|
|
5
|
-
*
|
|
6
|
-
* `TestValidator` is a collection gathering E2E validation functions.
|
|
7
|
-
*
|
|
8
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
9
|
-
*/
|
|
10
|
-
export namespace TestValidator {
|
|
11
|
-
/**
|
|
12
|
-
* Test whether error occurs.
|
|
13
|
-
*
|
|
14
|
-
* If error occurs, nothing would be happened.
|
|
15
|
-
*
|
|
16
|
-
* However, no error exists, then exception would be thrown.
|
|
17
|
-
*
|
|
18
|
-
* @param title Title of exception because of no error exists
|
|
19
|
-
*/
|
|
20
|
-
export const error =
|
|
21
|
-
(title: string) =>
|
|
22
|
-
async (task: () => any | Promise<any>): Promise<void> => {
|
|
23
|
-
try {
|
|
24
|
-
await task();
|
|
25
|
-
} catch {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
throw new Error(`Bug on ${title}: exception must be thrown.`);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Validate index API.
|
|
33
|
-
*
|
|
34
|
-
* Test whether two indexed values are equal.
|
|
35
|
-
*
|
|
36
|
-
* If two values are different, then exception would be thrown.
|
|
37
|
-
*
|
|
38
|
-
* @param title Title of error message when different
|
|
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
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
1
|
+
import { is_sorted } from "tstl/ranges";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test validator.
|
|
5
|
+
*
|
|
6
|
+
* `TestValidator` is a collection gathering E2E validation functions.
|
|
7
|
+
*
|
|
8
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
9
|
+
*/
|
|
10
|
+
export namespace TestValidator {
|
|
11
|
+
/**
|
|
12
|
+
* Test whether error occurs.
|
|
13
|
+
*
|
|
14
|
+
* If error occurs, nothing would be happened.
|
|
15
|
+
*
|
|
16
|
+
* However, no error exists, then exception would be thrown.
|
|
17
|
+
*
|
|
18
|
+
* @param title Title of exception because of no error exists
|
|
19
|
+
*/
|
|
20
|
+
export const error =
|
|
21
|
+
(title: string) =>
|
|
22
|
+
async (task: () => any | Promise<any>): Promise<void> => {
|
|
23
|
+
try {
|
|
24
|
+
await task();
|
|
25
|
+
} catch {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(`Bug on ${title}: exception must be thrown.`);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Validate index API.
|
|
33
|
+
*
|
|
34
|
+
* Test whether two indexed values are equal.
|
|
35
|
+
*
|
|
36
|
+
* If two values are different, then exception would be thrown.
|
|
37
|
+
*
|
|
38
|
+
* @param title Title of error message when different
|
|
39
|
+
* @return Currying function
|
|
40
|
+
*
|
|
41
|
+
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_search.ts
|
|
42
|
+
*/
|
|
43
|
+
export const index =
|
|
44
|
+
(title: string) =>
|
|
45
|
+
<Solution extends IEntity<any>>(expected: Solution[]) =>
|
|
46
|
+
<Summary extends IEntity<any>>(
|
|
47
|
+
gotten: Summary[],
|
|
48
|
+
trace: boolean = true,
|
|
49
|
+
): void => {
|
|
50
|
+
const length: number = Math.min(expected.length, gotten.length);
|
|
51
|
+
expected = expected.slice(0, length);
|
|
52
|
+
gotten = gotten.slice(0, length);
|
|
53
|
+
|
|
54
|
+
const xIds: string[] = get_ids(expected).slice(0, length);
|
|
55
|
+
const yIds: string[] = get_ids(gotten)
|
|
56
|
+
.filter((id) => id >= xIds[0])
|
|
57
|
+
.slice(0, length);
|
|
58
|
+
|
|
59
|
+
const equals: boolean = xIds.every((x, i) => x === yIds[i]);
|
|
60
|
+
if (equals === true) return;
|
|
61
|
+
else if (trace === true)
|
|
62
|
+
console.log({
|
|
63
|
+
expected: xIds,
|
|
64
|
+
gotten: yIds,
|
|
65
|
+
});
|
|
66
|
+
throw new Error(
|
|
67
|
+
`Bug on ${title}: result of the index is different with manual aggregation.`,
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Validate sorting options.
|
|
73
|
+
*
|
|
74
|
+
* Test a pagination API supporting sorting options.
|
|
75
|
+
*
|
|
76
|
+
* You can validate detailed sorting options both asceding and descending orders
|
|
77
|
+
* with multiple fields. However, as it forms a complicate currying function,
|
|
78
|
+
* I recomend you to see below example code before using.
|
|
79
|
+
*
|
|
80
|
+
* @param title Title of error messaeg when sorting is invalid
|
|
81
|
+
*
|
|
82
|
+
* @example https://github.com/samchon/nestia-template/blob/master/src/test/features/api/bbs/test_api_bbs_article_index_sort.ts
|
|
83
|
+
*/
|
|
84
|
+
export const sort =
|
|
85
|
+
(title: string) =>
|
|
86
|
+
/**
|
|
87
|
+
* @param getter A pagination API function to be called
|
|
88
|
+
*/
|
|
89
|
+
<
|
|
90
|
+
T extends object,
|
|
91
|
+
Fields extends string,
|
|
92
|
+
Sortable extends Array<`-${Fields}` | `+${Fields}`>,
|
|
93
|
+
>(
|
|
94
|
+
getter: (sortable: Sortable) => Promise<T[]>,
|
|
95
|
+
) =>
|
|
96
|
+
/**
|
|
97
|
+
* @param fields List of fields to be sorted
|
|
98
|
+
*/
|
|
99
|
+
(...fields: Fields[]) =>
|
|
100
|
+
/**
|
|
101
|
+
* @param comp Comparator function for validation
|
|
102
|
+
* @param filter Filter function for data if required
|
|
103
|
+
*/
|
|
104
|
+
(comp: (x: T, y: T) => number, filter?: (elem: T) => boolean) =>
|
|
105
|
+
/**
|
|
106
|
+
* @param direction "+" means ascending order, and "-" means descending order
|
|
107
|
+
*/
|
|
108
|
+
async (direction: "+" | "-", trace: boolean = true) => {
|
|
109
|
+
let data: T[] = await getter(
|
|
110
|
+
fields.map(
|
|
111
|
+
(field) => `${direction}${field}` as const,
|
|
112
|
+
) as Sortable,
|
|
113
|
+
);
|
|
114
|
+
if (filter) data = data.filter(filter);
|
|
115
|
+
|
|
116
|
+
const reversed: typeof comp =
|
|
117
|
+
direction === "+" ? comp : (x, y) => comp(y, x);
|
|
118
|
+
if (is_sorted(data, (x, y) => reversed(x, y) < 0) === false) {
|
|
119
|
+
if (
|
|
120
|
+
fields.length === 1 &&
|
|
121
|
+
data.length &&
|
|
122
|
+
(data as any)[0][fields[0]] !== undefined &&
|
|
123
|
+
trace
|
|
124
|
+
)
|
|
125
|
+
console.log(data.map((elem) => (elem as any)[fields[0]]));
|
|
126
|
+
throw new Error(
|
|
127
|
+
`Bug on ${title}: wrong sorting on ${direction}(${fields.join(
|
|
128
|
+
", ",
|
|
129
|
+
)}).`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export type Sortable<Literal extends string> = Array<
|
|
135
|
+
`-${Literal}` | `+${Literal}`
|
|
136
|
+
>;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface IEntity<Type extends string | number | bigint> {
|
|
140
|
+
id: Type;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function get_ids<Entity extends IEntity<any>>(entities: Entity[]): string[] {
|
|
144
|
+
return entities.map((entity) => entity.id).sort((x, y) => (x < y ? -1 : 1));
|
|
145
|
+
}
|
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";
|
package/src/module.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./ArrayUtil";
|
|
2
|
-
export * from "./DynamicExecutor";
|
|
3
|
-
export * from "./GaffComparator";
|
|
4
|
-
export * from "./RandomGenerator";
|
|
5
|
-
export * from "./StopWatch";
|
|
6
|
-
export * from "./TestValidator";
|
|
1
|
+
export * from "./ArrayUtil";
|
|
2
|
+
export * from "./DynamicExecutor";
|
|
3
|
+
export * from "./GaffComparator";
|
|
4
|
+
export * from "./RandomGenerator";
|
|
5
|
+
export * from "./StopWatch";
|
|
6
|
+
export * from "./TestValidator";
|