@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
package/dist/test/main.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const path_1 = require("path");
|
|
4
|
-
const util_1 = require("../util");
|
|
5
|
-
const common_1 = require("./common");
|
|
6
|
-
const startMS = Date.now();
|
|
7
|
-
const args = util_1.CLIUtil.extractFlags(process.argv.slice(2));
|
|
8
|
-
const name = args.flags.n ? args.flags.n : "all";
|
|
9
|
-
const logger = console;
|
|
10
|
-
const modules = args.cmds;
|
|
11
|
-
(0, common_1.runTestModules)(modules.map(m => (0, path_1.resolve)(process.cwd(), m)), typeof name === "string" && name.toLowerCase() === "all" ? undefined : name, console).then((ret) => {
|
|
12
|
-
const took = Date.now() - startMS;
|
|
13
|
-
logger.log("");
|
|
14
|
-
logger.log("");
|
|
15
|
-
logger.log(ret.passed + " tests pased");
|
|
16
|
-
logger.log(ret.failed.length + " failed");
|
|
17
|
-
logger.log("took " + took + "ms");
|
|
18
|
-
logger.log("");
|
|
19
|
-
logger.log("");
|
|
20
|
-
if (ret.failed.length > 0) {
|
|
21
|
-
ret.failed.forEach(e => {
|
|
22
|
-
logger.error("\x1b[31m%s\x1b[0m", e.fullName);
|
|
23
|
-
logger.error("\x1b[31m%s\x1b[0m", e.error);
|
|
24
|
-
});
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
}).catch(e => {
|
|
28
|
-
logger.error(e);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
});
|
|
31
|
-
//# sourceMappingURL=main.js.map
|
package/dist/test/main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/test/main.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,kCAA6C;AAC7C,qCAA0C;AAE1C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE3B,MAAM,IAAI,GAAG,cAAO,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACzD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAEjD,MAAM,MAAM,GAAG,OAAO,CAAC;AAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;AAC1B,IAAA,uBAAc,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IAC7J,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC;IAClC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,cAAc,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC1C,MAAM,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC;IAClC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACf,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACzB,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;YACrB,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC;YAC9C,MAAM,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;AACH,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACX,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAChB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/src/test/common/app.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { request, RequestOptions, RequestResponse } from "../../util/request";
|
|
2
|
-
import { App } from "../../handler/app";
|
|
3
|
-
import { existsSync, unlinkSync } from "fs";
|
|
4
|
-
import { createServer } from "http";
|
|
5
|
-
|
|
6
|
-
export const TestHelper = async (app: App, options: RequestOptions, cb?: (response: RequestResponse) => void): Promise<RequestResponse> => {
|
|
7
|
-
const unixSocket = `/tmp/socket.test.helper${Date.now()}`;
|
|
8
|
-
if (existsSync(unixSocket)) {
|
|
9
|
-
unlinkSync(unixSocket);
|
|
10
|
-
}
|
|
11
|
-
const server = createServer(app.listener);
|
|
12
|
-
return new Promise<RequestResponse>((resolve, reject) => {
|
|
13
|
-
server.listen(unixSocket, () => {
|
|
14
|
-
request({
|
|
15
|
-
disableThrow: true,
|
|
16
|
-
...options,
|
|
17
|
-
socketPath: unixSocket
|
|
18
|
-
}).then((response) => {
|
|
19
|
-
server.close(() => {
|
|
20
|
-
if (cb) {
|
|
21
|
-
try {
|
|
22
|
-
cb(response);
|
|
23
|
-
} catch (ee) {
|
|
24
|
-
reject(ee);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
resolve(response);
|
|
28
|
-
});
|
|
29
|
-
}).catch((e: any) => {
|
|
30
|
-
server.close(() => {
|
|
31
|
-
if (cb) {
|
|
32
|
-
try {
|
|
33
|
-
cb(e as any);
|
|
34
|
-
} catch (ee) {
|
|
35
|
-
reject(ee);
|
|
36
|
-
}
|
|
37
|
-
resolve(undefined as any);
|
|
38
|
-
} else {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type Callback<T = any> = (...args: any[]) => T;
|
|
2
|
-
|
|
3
|
-
export interface FakeCallback<T = any> extends Callback<T> {
|
|
4
|
-
callCount: number;
|
|
5
|
-
callArgs: T[];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const fake = (cb: Callback): FakeCallback => {
|
|
9
|
-
const ret = (...args: any[]) => {
|
|
10
|
-
ret.callCount++;
|
|
11
|
-
ret.callArgs.push(args);
|
|
12
|
-
return cb(...args);
|
|
13
|
-
};
|
|
14
|
-
ret.callCount = 0;
|
|
15
|
-
ret.callArgs = [] as any;
|
|
16
|
-
return ret;
|
|
17
|
-
}
|
package/src/test/common/index.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Console, count } from "console";
|
|
2
|
-
import { format } from "util";
|
|
3
|
-
import { Logger } from "../../util";
|
|
4
|
-
|
|
5
|
-
export type TestFunction = () => void | Promise<void>;
|
|
6
|
-
const DEFAULT_TIMEOUT = 2000;
|
|
7
|
-
|
|
8
|
-
interface Test { run: TestFunction; title: string; category?: string; fullName: string; }
|
|
9
|
-
|
|
10
|
-
const tests: Test[] = [];
|
|
11
|
-
|
|
12
|
-
export const getTestCount = () => tests.length;
|
|
13
|
-
|
|
14
|
-
export const it = (title: string, impl: TestFunction, options?: {
|
|
15
|
-
category?: string;
|
|
16
|
-
timeout?: number;
|
|
17
|
-
before?: TestFunction;
|
|
18
|
-
after?: TestFunction;
|
|
19
|
-
}, logger: Logger | Console = new Console(process.stdout)): void => {
|
|
20
|
-
const category = options && options.category ? options.category : undefined;
|
|
21
|
-
const fullName = `${category ? `${category} [` : ""}${title}${category ? "]" : ""}`;
|
|
22
|
-
tests.push({
|
|
23
|
-
run: () => new Promise((resolve, reject) => {
|
|
24
|
-
const timeoutMS = options && options.timeout ? options.timeout : DEFAULT_TIMEOUT;
|
|
25
|
-
const timeout = setTimeout(() => {
|
|
26
|
-
reject(new Error(format("%s failed\x1b[31m\n%s timeout %o\x1b", fullName, fullName, timeoutMS)));
|
|
27
|
-
}, timeoutMS);
|
|
28
|
-
try {
|
|
29
|
-
(async () => {
|
|
30
|
-
if (options && options.before) {
|
|
31
|
-
await options.before();
|
|
32
|
-
}
|
|
33
|
-
const startMS = Date.now();
|
|
34
|
-
await impl();
|
|
35
|
-
const took = Date.now() - startMS;
|
|
36
|
-
if (options && options.after) {
|
|
37
|
-
await options.after();
|
|
38
|
-
}
|
|
39
|
-
return took;
|
|
40
|
-
})().then((took) => {
|
|
41
|
-
clearTimeout(timeout);
|
|
42
|
-
logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m", fullName, took);
|
|
43
|
-
resolve();
|
|
44
|
-
}).catch(e => {
|
|
45
|
-
clearTimeout(timeout);
|
|
46
|
-
reject(new Error(format("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
47
|
-
});
|
|
48
|
-
} catch (e) {
|
|
49
|
-
clearTimeout(timeout);
|
|
50
|
-
reject(new Error(format("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
51
|
-
}
|
|
52
|
-
}), title,
|
|
53
|
-
category,
|
|
54
|
-
fullName
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const runTests = async (title?: string | string[], logger: Logger | Console = new Console(process.stdout)): Promise<{
|
|
59
|
-
passed: number;
|
|
60
|
-
total: number;
|
|
61
|
-
ignored: number;
|
|
62
|
-
failed: {
|
|
63
|
-
error: any;
|
|
64
|
-
fullName: string;
|
|
65
|
-
}[];
|
|
66
|
-
}> => {
|
|
67
|
-
const titles = title ? title instanceof Array ? title : [title] : [undefined];
|
|
68
|
-
const ret: {
|
|
69
|
-
passed: number;
|
|
70
|
-
total: number;
|
|
71
|
-
ignored: number;
|
|
72
|
-
failed: {
|
|
73
|
-
error: any;
|
|
74
|
-
fullName: string;
|
|
75
|
-
}[];
|
|
76
|
-
} = {
|
|
77
|
-
total: tests.length,
|
|
78
|
-
ignored: 0,
|
|
79
|
-
passed: 0,
|
|
80
|
-
failed: []
|
|
81
|
-
};
|
|
82
|
-
for (const test of tests) {
|
|
83
|
-
for (const title of titles) {
|
|
84
|
-
if (title && test.fullName.indexOf(title) !== -1 || !title) {
|
|
85
|
-
try {
|
|
86
|
-
await test.run();
|
|
87
|
-
ret.passed++;
|
|
88
|
-
} catch (e) {
|
|
89
|
-
logger.error("\x1b[31m%s\x1b[0m", e);
|
|
90
|
-
ret.failed.push({
|
|
91
|
-
error: e,
|
|
92
|
-
fullName: test.fullName
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
ret.ignored++;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return ret;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const runTestModules = async (modules: string[], title?: string | string[], logger: Logger | Console = new Console(process.stdout)): Promise<{
|
|
104
|
-
passed: number;
|
|
105
|
-
total: number;
|
|
106
|
-
ignored: number;
|
|
107
|
-
failed: {
|
|
108
|
-
error: any;
|
|
109
|
-
fullName: string;
|
|
110
|
-
}[];
|
|
111
|
-
}> => {
|
|
112
|
-
for (const path of modules) {
|
|
113
|
-
require(path);
|
|
114
|
-
}
|
|
115
|
-
return await runTests(title, logger);
|
|
116
|
-
}
|
package/src/test/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./common";
|
package/src/test/main.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
2
|
-
import { CLIUtil, getLogger } from "../util";
|
|
3
|
-
import { runTestModules } from "./common";
|
|
4
|
-
|
|
5
|
-
const startMS = Date.now();
|
|
6
|
-
|
|
7
|
-
const args = CLIUtil.extractFlags(process.argv.slice(2));
|
|
8
|
-
const name = args.flags.n ? args.flags.n : "all";
|
|
9
|
-
|
|
10
|
-
const logger = console;
|
|
11
|
-
|
|
12
|
-
const modules = args.cmds;
|
|
13
|
-
runTestModules(modules.map(m => resolve(process.cwd(), m)), typeof name === "string" && name.toLowerCase() === "all" ? undefined : name, console).then((ret) => {
|
|
14
|
-
const took = Date.now() - startMS;
|
|
15
|
-
logger.log("");
|
|
16
|
-
logger.log("");
|
|
17
|
-
logger.log(ret.passed + " tests pased");
|
|
18
|
-
logger.log(ret.failed.length + " failed");
|
|
19
|
-
logger.log("took " + took + "ms");
|
|
20
|
-
logger.log("");
|
|
21
|
-
logger.log("");
|
|
22
|
-
if (ret.failed.length > 0) {
|
|
23
|
-
ret.failed.forEach(e => {
|
|
24
|
-
logger.error("\x1b[31m%s\x1b[0m", e.fullName);
|
|
25
|
-
logger.error("\x1b[31m%s\x1b[0m", e.error);
|
|
26
|
-
});
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
}).catch(e => {
|
|
30
|
-
logger.error(e);
|
|
31
|
-
process.exit(1);
|
|
32
|
-
});
|