@miqro/core 1.3.11 → 1.4.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/README.md +0 -18
- package/dist/handler/app.d.ts +1 -2
- package/dist/handler/app.js +2 -3
- package/dist/handler/app.js.map +1 -1
- package/dist/handler/common/index.js.map +1 -1
- package/dist/handler/common/router-utils.js.map +1 -1
- package/dist/handler/middleware/form.js.map +1 -1
- package/dist/handler/middleware/index.js.map +1 -1
- package/dist/handler/middleware/json.js.map +1 -1
- package/dist/handler/middleware/session.js.map +1 -1
- package/dist/handler/middleware/text.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/util/cli/index.d.ts +2 -1
- package/dist/util/cli/index.js.map +1 -1
- package/dist/util/error/configfilenotfound.js.map +1 -1
- package/dist/util/error/forbiddenerror.js.map +1 -1
- package/dist/util/error/notfound.js.map +1 -1
- package/dist/util/error/notimplemented.js.map +1 -1
- package/dist/util/error/parsererror.js.map +1 -1
- package/dist/util/error/unauthorizederror.js.map +1 -1
- package/package.json +5 -4
- package/src/handler/app.ts +2 -2
- package/src/handler/common/index.ts +1 -2
- package/src/handler/common/router-utils.ts +44 -51
- package/src/handler/middleware/form.ts +1 -1
- package/src/handler/middleware/index.ts +24 -24
- package/src/handler/middleware/json.ts +1 -1
- package/src/handler/middleware/session.ts +128 -128
- package/src/handler/middleware/text.ts +1 -1
- package/src/index.ts +0 -1
- package/src/util/cli/index.ts +2 -1
- package/src/util/error/configfilenotfound.ts +1 -1
- package/src/util/error/forbiddenerror.ts +1 -1
- package/src/util/error/notfound.ts +1 -1
- package/src/util/error/notimplemented.ts +1 -1
- package/src/util/error/parsererror.ts +1 -1
- package/src/util/error/unauthorizederror.ts +1 -1
- package/src/util/parser/common.ts +1 -1
- package/src/util/parser/index.ts +0 -3
- package/src/util/request/index.ts +1 -1
- package/src/util/session/index.ts +1 -1
- package/dist/test/common/app.d.ts +0 -3
- package/dist/test/common/app.js +0 -51
- package/dist/test/common/app.js.map +0 -1
- package/dist/test/common/common.d.ts +0 -6
- package/dist/test/common/common.js +0 -15
- package/dist/test/common/common.js.map +0 -1
- package/dist/test/common/index.d.ts +0 -3
- package/dist/test/common/index.js +0 -16
- package/dist/test/common/index.js.map +0 -1
- package/dist/test/common/runner.d.ts +0 -28
- package/dist/test/common/runner.js +0 -88
- package/dist/test/common/runner.js.map +0 -1
- package/dist/test/index.d.ts +0 -1
- package/dist/test/index.js +0 -14
- package/dist/test/index.js.map +0 -1
- package/dist/test/main.d.ts +0 -1
- package/dist/test/main.js +0 -31
- package/dist/test/main.js.map +0 -1
- package/src/test/common/app.ts +0 -45
- package/src/test/common/common.ts +0 -17
- package/src/test/common/index.ts +0 -3
- package/src/test/common/runner.ts +0 -116
- package/src/test/index.ts +0 -1
- package/src/test/main.ts +0 -32
|
@@ -14,142 +14,142 @@ const DEFAULT_TOKEN_SET_COOKIE_PATH = "/";
|
|
|
14
14
|
const DEFAULT_TOKEN_SET_COOKIE_SAME_SITE = "strict";
|
|
15
15
|
|
|
16
16
|
export interface SessionHandlerOptions {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
17
|
+
authService: {
|
|
18
|
+
verify(args: { token: string; ctx: Context }): Promise<Session | null>;
|
|
19
|
+
};
|
|
20
|
+
options?: {
|
|
21
|
+
tokenLocation: "header" | "query" | "cookie";
|
|
22
|
+
tokenLocationName: string | ((ctx: Context) => Promise<string>);
|
|
23
|
+
setCookieOptions?: {
|
|
24
|
+
httpOnly: boolean;
|
|
25
|
+
secure: boolean;
|
|
26
|
+
path: string | ((ctx: Context) => Promise<string>);
|
|
27
|
+
sameSite: "lax" | "strict" | "none";
|
|
29
28
|
}
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export const SessionHandler = (config: SessionHandlerOptions): Handler<void> => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
if (!config.options) {
|
|
34
|
+
const tokenLocation = checkEnvVariables(["TOKEN_LOCATION"], [DEFAULT_TOKEN_LOCATION])[0];
|
|
35
|
+
config.options = {
|
|
36
|
+
tokenLocation: tokenLocation as any,
|
|
37
|
+
tokenLocationName: "",
|
|
38
|
+
setCookieOptions: {
|
|
39
|
+
httpOnly: true,
|
|
40
|
+
path: "/",
|
|
41
|
+
sameSite: "strict",
|
|
42
|
+
secure: true
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
switch (tokenLocation) {
|
|
46
|
+
case "header":
|
|
47
|
+
config.options.tokenLocationName = checkEnvVariables(["TOKEN_HEADER"], [DEFAULT_TOKEN_HEADER])[0];
|
|
48
|
+
break;
|
|
49
|
+
case "query":
|
|
50
|
+
config.options.tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
|
|
51
|
+
break;
|
|
52
|
+
case "cookie":
|
|
53
|
+
config.options.tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
|
|
54
|
+
const [httpOnlyS, secureS, path, sameSite] = checkEnvVariables(
|
|
55
|
+
["TOKEN_SET_COOKIE_HTTP_ONLY", "TOKEN_SET_COOKIE_SECURE", "TOKEN_SET_COOKIE_PATH", "TOKEN_SET_COOKIE_SAME_SITE"],
|
|
56
|
+
[DEFAULT_TOKEN_SET_COOKIE_HTTP_ONLY, DEFAULT_TOKEN_SET_COOKIE_SECURE, DEFAULT_TOKEN_SET_COOKIE_PATH, DEFAULT_TOKEN_SET_COOKIE_SAME_SITE]);
|
|
57
|
+
config.options.setCookieOptions = {
|
|
58
|
+
httpOnly: httpOnlyS === "true",
|
|
59
|
+
secure: secureS === "true",
|
|
60
|
+
path,
|
|
61
|
+
sameSite: sameSite as any
|
|
44
62
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
break;
|
|
49
|
-
case "query":
|
|
50
|
-
config.options.tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
|
|
51
|
-
break;
|
|
52
|
-
case "cookie":
|
|
53
|
-
config.options.tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
|
|
54
|
-
const [httpOnlyS, secureS, path, sameSite] = checkEnvVariables(
|
|
55
|
-
["TOKEN_SET_COOKIE_HTTP_ONLY", "TOKEN_SET_COOKIE_SECURE", "TOKEN_SET_COOKIE_PATH", "TOKEN_SET_COOKIE_SAME_SITE"],
|
|
56
|
-
[DEFAULT_TOKEN_SET_COOKIE_HTTP_ONLY, DEFAULT_TOKEN_SET_COOKIE_SECURE, DEFAULT_TOKEN_SET_COOKIE_PATH, DEFAULT_TOKEN_SET_COOKIE_SAME_SITE]);
|
|
57
|
-
config.options.setCookieOptions = {
|
|
58
|
-
httpOnly: httpOnlyS === "true",
|
|
59
|
-
secure: secureS === "true",
|
|
60
|
-
path,
|
|
61
|
-
sameSite: sameSite as any
|
|
62
|
-
};
|
|
63
|
-
break;
|
|
64
|
-
default:
|
|
65
|
-
throw new Error(`TOKEN_LOCATION=${tokenLocation} not supported use (header or query)`);
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
config.options = parse("options", config.options as any, [
|
|
69
|
-
{ name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
|
|
70
|
-
{ name: "tokenLocationName", required: true, type: "any" },
|
|
71
|
-
{
|
|
72
|
-
name: "setCookieOptions", required: false, type: "nested", defaultValue: {
|
|
73
|
-
httpOnly: DEFAULT_TOKEN_SET_COOKIE_HTTP_ONLY === "true",
|
|
74
|
-
secure: DEFAULT_TOKEN_SET_COOKIE_SECURE === "true",
|
|
75
|
-
path: DEFAULT_TOKEN_SET_COOKIE_PATH,
|
|
76
|
-
sameSite: DEFAULT_TOKEN_SET_COOKIE_SAME_SITE,
|
|
77
|
-
}, nestedOptions: {
|
|
78
|
-
mode: "no_extra",
|
|
79
|
-
options: [
|
|
80
|
-
{ name: "httpOnly", required: true, type: "boolean" },
|
|
81
|
-
{ name: "secure", required: true, type: "boolean" },
|
|
82
|
-
{ name: "path", required: true, type: "any" },
|
|
83
|
-
{ name: "sameSite", required: true, type: "enum", enumValues: ["lax", "strict", "none"] }
|
|
84
|
-
]
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
], "no_extra") as any;
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
throw new Error(`TOKEN_LOCATION=${tokenLocation} not supported use (header or query)`);
|
|
88
66
|
}
|
|
67
|
+
} else {
|
|
68
|
+
config.options = parse("options", config.options as any, [
|
|
69
|
+
{ name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
|
|
70
|
+
{ name: "tokenLocationName", required: true, type: "any" },
|
|
71
|
+
{
|
|
72
|
+
name: "setCookieOptions", required: false, type: "nested", defaultValue: {
|
|
73
|
+
httpOnly: DEFAULT_TOKEN_SET_COOKIE_HTTP_ONLY === "true",
|
|
74
|
+
secure: DEFAULT_TOKEN_SET_COOKIE_SECURE === "true",
|
|
75
|
+
path: DEFAULT_TOKEN_SET_COOKIE_PATH,
|
|
76
|
+
sameSite: DEFAULT_TOKEN_SET_COOKIE_SAME_SITE,
|
|
77
|
+
}, nestedOptions: {
|
|
78
|
+
mode: "no_extra",
|
|
79
|
+
options: [
|
|
80
|
+
{ name: "httpOnly", required: true, type: "boolean" },
|
|
81
|
+
{ name: "secure", required: true, type: "boolean" },
|
|
82
|
+
{ name: "path", required: true, type: "any" },
|
|
83
|
+
{ name: "sameSite", required: true, type: "enum", enumValues: ["lax", "strict", "none"] }
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
], "no_extra") as any;
|
|
88
|
+
}
|
|
89
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
|
-
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
} catch (e: any) {
|
|
146
|
-
if (e.message && e.message === "NO TOKEN") {
|
|
147
|
-
throw e;
|
|
148
|
-
} else {
|
|
149
|
-
throw new UnAuthorizedError();
|
|
150
|
-
}
|
|
90
|
+
if (!config.authService) {
|
|
91
|
+
throw new Error("authService must be provided!");
|
|
92
|
+
}
|
|
93
|
+
if (!config.options || !config.options.setCookieOptions) {
|
|
94
|
+
throw new Error("config.options not populated!");
|
|
95
|
+
}
|
|
96
|
+
const tokenLocation = config.options.tokenLocation;
|
|
97
|
+
const tokenLocationName = config.options.tokenLocationName;
|
|
98
|
+
const setCookieOptions = config.options.setCookieOptions;
|
|
99
|
+
return async (ctx: Context): Promise<void> => {
|
|
100
|
+
try {
|
|
101
|
+
const tlN = typeof tokenLocationName === "string" ? tokenLocationName : await tokenLocationName(ctx);
|
|
102
|
+
let token = null;
|
|
103
|
+
switch (tokenLocation) {
|
|
104
|
+
case "header":
|
|
105
|
+
token = ctx.headers[(tlN).toLowerCase()] as string;
|
|
106
|
+
break;
|
|
107
|
+
case "query":
|
|
108
|
+
token = ctx.query[tlN] as string;
|
|
109
|
+
break;
|
|
110
|
+
case "cookie":
|
|
111
|
+
token = ctx.cookies[tlN] ? ctx.cookies[tlN] : undefined;
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`TOKEN_LOCATION=${tokenLocation} not supported use (header, query or cookie)`);
|
|
115
|
+
}
|
|
116
|
+
if (!token) {
|
|
117
|
+
ctx.logger.warn("No token provided!");
|
|
118
|
+
throw new ForbiddenError("NO TOKEN");
|
|
119
|
+
} else {
|
|
120
|
+
const session = await config.authService.verify({ token, ctx });
|
|
121
|
+
if (!session) {
|
|
122
|
+
ctx.logger.warn("fail to authenticate token [%s]!", token);
|
|
123
|
+
throw new UnAuthorizedError();
|
|
124
|
+
} else {
|
|
125
|
+
if (tokenLocation === "cookie" && session.token !== token) {
|
|
126
|
+
const newTokenCookie = String(session.token ? session.token : token);
|
|
127
|
+
const cookiePath = typeof setCookieOptions.path === "string" ? setCookieOptions.path : await setCookieOptions.path(ctx);
|
|
128
|
+
ctx.setCookie(tlN, newTokenCookie, session.expires instanceof Date ? {
|
|
129
|
+
httpOnly: setCookieOptions.httpOnly,
|
|
130
|
+
secure: setCookieOptions.secure,
|
|
131
|
+
path: cookiePath,
|
|
132
|
+
sameSite: setCookieOptions.sameSite,
|
|
133
|
+
expires: session.expires
|
|
134
|
+
} : {
|
|
135
|
+
httpOnly: setCookieOptions.httpOnly,
|
|
136
|
+
path: cookiePath,
|
|
137
|
+
secure: setCookieOptions.secure,
|
|
138
|
+
sameSite: setCookieOptions.sameSite
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
ctx.session = session;
|
|
142
|
+
ctx.logger.debug("authenticated!");
|
|
151
143
|
}
|
|
152
|
-
|
|
144
|
+
}
|
|
145
|
+
} catch (e: any) {
|
|
146
|
+
if (e.message && e.message === "NO TOKEN") {
|
|
147
|
+
throw e;
|
|
148
|
+
} else {
|
|
149
|
+
throw new UnAuthorizedError();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
|
|
@@ -25,7 +25,7 @@ export const TextParser = (options?: {
|
|
|
25
25
|
return async (ctx: Context): Promise<void> => {
|
|
26
26
|
try {
|
|
27
27
|
const isType = ctx.body === undefined && ctx.headers["content-type"] ? ctx.headers["content-type"].toLocaleLowerCase().indexOf(type.toLocaleLowerCase()) !== -1 : false;
|
|
28
|
-
if(isType && !ctx.buffer) {
|
|
28
|
+
if (isType && !ctx.buffer) {
|
|
29
29
|
await readBuffer(ctx);
|
|
30
30
|
}
|
|
31
31
|
if (isType && ctx.buffer && ctx.buffer.length <= limit) {
|
package/src/index.ts
CHANGED
package/src/util/cli/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SimpleMap } from "../parser/common";
|
|
2
2
|
import { Logger } from "../logger";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
type Callback<T = any> = (...args: any[]) => T;
|
|
4
5
|
|
|
5
6
|
// noinspection SpellCheckingInspection
|
|
6
7
|
const routeCMDModule = async (cmdArg: string | undefined, cmds: CMDMapType, logger: Logger | Console, exit = true): Promise<void> => {
|
package/src/util/parser/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./common";
|
|
2
|
-
export * from "./service";
|
|
2
|
+
export * from "./service";
|
package/dist/test/common/app.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TestHelper = void 0;
|
|
4
|
-
const request_1 = require("../../util/request");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const http_1 = require("http");
|
|
7
|
-
const TestHelper = async (app, options, cb) => {
|
|
8
|
-
const unixSocket = `/tmp/socket.test.helper${Date.now()}`;
|
|
9
|
-
if ((0, fs_1.existsSync)(unixSocket)) {
|
|
10
|
-
(0, fs_1.unlinkSync)(unixSocket);
|
|
11
|
-
}
|
|
12
|
-
const server = (0, http_1.createServer)(app.listener);
|
|
13
|
-
return new Promise((resolve, reject) => {
|
|
14
|
-
server.listen(unixSocket, () => {
|
|
15
|
-
(0, request_1.request)({
|
|
16
|
-
disableThrow: true,
|
|
17
|
-
...options,
|
|
18
|
-
socketPath: unixSocket
|
|
19
|
-
}).then((response) => {
|
|
20
|
-
server.close(() => {
|
|
21
|
-
if (cb) {
|
|
22
|
-
try {
|
|
23
|
-
cb(response);
|
|
24
|
-
}
|
|
25
|
-
catch (ee) {
|
|
26
|
-
reject(ee);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
resolve(response);
|
|
30
|
-
});
|
|
31
|
-
}).catch((e) => {
|
|
32
|
-
server.close(() => {
|
|
33
|
-
if (cb) {
|
|
34
|
-
try {
|
|
35
|
-
cb(e);
|
|
36
|
-
}
|
|
37
|
-
catch (ee) {
|
|
38
|
-
reject(ee);
|
|
39
|
-
}
|
|
40
|
-
resolve(undefined);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
reject(e);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
exports.TestHelper = TestHelper;
|
|
51
|
-
//# sourceMappingURL=app.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/test/common/app.ts"],"names":[],"mappings":";;;AAAA,gDAA8E;AAE9E,2BAA4C;AAC5C,+BAAoC;AAE7B,MAAM,UAAU,GAAG,KAAK,EAAE,GAAQ,EAAE,OAAuB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C,CAAC;AACL,CAAC,CAAA;AAvCY,QAAA,UAAU,cAuCtB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fake = void 0;
|
|
4
|
-
const fake = (cb) => {
|
|
5
|
-
const ret = (...args) => {
|
|
6
|
-
ret.callCount++;
|
|
7
|
-
ret.callArgs.push(args);
|
|
8
|
-
return cb(...args);
|
|
9
|
-
};
|
|
10
|
-
ret.callCount = 0;
|
|
11
|
-
ret.callArgs = [];
|
|
12
|
-
return ret;
|
|
13
|
-
};
|
|
14
|
-
exports.fake = fake;
|
|
15
|
-
//# sourceMappingURL=common.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/test/common/common.ts"],"names":[],"mappings":";;;AAOO,MAAM,IAAI,GAAG,CAAC,EAAY,EAAgB,EAAE;IACjD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;QAC7B,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;IACF,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC;IAClB,GAAG,CAAC,QAAQ,GAAG,EAAS,CAAC;IACzB,OAAO,GAAG,CAAC;AACb,CAAC,CAAA;AATY,QAAA,IAAI,QAShB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./common"), exports);
|
|
14
|
-
__exportStar(require("./app"), exports);
|
|
15
|
-
__exportStar(require("./runner"), exports);
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,wCAAsB;AACtB,2CAAyB"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Console } from "console";
|
|
2
|
-
import { Logger } from "../../util";
|
|
3
|
-
export declare type TestFunction = () => void | Promise<void>;
|
|
4
|
-
export declare const getTestCount: () => number;
|
|
5
|
-
export declare const it: (title: string, impl: TestFunction, options?: {
|
|
6
|
-
category?: string | undefined;
|
|
7
|
-
timeout?: number | undefined;
|
|
8
|
-
before?: TestFunction | undefined;
|
|
9
|
-
after?: TestFunction | undefined;
|
|
10
|
-
} | undefined, logger?: Logger | Console) => void;
|
|
11
|
-
export declare const runTests: (title?: string | string[] | undefined, logger?: Logger | Console) => Promise<{
|
|
12
|
-
passed: number;
|
|
13
|
-
total: number;
|
|
14
|
-
ignored: number;
|
|
15
|
-
failed: {
|
|
16
|
-
error: any;
|
|
17
|
-
fullName: string;
|
|
18
|
-
}[];
|
|
19
|
-
}>;
|
|
20
|
-
export declare const runTestModules: (modules: string[], title?: string | string[] | undefined, logger?: Logger | Console) => Promise<{
|
|
21
|
-
passed: number;
|
|
22
|
-
total: number;
|
|
23
|
-
ignored: number;
|
|
24
|
-
failed: {
|
|
25
|
-
error: any;
|
|
26
|
-
fullName: string;
|
|
27
|
-
}[];
|
|
28
|
-
}>;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runTestModules = exports.runTests = exports.it = exports.getTestCount = void 0;
|
|
4
|
-
const console_1 = require("console");
|
|
5
|
-
const util_1 = require("util");
|
|
6
|
-
const DEFAULT_TIMEOUT = 2000;
|
|
7
|
-
const tests = [];
|
|
8
|
-
const getTestCount = () => tests.length;
|
|
9
|
-
exports.getTestCount = getTestCount;
|
|
10
|
-
const it = (title, impl, options, logger = new console_1.Console(process.stdout)) => {
|
|
11
|
-
const category = options && options.category ? options.category : undefined;
|
|
12
|
-
const fullName = `${category ? `${category} [` : ""}${title}${category ? "]" : ""}`;
|
|
13
|
-
tests.push({
|
|
14
|
-
run: () => new Promise((resolve, reject) => {
|
|
15
|
-
const timeoutMS = options && options.timeout ? options.timeout : DEFAULT_TIMEOUT;
|
|
16
|
-
const timeout = setTimeout(() => {
|
|
17
|
-
reject(new Error((0, util_1.format)("%s failed\x1b[31m\n%s timeout %o\x1b", fullName, fullName, timeoutMS)));
|
|
18
|
-
}, timeoutMS);
|
|
19
|
-
try {
|
|
20
|
-
(async () => {
|
|
21
|
-
if (options && options.before) {
|
|
22
|
-
await options.before();
|
|
23
|
-
}
|
|
24
|
-
const startMS = Date.now();
|
|
25
|
-
await impl();
|
|
26
|
-
const took = Date.now() - startMS;
|
|
27
|
-
if (options && options.after) {
|
|
28
|
-
await options.after();
|
|
29
|
-
}
|
|
30
|
-
return took;
|
|
31
|
-
})().then((took) => {
|
|
32
|
-
clearTimeout(timeout);
|
|
33
|
-
logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m", fullName, took);
|
|
34
|
-
resolve();
|
|
35
|
-
}).catch(e => {
|
|
36
|
-
clearTimeout(timeout);
|
|
37
|
-
reject(new Error((0, util_1.format)("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
clearTimeout(timeout);
|
|
42
|
-
reject(new Error((0, util_1.format)("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
43
|
-
}
|
|
44
|
-
}), title,
|
|
45
|
-
category,
|
|
46
|
-
fullName
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
exports.it = it;
|
|
50
|
-
const runTests = async (title, logger = new console_1.Console(process.stdout)) => {
|
|
51
|
-
const titles = title ? title instanceof Array ? title : [title] : [undefined];
|
|
52
|
-
const ret = {
|
|
53
|
-
total: tests.length,
|
|
54
|
-
ignored: 0,
|
|
55
|
-
passed: 0,
|
|
56
|
-
failed: []
|
|
57
|
-
};
|
|
58
|
-
for (const test of tests) {
|
|
59
|
-
for (const title of titles) {
|
|
60
|
-
if (title && test.fullName.indexOf(title) !== -1 || !title) {
|
|
61
|
-
try {
|
|
62
|
-
await test.run();
|
|
63
|
-
ret.passed++;
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
logger.error("\x1b[31m%s\x1b[0m", e);
|
|
67
|
-
ret.failed.push({
|
|
68
|
-
error: e,
|
|
69
|
-
fullName: test.fullName
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
ret.ignored++;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return ret;
|
|
79
|
-
};
|
|
80
|
-
exports.runTests = runTests;
|
|
81
|
-
const runTestModules = async (modules, title, logger = new console_1.Console(process.stdout)) => {
|
|
82
|
-
for (const path of modules) {
|
|
83
|
-
require(path);
|
|
84
|
-
}
|
|
85
|
-
return await (0, exports.runTests)(title, logger);
|
|
86
|
-
};
|
|
87
|
-
exports.runTestModules = runTestModules;
|
|
88
|
-
//# sourceMappingURL=runner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/test/common/runner.ts"],"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index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./common";
|
package/dist/test/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./common"), exports);
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
package/dist/test/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB"}
|
package/dist/test/main.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|