@nestia/e2e 7.0.0-dev.20250607 → 7.0.0
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/LICENSE +21 -21
- package/README.md +92 -92
- package/package.json +1 -1
- package/src/ArrayUtil.ts +98 -98
- package/src/DynamicExecutor.ts +296 -296
- package/src/GaffComparator.ts +64 -64
- package/src/RandomGenerator.ts +162 -162
- package/src/TestValidator.ts +347 -347
- package/src/index.ts +4 -4
- package/src/internal/json_equal_to.ts +35 -35
- package/src/module.ts +5 -5
package/src/GaffComparator.ts
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
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): number => {
|
|
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): number => {
|
|
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): number => {
|
|
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
|
-
const compare = (x: string, y: string) => x.localeCompare(y);
|
|
63
|
-
const wrap = <T>(elem: T | T[]): T[] => (Array.isArray(elem) ? elem : [elem]);
|
|
64
|
-
}
|
|
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): number => {
|
|
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): number => {
|
|
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): number => {
|
|
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
|
+
const compare = (x: string, y: string) => x.localeCompare(y);
|
|
63
|
+
const wrap = <T>(elem: T | T[]): T[] => (Array.isArray(elem) ? elem : [elem]);
|
|
64
|
+
}
|
package/src/RandomGenerator.ts
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Random data generator.
|
|
3
|
-
*
|
|
4
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
5
|
-
*/
|
|
6
|
-
export namespace RandomGenerator {
|
|
7
|
-
/* ----------------------------------------------------------------
|
|
8
|
-
IDENTIFICATIONS
|
|
9
|
-
---------------------------------------------------------------- */
|
|
10
|
-
const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
11
|
-
const LETTERS: string = "0123456789" + CHARACTERS;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Generate random alphabets
|
|
15
|
-
*
|
|
16
|
-
* @param length Length of alphabets
|
|
17
|
-
* @returns Generated alphabets
|
|
18
|
-
*/
|
|
19
|
-
export const alphabets = (length: number): string =>
|
|
20
|
-
new Array(length)
|
|
21
|
-
.fill("")
|
|
22
|
-
.map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
|
|
23
|
-
.join("");
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Generate random alpha-numeric characters.
|
|
27
|
-
*
|
|
28
|
-
* Generate random string constructed with only alphabets and numbers.
|
|
29
|
-
*
|
|
30
|
-
* @param length Length of characters
|
|
31
|
-
* @returns Generated string
|
|
32
|
-
*/
|
|
33
|
-
export const alphaNumeric = (length: number): string =>
|
|
34
|
-
new Array(length)
|
|
35
|
-
.fill("")
|
|
36
|
-
.map(() => LETTERS[randint(0, LETTERS.length - 1)])
|
|
37
|
-
.join("");
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generate random name.
|
|
41
|
-
*
|
|
42
|
-
* @param length Length of paragraph, default is 2 or 3
|
|
43
|
-
* @returns Generated name
|
|
44
|
-
*/
|
|
45
|
-
export const name = (length: number = randint(2, 3)): string =>
|
|
46
|
-
paragraph(length)();
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Generate random paragraph.
|
|
50
|
-
*
|
|
51
|
-
* @param sentences Number of sentences
|
|
52
|
-
* @returns Paragraph generator
|
|
53
|
-
*/
|
|
54
|
-
export const paragraph =
|
|
55
|
-
(sentences: number = randint(2, 5)) =>
|
|
56
|
-
/**
|
|
57
|
-
* @param wordMin Minimum number of characters in a sentence
|
|
58
|
-
* @param wordMax Maximum number of characters in a sentence
|
|
59
|
-
* @returns Generated paragraph
|
|
60
|
-
*/
|
|
61
|
-
(wordMin: number = 3, wordMax: number = 7): string =>
|
|
62
|
-
new Array(sentences)
|
|
63
|
-
.fill("")
|
|
64
|
-
.map(() => alphabets(randint(wordMin, wordMax)))
|
|
65
|
-
.join(" ");
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Generate random content.
|
|
69
|
-
*
|
|
70
|
-
* @param paragraphs Number of paragraphs
|
|
71
|
-
* @returns Currying function
|
|
72
|
-
*/
|
|
73
|
-
export const content =
|
|
74
|
-
(paragraphs: number = randint(3, 8)) =>
|
|
75
|
-
/**
|
|
76
|
-
* @param sentenceMin Minimum number of sentences in a paragraph
|
|
77
|
-
* @param sentenceMax Maximum number of sentences in a paragraph
|
|
78
|
-
* @returns Currying function
|
|
79
|
-
*/
|
|
80
|
-
(sentenceMin: number = 10, sentenceMax: number = 40) =>
|
|
81
|
-
/**
|
|
82
|
-
* @param wordMin Minimum number of characters in a sentence
|
|
83
|
-
* @param wordMax Maximum number of characters in a sentence
|
|
84
|
-
* @returns Content generator
|
|
85
|
-
*/
|
|
86
|
-
(wordMin: number = 1, wordMax: number = 7): string =>
|
|
87
|
-
new Array(paragraphs)
|
|
88
|
-
.fill("")
|
|
89
|
-
.map(() =>
|
|
90
|
-
paragraph(randint(sentenceMin, sentenceMax))(wordMin, wordMax),
|
|
91
|
-
)
|
|
92
|
-
.join("\n\n");
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Generate random substring.
|
|
96
|
-
*
|
|
97
|
-
* @param content Target content
|
|
98
|
-
* @returns Random substring
|
|
99
|
-
*/
|
|
100
|
-
export const substring = (content: string): string => {
|
|
101
|
-
const first: number = randint(0, content.length - 1);
|
|
102
|
-
const last: number = randint(first + 1, content.length);
|
|
103
|
-
|
|
104
|
-
return content.substring(first, last).trim();
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Generate random mobile number.
|
|
109
|
-
*
|
|
110
|
-
* @param prefix Prefix string, default is "010"
|
|
111
|
-
* @returns Random mobile number
|
|
112
|
-
* @example 0103340067
|
|
113
|
-
*/
|
|
114
|
-
export const mobile = (prefix: string = "010"): string =>
|
|
115
|
-
[
|
|
116
|
-
prefix,
|
|
117
|
-
(() => {
|
|
118
|
-
const value = randint(0, 9999);
|
|
119
|
-
return value.toString().padStart(value < 1_000 ? 3 : 4, "0");
|
|
120
|
-
})(),
|
|
121
|
-
randint(0, 9999).toString().padStart(4, "0"),
|
|
122
|
-
].join("");
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Generate random date.
|
|
126
|
-
*
|
|
127
|
-
* @param from Start date
|
|
128
|
-
* @param range Range of random milliseconds
|
|
129
|
-
* @returns Random date
|
|
130
|
-
*/
|
|
131
|
-
export const date =
|
|
132
|
-
(from: Date) =>
|
|
133
|
-
(range: number): Date =>
|
|
134
|
-
new Date(from.getTime() + randint(0, range));
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Pick random elements from an array.
|
|
138
|
-
*
|
|
139
|
-
* @param array Target array
|
|
140
|
-
* @param count Number of count to pick
|
|
141
|
-
* @returns Sampled array
|
|
142
|
-
*/
|
|
143
|
-
export const sample =
|
|
144
|
-
<T>(array: T[]) =>
|
|
145
|
-
(count: number): T[] => {
|
|
146
|
-
count = Math.min(count, array.length);
|
|
147
|
-
const indexes: Set<number> = new Set();
|
|
148
|
-
while (indexes.size < count) indexes.add(randint(0, array.length - 1));
|
|
149
|
-
return Array.from(indexes).map((index) => array[index]);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Pick random element from an array.
|
|
154
|
-
*
|
|
155
|
-
* @param array Target array
|
|
156
|
-
* @returns picked element
|
|
157
|
-
*/
|
|
158
|
-
export const pick = <T>(array: T[]): T => array[randint(0, array.length - 1)];
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const randint = (min: number, max: number): number =>
|
|
162
|
-
Math.floor(Math.random() * (max - min + 1)) + min;
|
|
1
|
+
/**
|
|
2
|
+
* Random data generator.
|
|
3
|
+
*
|
|
4
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
5
|
+
*/
|
|
6
|
+
export namespace RandomGenerator {
|
|
7
|
+
/* ----------------------------------------------------------------
|
|
8
|
+
IDENTIFICATIONS
|
|
9
|
+
---------------------------------------------------------------- */
|
|
10
|
+
const CHARACTERS = "abcdefghijklmnopqrstuvwxyz";
|
|
11
|
+
const LETTERS: string = "0123456789" + CHARACTERS;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Generate random alphabets
|
|
15
|
+
*
|
|
16
|
+
* @param length Length of alphabets
|
|
17
|
+
* @returns Generated alphabets
|
|
18
|
+
*/
|
|
19
|
+
export const alphabets = (length: number): string =>
|
|
20
|
+
new Array(length)
|
|
21
|
+
.fill("")
|
|
22
|
+
.map(() => CHARACTERS[randint(0, CHARACTERS.length - 1)])
|
|
23
|
+
.join("");
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generate random alpha-numeric characters.
|
|
27
|
+
*
|
|
28
|
+
* Generate random string constructed with only alphabets and numbers.
|
|
29
|
+
*
|
|
30
|
+
* @param length Length of characters
|
|
31
|
+
* @returns Generated string
|
|
32
|
+
*/
|
|
33
|
+
export const alphaNumeric = (length: number): string =>
|
|
34
|
+
new Array(length)
|
|
35
|
+
.fill("")
|
|
36
|
+
.map(() => LETTERS[randint(0, LETTERS.length - 1)])
|
|
37
|
+
.join("");
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generate random name.
|
|
41
|
+
*
|
|
42
|
+
* @param length Length of paragraph, default is 2 or 3
|
|
43
|
+
* @returns Generated name
|
|
44
|
+
*/
|
|
45
|
+
export const name = (length: number = randint(2, 3)): string =>
|
|
46
|
+
paragraph(length)();
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Generate random paragraph.
|
|
50
|
+
*
|
|
51
|
+
* @param sentences Number of sentences
|
|
52
|
+
* @returns Paragraph generator
|
|
53
|
+
*/
|
|
54
|
+
export const paragraph =
|
|
55
|
+
(sentences: number = randint(2, 5)) =>
|
|
56
|
+
/**
|
|
57
|
+
* @param wordMin Minimum number of characters in a sentence
|
|
58
|
+
* @param wordMax Maximum number of characters in a sentence
|
|
59
|
+
* @returns Generated paragraph
|
|
60
|
+
*/
|
|
61
|
+
(wordMin: number = 3, wordMax: number = 7): string =>
|
|
62
|
+
new Array(sentences)
|
|
63
|
+
.fill("")
|
|
64
|
+
.map(() => alphabets(randint(wordMin, wordMax)))
|
|
65
|
+
.join(" ");
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Generate random content.
|
|
69
|
+
*
|
|
70
|
+
* @param paragraphs Number of paragraphs
|
|
71
|
+
* @returns Currying function
|
|
72
|
+
*/
|
|
73
|
+
export const content =
|
|
74
|
+
(paragraphs: number = randint(3, 8)) =>
|
|
75
|
+
/**
|
|
76
|
+
* @param sentenceMin Minimum number of sentences in a paragraph
|
|
77
|
+
* @param sentenceMax Maximum number of sentences in a paragraph
|
|
78
|
+
* @returns Currying function
|
|
79
|
+
*/
|
|
80
|
+
(sentenceMin: number = 10, sentenceMax: number = 40) =>
|
|
81
|
+
/**
|
|
82
|
+
* @param wordMin Minimum number of characters in a sentence
|
|
83
|
+
* @param wordMax Maximum number of characters in a sentence
|
|
84
|
+
* @returns Content generator
|
|
85
|
+
*/
|
|
86
|
+
(wordMin: number = 1, wordMax: number = 7): string =>
|
|
87
|
+
new Array(paragraphs)
|
|
88
|
+
.fill("")
|
|
89
|
+
.map(() =>
|
|
90
|
+
paragraph(randint(sentenceMin, sentenceMax))(wordMin, wordMax),
|
|
91
|
+
)
|
|
92
|
+
.join("\n\n");
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Generate random substring.
|
|
96
|
+
*
|
|
97
|
+
* @param content Target content
|
|
98
|
+
* @returns Random substring
|
|
99
|
+
*/
|
|
100
|
+
export const substring = (content: string): string => {
|
|
101
|
+
const first: number = randint(0, content.length - 1);
|
|
102
|
+
const last: number = randint(first + 1, content.length);
|
|
103
|
+
|
|
104
|
+
return content.substring(first, last).trim();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Generate random mobile number.
|
|
109
|
+
*
|
|
110
|
+
* @param prefix Prefix string, default is "010"
|
|
111
|
+
* @returns Random mobile number
|
|
112
|
+
* @example 0103340067
|
|
113
|
+
*/
|
|
114
|
+
export const mobile = (prefix: string = "010"): string =>
|
|
115
|
+
[
|
|
116
|
+
prefix,
|
|
117
|
+
(() => {
|
|
118
|
+
const value = randint(0, 9999);
|
|
119
|
+
return value.toString().padStart(value < 1_000 ? 3 : 4, "0");
|
|
120
|
+
})(),
|
|
121
|
+
randint(0, 9999).toString().padStart(4, "0"),
|
|
122
|
+
].join("");
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Generate random date.
|
|
126
|
+
*
|
|
127
|
+
* @param from Start date
|
|
128
|
+
* @param range Range of random milliseconds
|
|
129
|
+
* @returns Random date
|
|
130
|
+
*/
|
|
131
|
+
export const date =
|
|
132
|
+
(from: Date) =>
|
|
133
|
+
(range: number): Date =>
|
|
134
|
+
new Date(from.getTime() + randint(0, range));
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Pick random elements from an array.
|
|
138
|
+
*
|
|
139
|
+
* @param array Target array
|
|
140
|
+
* @param count Number of count to pick
|
|
141
|
+
* @returns Sampled array
|
|
142
|
+
*/
|
|
143
|
+
export const sample =
|
|
144
|
+
<T>(array: T[]) =>
|
|
145
|
+
(count: number): T[] => {
|
|
146
|
+
count = Math.min(count, array.length);
|
|
147
|
+
const indexes: Set<number> = new Set();
|
|
148
|
+
while (indexes.size < count) indexes.add(randint(0, array.length - 1));
|
|
149
|
+
return Array.from(indexes).map((index) => array[index]);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Pick random element from an array.
|
|
154
|
+
*
|
|
155
|
+
* @param array Target array
|
|
156
|
+
* @returns picked element
|
|
157
|
+
*/
|
|
158
|
+
export const pick = <T>(array: T[]): T => array[randint(0, array.length - 1)];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const randint = (min: number, max: number): number =>
|
|
162
|
+
Math.floor(Math.random() * (max - min + 1)) + min;
|