@miqro/core 1.3.8 → 1.3.9
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/dist/test/common/runner.d.ts +18 -3
- package/dist/test/common/runner.js +30 -34
- package/dist/test/common/runner.js.map +1 -1
- package/dist/test/main.js +21 -9
- package/dist/test/main.js.map +1 -1
- package/dist/util/cli/index.d.ts +4 -0
- package/dist/util/cli/index.js +26 -0
- package/dist/util/cli/index.js.map +1 -1
- package/dist/util/logger/formatter.js +1 -1
- package/dist/util/logger/formatter.js.map +1 -1
- package/package.json +4 -3
- package/src/test/common/runner.ts +54 -35
- package/src/test/main.ts +25 -10
- package/src/util/cli/index.ts +23 -0
- package/src/util/logger/formatter.ts +1 -1
- package/test.md +0 -0
|
@@ -8,6 +8,21 @@ export declare const it: (title: string, impl: TestFunction, options?: {
|
|
|
8
8
|
before?: TestFunction | undefined;
|
|
9
9
|
after?: TestFunction | undefined;
|
|
10
10
|
} | undefined, logger?: Logger | Console) => void;
|
|
11
|
-
export declare const runTests: (title?: string | string[] | undefined, logger?: Logger | Console) => Promise<
|
|
12
|
-
|
|
13
|
-
|
|
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,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.runTestModules = exports.runTests = exports.it = exports.getTestCount = void 0;
|
|
4
4
|
const console_1 = require("console");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
const path_1 = require("path");
|
|
7
5
|
const util_1 = require("util");
|
|
8
6
|
const DEFAULT_TIMEOUT = 2000;
|
|
9
7
|
const tests = [];
|
|
@@ -16,7 +14,7 @@ const it = (title, impl, options, logger = new console_1.Console(process.stdout)
|
|
|
16
14
|
run: () => new Promise((resolve, reject) => {
|
|
17
15
|
const timeoutMS = options && options.timeout ? options.timeout : DEFAULT_TIMEOUT;
|
|
18
16
|
const timeout = setTimeout(() => {
|
|
19
|
-
reject(new Error((0, util_1.format)("
|
|
17
|
+
reject(new Error((0, util_1.format)("%s failed\x1b[31m\n%s timeout %o\x1b", fullName, fullName, timeoutMS)));
|
|
20
18
|
}, timeoutMS);
|
|
21
19
|
try {
|
|
22
20
|
(async () => {
|
|
@@ -32,16 +30,16 @@ const it = (title, impl, options, logger = new console_1.Console(process.stdout)
|
|
|
32
30
|
return took;
|
|
33
31
|
})().then((took) => {
|
|
34
32
|
clearTimeout(timeout);
|
|
35
|
-
logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m
|
|
33
|
+
logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m", fullName, took);
|
|
36
34
|
resolve();
|
|
37
35
|
}).catch(e => {
|
|
38
36
|
clearTimeout(timeout);
|
|
39
|
-
reject(new Error((0, util_1.format)("
|
|
37
|
+
reject(new Error((0, util_1.format)("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
catch (e) {
|
|
43
41
|
clearTimeout(timeout);
|
|
44
|
-
reject(new Error((0, util_1.format)("
|
|
42
|
+
reject(new Error((0, util_1.format)("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
45
43
|
}
|
|
46
44
|
}), title,
|
|
47
45
|
category,
|
|
@@ -50,43 +48,41 @@ const it = (title, impl, options, logger = new console_1.Console(process.stdout)
|
|
|
50
48
|
};
|
|
51
49
|
exports.it = it;
|
|
52
50
|
const runTests = async (title, logger = new console_1.Console(process.stdout)) => {
|
|
53
|
-
const titles = title ? title instanceof Array ? title : [title] : undefined;
|
|
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
|
+
};
|
|
54
58
|
for (const test of tests) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
}
|
|
58
72
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
process.exit(1);
|
|
73
|
+
else {
|
|
74
|
+
ret.ignored++;
|
|
62
75
|
}
|
|
63
76
|
}
|
|
64
77
|
}
|
|
78
|
+
return ret;
|
|
65
79
|
};
|
|
66
80
|
exports.runTests = runTests;
|
|
67
|
-
const runTestModules = async (modules, title) => {
|
|
81
|
+
const runTestModules = async (modules, title, logger = new console_1.Console(process.stdout)) => {
|
|
68
82
|
for (const path of modules) {
|
|
69
83
|
require(path);
|
|
70
84
|
}
|
|
71
|
-
await (0, exports.runTests)(title);
|
|
85
|
+
return await (0, exports.runTests)(title, logger);
|
|
72
86
|
};
|
|
73
87
|
exports.runTestModules = runTestModules;
|
|
74
|
-
const runTestDir = async (dirs, title, exts = ["test.js"]) => {
|
|
75
|
-
for (const dir of dirs) {
|
|
76
|
-
const files = (0, fs_1.readdirSync)((0, path_1.resolve)(process.cwd(), dir));
|
|
77
|
-
for (const f of files) {
|
|
78
|
-
const path = (0, path_1.resolve)(dir, f);
|
|
79
|
-
if (!(0, fs_1.lstatSync)(path).isDirectory()) {
|
|
80
|
-
for (const ext of exts) {
|
|
81
|
-
const name = (0, path_1.basename)(f);
|
|
82
|
-
if (name.indexOf(ext) === name.length - ext.length) {
|
|
83
|
-
require(path);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
await (0, exports.runTests)(title);
|
|
90
|
-
};
|
|
91
|
-
exports.runTestDir = runTestDir;
|
|
92
88
|
//# sourceMappingURL=runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/test/common/runner.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/test/common/runner.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,+BAA8B;AAI9B,MAAM,eAAe,GAAG,IAAI,CAAC;AAI7B,MAAM,KAAK,GAAW,EAAE,CAAC;AAElB,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;AAAlC,QAAA,YAAY,gBAAsB;AAExC,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,IAAkB,EAAE,OAKrD,EAAE,SAA2B,IAAI,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAQ,EAAE;IACjE,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5E,MAAM,QAAQ,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC,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AmB,EAAE,CAAC,CAAC,CAAC;oBACrC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;wBACd,KAAK,EAAE,CAAC;wBACR,QAAQ,EAAE,IAAI,CAAC,QAAQ;qBACxB,CAAC,CAAA;iBACH;aACF;iBAAM;gBACL,GAAG,CAAC,OAAO,EAAE,CAAC;aACf;SACF;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AA3CW,QAAA,QAAQ,YA2CnB;AAEK,MAAM,cAAc,GAAG,KAAK,EAAE,OAAiB,EAAE,KAAyB,EAAE,SAA2B,IAAI,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAQtI,EAAE;IACH,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE;QAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IACD,OAAO,MAAM,IAAA,gBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAA;AAbY,QAAA,cAAc,kBAa1B"}
|
package/dist/test/main.js
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path_1 = require("path");
|
|
4
|
+
const util_1 = require("../util");
|
|
4
5
|
const common_1 = require("./common");
|
|
5
6
|
const startMS = Date.now();
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
(0, common_1.runTestModules)(modules.map(m => (0, path_1.resolve)(process.cwd(), m)), name.toLowerCase() !== "all" ? name : undefined).then(() => {
|
|
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
12
|
const took = Date.now() - startMS;
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
}
|
|
15
27
|
}).catch(e => {
|
|
16
|
-
|
|
28
|
+
logger.error(e);
|
|
17
29
|
process.exit(1);
|
|
18
30
|
});
|
|
19
31
|
//# sourceMappingURL=main.js.map
|
package/dist/test/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/test/main.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,
|
|
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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OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/util/cli/index.d.ts
CHANGED
|
@@ -8,5 +8,9 @@ export declare type CMDMapType = SimpleMap<{
|
|
|
8
8
|
section?: string;
|
|
9
9
|
}>;
|
|
10
10
|
export declare abstract class CLIUtil {
|
|
11
|
+
static extractFlags(args: string[]): {
|
|
12
|
+
flags: SimpleMap<string | string[]>;
|
|
13
|
+
cmds: string[];
|
|
14
|
+
};
|
|
11
15
|
static cliFlow(cmds: CMDMapType, usage: string, logger: Logger | Console, cmdArg?: string, exit?: boolean): void;
|
|
12
16
|
}
|
package/dist/util/cli/index.js
CHANGED
|
@@ -26,6 +26,32 @@ const routeCMDModule = async (cmdArg, cmds, logger, exit = true) => {
|
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
28
|
class CLIUtil {
|
|
29
|
+
static extractFlags(args) {
|
|
30
|
+
const flags = {};
|
|
31
|
+
const cmds = [];
|
|
32
|
+
for (let i = 0; i < args.length; i++) {
|
|
33
|
+
const arg = args[i];
|
|
34
|
+
if (arg.indexOf("-") === 0) {
|
|
35
|
+
const argName = arg.substring(arg.indexOf("--") === 0 ? 2 : 1);
|
|
36
|
+
const argValue = args.length > i + 1 && args[i + 1] && args[i + 1].indexOf("-") != 0 ? args[i + 1] : "";
|
|
37
|
+
const flag = flags[argName];
|
|
38
|
+
if (flag instanceof Array) {
|
|
39
|
+
flag.push(argValue);
|
|
40
|
+
}
|
|
41
|
+
else if (flag) {
|
|
42
|
+
flags[argName] = [flag, argValue];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
flags[argName] = argValue;
|
|
46
|
+
}
|
|
47
|
+
i++;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
cmds.push(arg);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { flags, cmds };
|
|
54
|
+
}
|
|
29
55
|
// noinspection SpellCheckingInspection
|
|
30
56
|
static cliFlow(cmds, usage, logger, cmdArg = process.argv[2], exit = true) {
|
|
31
57
|
const flow = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/cli/index.ts"],"names":[],"mappings":";;;AAIA,uCAAuC;AACvC,MAAM,cAAc,GAAG,KAAK,EAAE,MAA0B,EAAE,IAAgB,EAAE,MAAwB,EAAE,IAAI,GAAG,IAAI,EAAiB,EAAE;IAClI,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;KAC/B;SAAM;QACL,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,aAAa,CAAC,CAAC;SACtD;aAAM;YACL,IAAI;gBACF,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC;aACzB;YAAC,OAAO,CAAM,EAAE;gBACf,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE;oBAClB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBACjB;gBACD,IAAI,IAAI,EAAE;oBACR,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBACjB;aACF;SACF;KACF;AACH,CAAC,CAAA;AAKD,MAAsB,OAAO;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/util/cli/index.ts"],"names":[],"mappings":";;;AAIA,uCAAuC;AACvC,MAAM,cAAc,GAAG,KAAK,EAAE,MAA0B,EAAE,IAAgB,EAAE,MAAwB,EAAE,IAAI,GAAG,IAAI,EAAiB,EAAE;IAClI,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;KAC/B;SAAM;QACL,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,UAAU,GAAG,MAAM,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C,WAAW,EAAE,CAAC,CAAC;iBACnD;gBACD,IAAI,IAAI,EAAE;oBACR,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;iBACjB;aACF;QACH,CAAC,CAAA;QACD,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACjB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAlDD,0BAkDC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultLoggerFormatter = void 0;
|
|
4
4
|
const defaultLoggerFormatter = ({ identifier, level, message }) => `${new Date().toISOString()} ${process.pid} ` +
|
|
5
|
-
`[${identifier}] ` +
|
|
5
|
+
`${identifier ? `[${identifier}] ` : ""}` +
|
|
6
6
|
`${level !== "info" ? (level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] `) : ""}` +
|
|
7
7
|
`${message}`;
|
|
8
8
|
exports.defaultLoggerFormatter = defaultLoggerFormatter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/util/logger/formatter.ts"],"names":[],"mappings":";;;AAIO,MAAM,sBAAsB,GACjC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,GAAG,GAAG;IAC/E,IAAI,UAAU,IAAI;
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/util/logger/formatter.ts"],"names":[],"mappings":";;;AAIO,MAAM,sBAAsB,GACjC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,OAAO,CAAC,GAAG,GAAG;IAC/E,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;IACzC,GAAG,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;IAClH,GAAG,OAAO,EAAE,CAAC;AAJJ,QAAA,sBAAsB,0BAIlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miqro/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"coverage": "nyc npm run test",
|
|
12
12
|
"build:test": "rm -Rf test-dist/; tsc -p tsconfig-test.json",
|
|
13
13
|
"pretest": "npm run build:test",
|
|
14
|
-
"test": "LOG_LEVEL=trace NODE_ENV=test node test-dist/src/test/main.js
|
|
15
|
-
"
|
|
14
|
+
"test": "LOG_LEVEL=trace NODE_ENV=test node test-dist/src/test/main.js test-dist/**/*.test.js -n ",
|
|
15
|
+
"testname": "LOG_LEVEL=trace NODE_ENV=test node test-dist/src/test/main.js test-dist/**/*.test.js -n ",
|
|
16
|
+
"testfile": "LOG_LEVEL=trace NODE_ENV=test node test-dist/src/test/main.js ",
|
|
16
17
|
"lint": "eslint ./src --ext ts",
|
|
17
18
|
"fixlint": "eslint ./src --ext ts --fix"
|
|
18
19
|
},
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { Console } from "console";
|
|
2
|
-
import { lstatSync, readdirSync } from "fs";
|
|
3
|
-
import { basename, resolve } from "path";
|
|
1
|
+
import { Console, count } from "console";
|
|
4
2
|
import { format } from "util";
|
|
5
3
|
import { Logger } from "../../util";
|
|
6
4
|
|
|
@@ -25,7 +23,7 @@ export const it = (title: string, impl: TestFunction, options?: {
|
|
|
25
23
|
run: () => new Promise((resolve, reject) => {
|
|
26
24
|
const timeoutMS = options && options.timeout ? options.timeout : DEFAULT_TIMEOUT;
|
|
27
25
|
const timeout = setTimeout(() => {
|
|
28
|
-
reject(new Error(format("
|
|
26
|
+
reject(new Error(format("%s failed\x1b[31m\n%s timeout %o\x1b", fullName, fullName, timeoutMS)));
|
|
29
27
|
}, timeoutMS);
|
|
30
28
|
try {
|
|
31
29
|
(async () => {
|
|
@@ -41,15 +39,15 @@ export const it = (title: string, impl: TestFunction, options?: {
|
|
|
41
39
|
return took;
|
|
42
40
|
})().then((took) => {
|
|
43
41
|
clearTimeout(timeout);
|
|
44
|
-
logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m
|
|
42
|
+
logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m", fullName, took);
|
|
45
43
|
resolve();
|
|
46
44
|
}).catch(e => {
|
|
47
45
|
clearTimeout(timeout);
|
|
48
|
-
reject(new Error(format("
|
|
46
|
+
reject(new Error(format("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
49
47
|
});
|
|
50
48
|
} catch (e) {
|
|
51
49
|
clearTimeout(timeout);
|
|
52
|
-
reject(new Error(format("
|
|
50
|
+
reject(new Error(format("%s failed\n%s finished with errors %o", fullName, fullName, e)));
|
|
53
51
|
}
|
|
54
52
|
}), title,
|
|
55
53
|
category,
|
|
@@ -57,41 +55,62 @@ export const it = (title: string, impl: TestFunction, options?: {
|
|
|
57
55
|
});
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
export const runTests = async (title?: string | string[], logger: Logger | Console = new Console(process.stdout))
|
|
61
|
-
|
|
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
|
+
};
|
|
62
82
|
for (const test of tests) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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++;
|
|
69
97
|
}
|
|
70
98
|
}
|
|
71
99
|
}
|
|
100
|
+
return ret;
|
|
72
101
|
};
|
|
73
102
|
|
|
74
|
-
export const runTestModules = async (modules: string[], title?: string | string[])
|
|
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
|
+
}> => {
|
|
75
112
|
for (const path of modules) {
|
|
76
113
|
require(path);
|
|
77
114
|
}
|
|
78
|
-
await runTests(title);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const runTestDir = async (dirs: string[], title?: string | string[], exts: string[] = ["test.js"]) => {
|
|
82
|
-
for (const dir of dirs) {
|
|
83
|
-
const files = readdirSync(resolve(process.cwd(), dir));
|
|
84
|
-
for (const f of files) {
|
|
85
|
-
const path = resolve(dir, f);
|
|
86
|
-
if (!lstatSync(path).isDirectory()) {
|
|
87
|
-
for (const ext of exts) {
|
|
88
|
-
const name = basename(f);
|
|
89
|
-
if (name.indexOf(ext) === name.length - ext.length) {
|
|
90
|
-
require(path);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
await runTests(title);
|
|
115
|
+
return await runTests(title, logger);
|
|
97
116
|
}
|
package/src/test/main.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
import { resolve } from "path";
|
|
2
|
-
import {
|
|
2
|
+
import { CLIUtil, getLogger } from "../util";
|
|
3
|
+
import { runTestModules } from "./common";
|
|
3
4
|
|
|
4
5
|
const startMS = Date.now();
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
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) => {
|
|
11
14
|
const took = Date.now() - startMS;
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
}
|
|
14
29
|
}).catch(e => {
|
|
15
|
-
|
|
30
|
+
logger.error(e);
|
|
16
31
|
process.exit(1);
|
|
17
32
|
});
|
package/src/util/cli/index.ts
CHANGED
|
@@ -28,6 +28,29 @@ const routeCMDModule = async (cmdArg: string | undefined, cmds: CMDMapType, logg
|
|
|
28
28
|
export type CMDMapType = SimpleMap<{ cb: Callback<void> | Callback<Promise<void>>; description: string; section?: string; }>
|
|
29
29
|
|
|
30
30
|
export abstract class CLIUtil {
|
|
31
|
+
public static extractFlags(args: string[]): { flags: SimpleMap<string | string[]>; cmds: string[]; } {
|
|
32
|
+
const flags: SimpleMap<string | string[]> = {};
|
|
33
|
+
const cmds: string[] = [];
|
|
34
|
+
for (let i = 0; i < args.length; i++) {
|
|
35
|
+
const arg = args[i];
|
|
36
|
+
if (arg.indexOf("-") === 0) {
|
|
37
|
+
const argName = arg.substring(arg.indexOf("--") === 0 ? 2 : 1);
|
|
38
|
+
const argValue = args.length > i + 1 && args[i + 1] && args[i + 1].indexOf("-") != 0 ? args[i + 1] : "";
|
|
39
|
+
const flag = flags[argName];
|
|
40
|
+
if (flag instanceof Array) {
|
|
41
|
+
flag.push(argValue);
|
|
42
|
+
} else if (flag) {
|
|
43
|
+
flags[argName] = [flag, argValue];
|
|
44
|
+
} else {
|
|
45
|
+
flags[argName] = argValue;
|
|
46
|
+
}
|
|
47
|
+
i++;
|
|
48
|
+
} else {
|
|
49
|
+
cmds.push(arg);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { flags, cmds };
|
|
53
|
+
}
|
|
31
54
|
// noinspection SpellCheckingInspection
|
|
32
55
|
public static cliFlow(cmds: CMDMapType, usage: string, logger: Logger | Console, cmdArg = process.argv[2], exit = true): void {
|
|
33
56
|
const flow = async () => {
|
|
@@ -4,6 +4,6 @@ export type LoggerFormatter = (args: { identifier: string, level: LogLevel, mess
|
|
|
4
4
|
|
|
5
5
|
export const defaultLoggerFormatter: LoggerFormatter =
|
|
6
6
|
({ identifier, level, message }) => `${new Date().toISOString()} ${process.pid} ` +
|
|
7
|
-
`[${identifier}] ` +
|
|
7
|
+
`${identifier ? `[${identifier}] ` : ""}` +
|
|
8
8
|
`${level !== "info" ? (level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] `) : ""}` +
|
|
9
9
|
`${message}`;
|
package/test.md
ADDED
|
File without changes
|