@nestia/e2e 0.1.7 → 0.1.8
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/TestValidator.d.ts +2 -2
- package/lib/TestValidator.js +54 -21
- package/lib/TestValidator.js.map +1 -1
- package/package.json +59 -56
- package/src/TestValidator.ts +51 -10
package/lib/TestValidator.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare namespace TestValidator {
|
|
|
12
12
|
* @param title Title of error message when condition is not satisfied
|
|
13
13
|
* @return Currying function
|
|
14
14
|
*/
|
|
15
|
-
const predicate: (title: string) => (
|
|
15
|
+
const predicate: (title: string) => <T extends boolean | (() => boolean) | (() => Promise<boolean>)>(condition: T) => T extends () => Promise<boolean> ? Promise<void> : void;
|
|
16
16
|
/**
|
|
17
17
|
* Test whether two values are equal.
|
|
18
18
|
*
|
|
@@ -34,7 +34,7 @@ export declare namespace TestValidator {
|
|
|
34
34
|
*
|
|
35
35
|
* @param title Title of exception because of no error exists
|
|
36
36
|
*/
|
|
37
|
-
const error: (title: string) => (task: () =>
|
|
37
|
+
const error: (title: string) => <T>(task: () => T) => T extends Promise<any> ? Promise<void> : void;
|
|
38
38
|
/**
|
|
39
39
|
* Validate index API.
|
|
40
40
|
*
|
package/lib/TestValidator.js
CHANGED
|
@@ -67,10 +67,37 @@ var TestValidator;
|
|
|
67
67
|
* @param title Title of error message when condition is not satisfied
|
|
68
68
|
* @return Currying function
|
|
69
69
|
*/
|
|
70
|
-
TestValidator.predicate = function (title) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
TestValidator.predicate = function (title) {
|
|
71
|
+
return function (condition) {
|
|
72
|
+
var message = function () {
|
|
73
|
+
return "Bug on ".concat(title, ": expected condition is not satisfied.");
|
|
74
|
+
};
|
|
75
|
+
// SCALAR
|
|
76
|
+
if (typeof condition === "boolean") {
|
|
77
|
+
if (condition !== true)
|
|
78
|
+
throw new Error(message());
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
// CLOSURE
|
|
82
|
+
var output = condition();
|
|
83
|
+
if (typeof output === "boolean") {
|
|
84
|
+
if (output !== true)
|
|
85
|
+
throw new Error(message());
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
// ASYNCHRONOUS
|
|
89
|
+
return new Promise(function (resolve, reject) {
|
|
90
|
+
output
|
|
91
|
+
.then(function (flag) {
|
|
92
|
+
if (flag === true)
|
|
93
|
+
resolve();
|
|
94
|
+
else
|
|
95
|
+
reject(message());
|
|
96
|
+
})
|
|
97
|
+
.catch(reject);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
};
|
|
74
101
|
/**
|
|
75
102
|
* Test whether two values are equal.
|
|
76
103
|
*
|
|
@@ -101,23 +128,23 @@ var TestValidator;
|
|
|
101
128
|
* @param title Title of exception because of no error exists
|
|
102
129
|
*/
|
|
103
130
|
TestValidator.error = function (title) {
|
|
104
|
-
return function (task) {
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
}
|
|
131
|
+
return function (task) {
|
|
132
|
+
var message = function () { return "Bug on ".concat(title, ": exception must be thrown."); };
|
|
133
|
+
try {
|
|
134
|
+
var output_1 = task();
|
|
135
|
+
if (is_promise(output_1))
|
|
136
|
+
return new Promise(function (resolve, reject) {
|
|
137
|
+
return output_1
|
|
138
|
+
.catch(function () { return resolve(); })
|
|
139
|
+
.then(function () { return reject(message()); });
|
|
140
|
+
});
|
|
141
|
+
else
|
|
142
|
+
throw new Error(message());
|
|
143
|
+
}
|
|
144
|
+
catch (_a) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
121
148
|
};
|
|
122
149
|
/**
|
|
123
150
|
* Validate index API.
|
|
@@ -301,4 +328,10 @@ var TestValidator;
|
|
|
301
328
|
function get_ids(entities) {
|
|
302
329
|
return entities.map(function (entity) { return entity.id; }).sort(function (x, y) { return (x < y ? -1 : 1); });
|
|
303
330
|
}
|
|
331
|
+
function is_promise(input) {
|
|
332
|
+
return (typeof input === "object" &&
|
|
333
|
+
input !== null &&
|
|
334
|
+
typeof input.then === "function" &&
|
|
335
|
+
typeof input.catch === "function");
|
|
336
|
+
}
|
|
304
337
|
//# sourceMappingURL=TestValidator.js.map
|
package/lib/TestValidator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAwC;AAExC,qDAAoD;AACpD,0DAAyD;AAEzD;;;;;;GAMG;AACH,IAAiB,aAAa,
|
|
1
|
+
{"version":3,"file":"TestValidator.js","sourceRoot":"","sources":["../src/TestValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAwC;AAExC,qDAAoD;AACpD,0DAAyD;AAEzD;;;;;;GAMG;AACH,IAAiB,aAAa,CA4P7B;AA5PD,WAAiB,aAAa;;IAC1B;;;;;OAKG;IACU,uBAAS,GAClB,UAAC,KAAa;QACd,OAAA,UACI,SAAY;YAEZ,IAAM,OAAO,GAAG;gBACZ,OAAA,iBAAU,KAAK,2CAAwC;YAAvD,CAAuD,CAAC;YAE5D,SAAS;YACT,IAAI,OAAO,SAAS,KAAK,SAAS,EAAE;gBAChC,IAAI,SAAS,KAAK,IAAI;oBAAE,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnD,OAAO,SAAgB,CAAC;aAC3B;YAED,UAAU;YACV,IAAM,MAAM,GAA+B,SAAS,EAAE,CAAC;YACv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CAAC,EA5PgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QA4P7B;AAMD,SAAS,OAAO,CAA8B,QAAkB;IAC5D,OAAO,QAAQ,CAAC,GAAG,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;AAChF,CAAC;AAED,SAAS,UAAU,CAAC,KAAU;IAC1B,OAAO,CACH,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAa,CAAC,IAAI,KAAK,UAAU;QACzC,OAAQ,KAAa,CAAC,KAAK,KAAK,UAAU,CAC7C,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,56 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@nestia/e2e",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "E2E test utilify functions",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "rimraf lib && tsc",
|
|
8
|
-
"dev": "npm run build -- --watch",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"prepare": "ts-patch install"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"@
|
|
34
|
-
"@types/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@nestia/e2e",
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "E2E test utilify functions",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "rimraf lib && tsc",
|
|
8
|
+
"dev": "npm run build -- --watch",
|
|
9
|
+
"eslint": "eslint src",
|
|
10
|
+
"prettier": "prettier --write ./src/**/*.ts",
|
|
11
|
+
"prepare": "ts-patch install",
|
|
12
|
+
"test": "node lib/test"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/samchon/nestia"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"e2e",
|
|
20
|
+
"nestia",
|
|
21
|
+
"nestjs",
|
|
22
|
+
"test",
|
|
23
|
+
"tdd",
|
|
24
|
+
"utility"
|
|
25
|
+
],
|
|
26
|
+
"author": "Jeongho Nam",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/samchon/nestia/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/samchon/nestia#readme",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
34
|
+
"@types/cli": "^0.11.21",
|
|
35
|
+
"@types/node": "^18.11.18",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.57.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.57.0",
|
|
38
|
+
"prettier": "^2.8.3",
|
|
39
|
+
"rimraf": "^4.1.2",
|
|
40
|
+
"ts-node": "^10.9.1",
|
|
41
|
+
"ts-patch": "^2.1.0",
|
|
42
|
+
"typescript": "^4.9.5",
|
|
43
|
+
"typia": "^3.6.9"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"chalk": "^4.1.2",
|
|
47
|
+
"cli": "^1.0.1",
|
|
48
|
+
"tstl": "^2.5.13"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"lib",
|
|
52
|
+
"src",
|
|
53
|
+
"!lib/test",
|
|
54
|
+
"!src/test",
|
|
55
|
+
"README.md",
|
|
56
|
+
"LICENSE",
|
|
57
|
+
"package.json"
|
|
58
|
+
]
|
|
59
|
+
}
|
package/src/TestValidator.ts
CHANGED
|
@@ -17,12 +17,37 @@ export namespace TestValidator {
|
|
|
17
17
|
* @param title Title of error message when condition is not satisfied
|
|
18
18
|
* @return Currying function
|
|
19
19
|
*/
|
|
20
|
-
export const predicate =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
export const predicate =
|
|
21
|
+
(title: string) =>
|
|
22
|
+
<T extends boolean | (() => boolean) | (() => Promise<boolean>)>(
|
|
23
|
+
condition: T,
|
|
24
|
+
): T extends () => Promise<boolean> ? Promise<void> : void => {
|
|
25
|
+
const message = () =>
|
|
26
|
+
`Bug on ${title}: expected condition is not satisfied.`;
|
|
27
|
+
|
|
28
|
+
// SCALAR
|
|
29
|
+
if (typeof condition === "boolean") {
|
|
30
|
+
if (condition !== true) throw new Error(message());
|
|
31
|
+
return undefined as any;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// CLOSURE
|
|
35
|
+
const output: boolean | Promise<boolean> = condition();
|
|
36
|
+
if (typeof output === "boolean") {
|
|
37
|
+
if (output !== true) throw new Error(message());
|
|
38
|
+
return undefined as any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ASYNCHRONOUS
|
|
42
|
+
return new Promise<void>((resolve, reject) => {
|
|
43
|
+
output
|
|
44
|
+
.then((flag) => {
|
|
45
|
+
if (flag === true) resolve();
|
|
46
|
+
else reject(message());
|
|
47
|
+
})
|
|
48
|
+
.catch(reject);
|
|
49
|
+
}) as any;
|
|
50
|
+
};
|
|
26
51
|
|
|
27
52
|
/**
|
|
28
53
|
* Test whether two values are equal.
|
|
@@ -59,13 +84,20 @@ export namespace TestValidator {
|
|
|
59
84
|
*/
|
|
60
85
|
export const error =
|
|
61
86
|
(title: string) =>
|
|
62
|
-
|
|
87
|
+
<T>(task: () => T): T extends Promise<any> ? Promise<void> : void => {
|
|
88
|
+
const message = () => `Bug on ${title}: exception must be thrown.`;
|
|
63
89
|
try {
|
|
64
|
-
|
|
90
|
+
const output: T = task();
|
|
91
|
+
if (is_promise(output))
|
|
92
|
+
return new Promise<void>((resolve, reject) =>
|
|
93
|
+
output
|
|
94
|
+
.catch(() => resolve())
|
|
95
|
+
.then(() => reject(message())),
|
|
96
|
+
) as any;
|
|
97
|
+
else throw new Error(message());
|
|
65
98
|
} catch {
|
|
66
|
-
return;
|
|
99
|
+
return undefined as any;
|
|
67
100
|
}
|
|
68
|
-
throw new Error(`Bug on ${title}: exception must be thrown.`);
|
|
69
101
|
};
|
|
70
102
|
|
|
71
103
|
/**
|
|
@@ -239,3 +271,12 @@ interface IEntity<Type extends string | number | bigint> {
|
|
|
239
271
|
function get_ids<Entity extends IEntity<any>>(entities: Entity[]): string[] {
|
|
240
272
|
return entities.map((entity) => entity.id).sort((x, y) => (x < y ? -1 : 1));
|
|
241
273
|
}
|
|
274
|
+
|
|
275
|
+
function is_promise(input: any): input is Promise<any> {
|
|
276
|
+
return (
|
|
277
|
+
typeof input === "object" &&
|
|
278
|
+
input !== null &&
|
|
279
|
+
typeof (input as any).then === "function" &&
|
|
280
|
+
typeof (input as any).catch === "function"
|
|
281
|
+
);
|
|
282
|
+
}
|