@hg-ts/tests 0.0.15

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.
Files changed (93) hide show
  1. package/.eslintcache +1 -0
  2. package/.eslintrc.json +1 -0
  3. package/bin/test-dev.mjs +4 -0
  4. package/bin/test.mjs +1 -0
  5. package/config/base.cjs +30 -0
  6. package/config/common.cjs +6 -0
  7. package/config/esm.cjs +14 -0
  8. package/config/index.cjs +1 -0
  9. package/dist/decorators/decorate-test.d.ts +4 -0
  10. package/dist/decorators/decorate-test.d.ts.map +1 -0
  11. package/dist/decorators/decorate-test.js +19 -0
  12. package/dist/decorators/decorate-test.js.map +1 -0
  13. package/dist/decorators/describe.decorator.d.ts +3 -0
  14. package/dist/decorators/describe.decorator.d.ts.map +1 -0
  15. package/dist/decorators/describe.decorator.js +11 -0
  16. package/dist/decorators/describe.decorator.js.map +1 -0
  17. package/dist/decorators/expect-error.decorator.d.ts +2 -0
  18. package/dist/decorators/expect-error.decorator.d.ts.map +1 -0
  19. package/dist/decorators/expect-error.decorator.js +22 -0
  20. package/dist/decorators/expect-error.decorator.js.map +1 -0
  21. package/dist/decorators/index.d.ts +4 -0
  22. package/dist/decorators/index.d.ts.map +1 -0
  23. package/dist/decorators/index.js +7 -0
  24. package/dist/decorators/index.js.map +1 -0
  25. package/dist/decorators/test.decorator.d.ts +10 -0
  26. package/dist/decorators/test.decorator.d.ts.map +1 -0
  27. package/dist/decorators/test.decorator.js +12 -0
  28. package/dist/decorators/test.decorator.js.map +1 -0
  29. package/dist/expection.d.ts +6 -0
  30. package/dist/expection.d.ts.map +1 -0
  31. package/dist/expection.js +8 -0
  32. package/dist/expection.js.map +1 -0
  33. package/dist/index.d.ts +5 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +13 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/test-runner.d.ts +16 -0
  38. package/dist/test-runner.d.ts.map +1 -0
  39. package/dist/test-runner.js +73 -0
  40. package/dist/test-runner.js.map +1 -0
  41. package/dist/test-suite.d.ts +10 -0
  42. package/dist/test-suite.d.ts.map +1 -0
  43. package/dist/test-suite.js +12 -0
  44. package/dist/test-suite.js.map +1 -0
  45. package/dist-esm/decorators/decorate-test.d.ts +4 -0
  46. package/dist-esm/decorators/decorate-test.d.ts.map +1 -0
  47. package/dist-esm/decorators/decorate-test.js +15 -0
  48. package/dist-esm/decorators/decorate-test.js.map +1 -0
  49. package/dist-esm/decorators/describe.decorator.d.ts +3 -0
  50. package/dist-esm/decorators/describe.decorator.d.ts.map +1 -0
  51. package/dist-esm/decorators/describe.decorator.js +7 -0
  52. package/dist-esm/decorators/describe.decorator.js.map +1 -0
  53. package/dist-esm/decorators/expect-error.decorator.d.ts +2 -0
  54. package/dist-esm/decorators/expect-error.decorator.d.ts.map +1 -0
  55. package/dist-esm/decorators/expect-error.decorator.js +18 -0
  56. package/dist-esm/decorators/expect-error.decorator.js.map +1 -0
  57. package/dist-esm/decorators/index.d.ts +4 -0
  58. package/dist-esm/decorators/index.d.ts.map +1 -0
  59. package/dist-esm/decorators/index.js +4 -0
  60. package/dist-esm/decorators/index.js.map +1 -0
  61. package/dist-esm/decorators/test.decorator.d.ts +10 -0
  62. package/dist-esm/decorators/test.decorator.d.ts.map +1 -0
  63. package/dist-esm/decorators/test.decorator.js +8 -0
  64. package/dist-esm/decorators/test.decorator.js.map +1 -0
  65. package/dist-esm/expection.d.ts +6 -0
  66. package/dist-esm/expection.d.ts.map +1 -0
  67. package/dist-esm/expection.js +4 -0
  68. package/dist-esm/expection.js.map +1 -0
  69. package/dist-esm/index.d.ts +5 -0
  70. package/dist-esm/index.d.ts.map +1 -0
  71. package/dist-esm/index.js +5 -0
  72. package/dist-esm/index.js.map +1 -0
  73. package/dist-esm/test-runner.d.ts +16 -0
  74. package/dist-esm/test-runner.d.ts.map +1 -0
  75. package/dist-esm/test-runner.js +69 -0
  76. package/dist-esm/test-runner.js.map +1 -0
  77. package/dist-esm/test-suite.d.ts +10 -0
  78. package/dist-esm/test-suite.d.ts.map +1 -0
  79. package/dist-esm/test-suite.js +8 -0
  80. package/dist-esm/test-suite.js.map +1 -0
  81. package/eslint.junit.xml +28 -0
  82. package/package.json +39 -0
  83. package/src/decorators/decorate-test.ts +22 -0
  84. package/src/decorators/describe.decorator.ts +10 -0
  85. package/src/decorators/expect-error.decorator.ts +17 -0
  86. package/src/decorators/index.ts +3 -0
  87. package/src/decorators/test.decorator.ts +23 -0
  88. package/src/expection.ts +13 -0
  89. package/src/index.ts +6 -0
  90. package/src/test-runner.ts +117 -0
  91. package/src/test-suite.ts +17 -0
  92. package/tsconfig.esm.json +9 -0
  93. package/tsconfig.json +10 -0
package/.eslintcache ADDED
@@ -0,0 +1 @@
1
+ [{"/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/decorate-test.ts":"1","/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/describe.decorator.ts":"2","/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/expect-error.decorator.ts":"3","/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/index.ts":"4","/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/test.decorator.ts":"5","/Volumes/Work/ts/hg/framework/packages/tests/src/expection.ts":"6","/Volumes/Work/ts/hg/framework/packages/tests/src/index.ts":"7","/Volumes/Work/ts/hg/framework/packages/tests/src/test-runner.ts":"8","/Volumes/Work/ts/hg/framework/packages/tests/src/test-suite.ts":"9"},{"size":690,"mtime":1664329600892,"results":"10","hashOfConfig":"11"},{"size":218,"mtime":1626299896349,"results":"12","hashOfConfig":"11"},{"size":448,"mtime":1664329482818,"results":"13","hashOfConfig":"11"},{"size":114,"mtime":1626299896350,"results":"14","hashOfConfig":"11"},{"size":539,"mtime":1657490375779,"results":"15","hashOfConfig":"11"},{"size":218,"mtime":1657493281168,"results":"16","hashOfConfig":"11"},{"size":169,"mtime":1665300013486,"results":"17","hashOfConfig":"11"},{"size":2989,"mtime":1664319237830,"results":"18","hashOfConfig":"11"},{"size":380,"mtime":1660866296753,"results":"19","hashOfConfig":"11"},{"filePath":"20","messages":"21","suppressedMessages":"22","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"ic51mg",{"filePath":"23","messages":"24","suppressedMessages":"25","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"26","messages":"27","suppressedMessages":"28","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"29","messages":"30","suppressedMessages":"31","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"32","messages":"33","suppressedMessages":"34","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"35","messages":"36","suppressedMessages":"37","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"38","messages":"39","suppressedMessages":"40","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"41","messages":"42","suppressedMessages":"43","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","suppressedMessages":"46","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/decorate-test.ts",[],["47"],"/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/describe.decorator.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/expect-error.decorator.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/decorators/test.decorator.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/expection.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/index.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/test-runner.ts",[],[],"/Volumes/Work/ts/hg/framework/packages/tests/src/test-suite.ts",[],[],{"ruleId":"48","severity":2,"message":"49","line":12,"column":11,"nodeType":"50","messageId":"51","endLine":12,"endColumn":15,"suppressions":"52"},"@typescript-eslint/no-this-alias","Unexpected aliasing of 'this' to local variable.","Identifier","thisAssignment",["53"],{"kind":"54","justification":"55"},"directive",""]
package/.eslintrc.json ADDED
@@ -0,0 +1 @@
1
+ { "extends": "@hg-ts-config/eslint-config" }
@@ -0,0 +1,4 @@
1
+ const commandParts = ['yarn', 'test'];
2
+ process.argv.push('--onSuccess', commandParts.join(' '));
3
+
4
+ import('@hg-ts-config/typescript/build-dev.mjs');
package/bin/test.mjs ADDED
@@ -0,0 +1 @@
1
+ import('mocha/bin/mocha.js');
@@ -0,0 +1,30 @@
1
+ const { resolve } = require('path');
2
+
3
+ module.exports.baseNodeOptions = [
4
+ 'enable-source-maps',
5
+ 'abort-on-uncaught-exception',
6
+ ];
7
+
8
+ const baseConfig = {
9
+ 'async-only': true,
10
+ extension: [
11
+ 'ts',
12
+ 'tsx',
13
+ ],
14
+ spec: [
15
+ 'dist/**/*.test.js',
16
+ 'dist/**/*.test-suite.js',
17
+ 'dist/**/*TestSuite.js',
18
+ ],
19
+ 'trace-warnings': true,
20
+ checkLeaks: true,
21
+ exit: true,
22
+ file: [require.resolve('reflect-metadata')]
23
+ };
24
+
25
+ if (process.env.CI) {
26
+ baseConfig.reporter = resolve(__dirname, 'ci-reporter.cjs');
27
+ baseConfig['reporter-options'] = `mochaFile=${resolve('junit.xml')}`;
28
+ }
29
+
30
+ module.exports.baseConfig = baseConfig;
@@ -0,0 +1,6 @@
1
+ const { baseNodeOptions, baseConfig } = require('./base.cjs');
2
+
3
+ module.exports = {
4
+ ...baseConfig,
5
+ 'node-option': baseNodeOptions.join(','),
6
+ };
package/config/esm.cjs ADDED
@@ -0,0 +1,14 @@
1
+ const { baseNodeOptions, baseConfig } = require('./base.cjs');
2
+
3
+ const nodeOptions = [
4
+ ...baseNodeOptions,
5
+ 'experimental-import-meta-resolve',
6
+ 'experimental-json-modules',
7
+ 'experimental-specifier-resolution=node',
8
+ 'no-warnings'
9
+ ];
10
+
11
+ module.exports = {
12
+ ...baseConfig,
13
+ 'node-option': nodeOptions.join(','),
14
+ };
@@ -0,0 +1 @@
1
+ module.exports = require('./esm');
@@ -0,0 +1,4 @@
1
+ declare type TestDecorator = (callback: () => Promise<void>) => Promise<void>;
2
+ export declare function createTestDecorator(decorator: TestDecorator): MethodDecorator;
3
+ export {};
4
+ //# sourceMappingURL=decorate-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorate-test.d.ts","sourceRoot":"","sources":["../../src/decorators/decorate-test.ts"],"names":[],"mappings":"AAAA,aAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,aAAa,GAAG,eAAe,CAmB7E"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTestDecorator = void 0;
4
+ function createTestDecorator(decorator) {
5
+ function result(_target, _key, descriptor) {
6
+ return {
7
+ async value(...args) {
8
+ const self = this;
9
+ const method = descriptor.value;
10
+ if (typeof method === 'function') {
11
+ await decorator(method.bind(self, ...args));
12
+ }
13
+ },
14
+ };
15
+ }
16
+ return result;
17
+ }
18
+ exports.createTestDecorator = createTestDecorator;
19
+ //# sourceMappingURL=decorate-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorate-test.js","sourceRoot":"","sources":["../../src/decorators/decorate-test.ts"],"names":[],"mappings":";;;AAEA,SAAgB,mBAAmB,CAAC,SAAwB;IAC3D,SAAS,MAAM,CACd,OAAgB,EAChB,IAAY,EACZ,UAA0E;QAE1E,OAAO;YACN,KAAK,CAAC,KAAK,CAAC,GAAG,IAAe;gBAE7B,MAAM,IAAI,GAAG,IAAI,CAAC;gBAClB,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;gBAChC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;oBACjC,MAAM,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;iBAC5C;YACF,CAAC;SACD,CAAC;IACH,CAAC;IAED,OAAO,MAAyB,CAAC;AAClC,CAAC;AAnBD,kDAmBC"}
@@ -0,0 +1,3 @@
1
+ import { TestRunnerOptions } from '../test-runner';
2
+ export declare function Describe(options?: TestRunnerOptions): ClassDecorator;
3
+ //# sourceMappingURL=describe.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/describe.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,iBAAiB,EACjB,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,QAAQ,CAAC,OAAO,GAAE,iBAAsB,GAAG,cAAc,CAIxE"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Describe = void 0;
4
+ const test_runner_1 = require("../test-runner");
5
+ function Describe(options = {}) {
6
+ return (target) => {
7
+ test_runner_1.TestRunner.run(target, options);
8
+ };
9
+ }
10
+ exports.Describe = Describe;
11
+ //# sourceMappingURL=describe.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.decorator.js","sourceRoot":"","sources":["../../src/decorators/describe.decorator.ts"],"names":[],"mappings":";;;AAAA,gDAGwB;AAExB,SAAgB,QAAQ,CAAC,UAA6B,EAAE;IACvD,OAAO,CAAC,MAAW,EAAQ,EAAE;QAC5B,wBAAU,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC,CAAC;AACH,CAAC;AAJD,4BAIC"}
@@ -0,0 +1,2 @@
1
+ export declare function ExpectException(error: Class<any, any[]>): MethodDecorator;
2
+ //# sourceMappingURL=expect-error.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-error.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/expect-error.decorator.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAazE"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExpectException = void 0;
4
+ const expection_1 = require("../expection");
5
+ const decorate_test_1 = require("./decorate-test");
6
+ function ExpectException(error) {
7
+ return (0, decorate_test_1.createTestDecorator)(async (method) => {
8
+ let isThrowError = false;
9
+ try {
10
+ await method();
11
+ }
12
+ catch (err) {
13
+ isThrowError = true;
14
+ (0, expection_1.expect)(err).toBeInstanceOf(error);
15
+ }
16
+ finally {
17
+ (0, expection_1.expect)(isThrowError).toBeTruthy();
18
+ }
19
+ });
20
+ }
21
+ exports.ExpectException = ExpectException;
22
+ //# sourceMappingURL=expect-error.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-error.decorator.js","sourceRoot":"","sources":["../../src/decorators/expect-error.decorator.ts"],"names":[],"mappings":";;;AAAA,4CAAsC;AACtC,mDAAsD;AAEtD,SAAgB,eAAe,CAAC,KAAwB;IACvD,OAAO,IAAA,mCAAmB,EAAC,KAAK,EAAC,MAA2B,EAAE,EAAE;QAC/D,IAAI,YAAY,GAAG,KAAK,CAAC;QAEzB,IAAI;YACH,MAAM,MAAM,EAAE,CAAC;SACf;QAAC,OAAO,GAAY,EAAE;YACtB,YAAY,GAAG,IAAI,CAAC;YACpB,IAAA,kBAAM,EAAC,GAAG,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;SAClC;gBAAS;YACT,IAAA,kBAAM,EAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;SAClC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAbD,0CAaC"}
@@ -0,0 +1,4 @@
1
+ export * from './expect-error.decorator';
2
+ export * from './describe.decorator';
3
+ export * from './test.decorator';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./expect-error.decorator"), exports);
5
+ tslib_1.__exportStar(require("./describe.decorator"), exports);
6
+ tslib_1.__exportStar(require("./test.decorator"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;AAAA,mEAAyC;AACzC,+DAAqC;AACrC,2DAAiC"}
@@ -0,0 +1,10 @@
1
+ export declare type MethodName = string | symbol;
2
+ export declare type Options = {
3
+ name?: string;
4
+ only?: boolean;
5
+ skip?: boolean;
6
+ todo?: boolean;
7
+ };
8
+ export declare type Method<Arguments extends any[] = never> = (...args: Arguments) => Promise<void> | void;
9
+ export declare function Test(options?: Options): MethodDecorator;
10
+ //# sourceMappingURL=test.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/test.decorator.ts"],"names":[],"mappings":"AAGA,oBAAY,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AACzC,oBAAY,OAAO,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AACF,oBAAY,MAAM,CAAC,SAAS,SAAS,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnG,wBAAgB,IAAI,CAAC,OAAO,GAAE,OAAY,GAAG,eAAe,CAU3D"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Test = void 0;
4
+ function Test(options = {}) {
5
+ return (target, propertyKey) => {
6
+ const suite = target;
7
+ suite.testsMap ??= new Map();
8
+ suite.testsMap.set(propertyKey, options);
9
+ };
10
+ }
11
+ exports.Test = Test;
12
+ //# sourceMappingURL=test.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.decorator.js","sourceRoot":"","sources":["../../src/decorators/test.decorator.ts"],"names":[],"mappings":";;;AAYA,SAAgB,IAAI,CAAC,UAAmB,EAAE;IACzC,OAAO,CACN,MAAc,EACd,WAAuB,EAChB,EAAE;QACT,MAAM,KAAK,GAAG,MAAmB,CAAC;QAElC,KAAK,CAAC,QAAQ,KAAK,IAAI,GAAG,EAAE,CAAC;QAC7B,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC;AACH,CAAC;AAVD,oBAUC"}
@@ -0,0 +1,6 @@
1
+ import expectFunc from 'expect';
2
+ declare global {
3
+ const expect: typeof expectFunc;
4
+ }
5
+ export { expectFunc as expect };
6
+ //# sourceMappingURL=expection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expection.d.ts","sourceRoot":"","sources":["../src/expection.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,QAAQ,CAAC;AAIhC,OAAO,CAAC,MAAM,CAAC;IACX,MAAM,MAAM,EAAE,OAAO,UAAU,CAAC;CACnC;AAMD,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expect = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const expect_1 = tslib_1.__importDefault(require("expect"));
6
+ exports.expect = expect_1.default;
7
+ global.expect = expect_1.default;
8
+ //# sourceMappingURL=expection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expection.js","sourceRoot":"","sources":["../src/expection.ts"],"names":[],"mappings":";;;;AAAA,4DAAgC;AAYT,iBAZhB,gBAAU,CAYY;AAV5B,MAAc,CAAC,MAAM,GAAG,gBAAU,CAAC"}
@@ -0,0 +1,5 @@
1
+ import '@hg-ts/types';
2
+ export { Describe, Test, ExpectException } from './decorators';
3
+ export { TestSuite } from './test-suite';
4
+ export { expect } from './expection';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.expect = exports.TestSuite = exports.ExpectException = exports.Test = exports.Describe = void 0;
4
+ require("@hg-ts/types");
5
+ var decorators_1 = require("./decorators");
6
+ Object.defineProperty(exports, "Describe", { enumerable: true, get: function () { return decorators_1.Describe; } });
7
+ Object.defineProperty(exports, "Test", { enumerable: true, get: function () { return decorators_1.Test; } });
8
+ Object.defineProperty(exports, "ExpectException", { enumerable: true, get: function () { return decorators_1.ExpectException; } });
9
+ var test_suite_1 = require("./test-suite");
10
+ Object.defineProperty(exports, "TestSuite", { enumerable: true, get: function () { return test_suite_1.TestSuite; } });
11
+ var expection_1 = require("./expection");
12
+ Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return expection_1.expect; } });
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,wBAAsB;AAEtB,2CAA+D;AAAtD,sGAAA,QAAQ,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,6GAAA,eAAe,OAAA;AAExC,2CAAyC;AAAhC,uGAAA,SAAS,OAAA;AAClB,yCAAqC;AAA5B,mGAAA,MAAM,OAAA"}
@@ -0,0 +1,16 @@
1
+ import type { TestSuiteConstructor } from './test-suite';
2
+ export declare type TestRunnerOptions = {
3
+ name?: string;
4
+ only?: boolean;
5
+ skip?: boolean;
6
+ };
7
+ export declare type TestMethod = (...args: unknown[]) => Promise<void>;
8
+ export declare class TestRunner {
9
+ static run(suiteConstructor: TestSuiteConstructor, options?: TestRunnerOptions): void;
10
+ private static getDescribeFunction;
11
+ private static describe;
12
+ private static registerTests;
13
+ private static getTestMethod;
14
+ private static getTestRegisterMethod;
15
+ }
16
+ //# sourceMappingURL=test-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runner.d.ts","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAa,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpE,oBAAY,iBAAiB,GAAG;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,oBAAY,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAI/D,qBAAa,UAAU;WACR,GAAG,CAChB,gBAAgB,EAAE,oBAAoB,EACtC,OAAO,GAAE,iBAAsB,GAC7B,IAAI;IAUP,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAiBlC,OAAO,CAAC,MAAM,CAAC,QAAQ;IAqBvB,OAAO,CAAC,MAAM,CAAC,aAAa;IAe5B,OAAO,CAAC,MAAM,CAAC,aAAa;IAa5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAWpC"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestRunner = void 0;
4
+ const expection_1 = require("./expection");
5
+ class TestRunner {
6
+ static run(suiteConstructor, options = {}) {
7
+ const suite = new suiteConstructor();
8
+ suite.testsMap = suiteConstructor.prototype.testsMap;
9
+ const { name = suite.constructor.name } = options;
10
+ const describeFunction = this.getDescribeFunction(options);
11
+ describeFunction(name, this.describe.bind(this, suite));
12
+ }
13
+ static getDescribeFunction(options = {}) {
14
+ const { only = false, skip = false, } = options;
15
+ let describeFunction = describe;
16
+ if (only) {
17
+ describeFunction = describe.only;
18
+ }
19
+ else if (skip) {
20
+ describeFunction = describe.skip;
21
+ }
22
+ return describeFunction;
23
+ }
24
+ static describe(suite) {
25
+ before(async () => suite.setUp());
26
+ after(async () => suite.tearDown());
27
+ beforeEach(async () => suite.beforeEach());
28
+ afterEach(async () => {
29
+ expection_1.expect.setState({
30
+ assertionCalls: 0,
31
+ expectedAssertionsNumber: null,
32
+ isExpectingAssertions: false,
33
+ });
34
+ await suite.afterEach();
35
+ });
36
+ if (!suite.testsMap) {
37
+ suite.testsMap = new Map();
38
+ }
39
+ suite.testsMap.forEach((options, methodName) => this.registerTests(suite, options, methodName));
40
+ }
41
+ static registerTests(suite, options, testName) {
42
+ const { name = testName.toString() } = options;
43
+ if (options.todo) {
44
+ it.skip(`TODO: ${name}`);
45
+ return;
46
+ }
47
+ const method = this.getTestMethod(suite, testName);
48
+ const registerMethod = this.getTestRegisterMethod(options);
49
+ registerMethod(name, method);
50
+ }
51
+ static getTestMethod(suite, methodName) {
52
+ const testMethod = suite[methodName].bind(suite);
53
+ return async (...args) => {
54
+ await testMethod(...args);
55
+ const { expectedAssertionsNumber, assertionCalls } = expection_1.expect.getState();
56
+ if (typeof expectedAssertionsNumber === 'number') {
57
+ (0, expection_1.expect)(assertionCalls).toBe(expectedAssertionsNumber);
58
+ }
59
+ };
60
+ }
61
+ static getTestRegisterMethod(options) {
62
+ let registerMethod = it;
63
+ if (options.skip) {
64
+ registerMethod = it.skip;
65
+ }
66
+ else if (options.only) {
67
+ registerMethod = it.only;
68
+ }
69
+ return registerMethod;
70
+ }
71
+ }
72
+ exports.TestRunner = TestRunner;
73
+ //# sourceMappingURL=test-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runner.js","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import type { MethodName, Options } from './decorators';
2
+ export declare type TestSuiteConstructor = new () => TestSuite;
3
+ export declare abstract class TestSuite {
4
+ testsMap: Map<MethodName, Options> | null;
5
+ setUp(): Promise<void>;
6
+ tearDown(): Promise<void>;
7
+ beforeEach(): Promise<void>;
8
+ afterEach(): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=test-suite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-suite.d.ts","sourceRoot":"","sources":["../src/test-suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,OAAO,EACP,MAAM,cAAc,CAAC;AAEtB,oBAAY,oBAAoB,GAAG,UAAU,SAAS,CAAC;AACvD,8BAAsB,SAAS;IACvB,QAAQ,EAAE,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAEpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAEtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAEzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CACvC"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TestSuite = void 0;
4
+ class TestSuite {
5
+ testsMap;
6
+ async setUp() { }
7
+ async tearDown() { }
8
+ async beforeEach() { }
9
+ async afterEach() { }
10
+ }
11
+ exports.TestSuite = TestSuite;
12
+ //# sourceMappingURL=test-suite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-suite.js","sourceRoot":"","sources":["../src/test-suite.ts"],"names":[],"mappings":";;;AAMA,MAAsB,SAAS;IACvB,QAAQ,CAAkC;IAE1C,KAAK,CAAC,KAAK,KAAmB,CAAC;IAE/B,KAAK,CAAC,QAAQ,KAAmB,CAAC;IAElC,KAAK,CAAC,UAAU,KAAmB,CAAC;IAEpC,KAAK,CAAC,SAAS,KAAmB,CAAC;CAC1C;AAVD,8BAUC"}
@@ -0,0 +1,4 @@
1
+ declare type TestDecorator = (callback: () => Promise<void>) => Promise<void>;
2
+ export declare function createTestDecorator(decorator: TestDecorator): MethodDecorator;
3
+ export {};
4
+ //# sourceMappingURL=decorate-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorate-test.d.ts","sourceRoot":"","sources":["../../src/decorators/decorate-test.ts"],"names":[],"mappings":"AAAA,aAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEtE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,aAAa,GAAG,eAAe,CAmB7E"}
@@ -0,0 +1,15 @@
1
+ export function createTestDecorator(decorator) {
2
+ function result(_target, _key, descriptor) {
3
+ return {
4
+ async value(...args) {
5
+ const self = this;
6
+ const method = descriptor.value;
7
+ if (typeof method === 'function') {
8
+ await decorator(method.bind(self, ...args));
9
+ }
10
+ },
11
+ };
12
+ }
13
+ return result;
14
+ }
15
+ //# sourceMappingURL=decorate-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorate-test.js","sourceRoot":"","sources":["../../src/decorators/decorate-test.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,mBAAmB,CAAC,SAAwB;IAC3D,SAAS,MAAM,CACd,OAAgB,EAChB,IAAY,EACZ,UAA0E;QAE1E,OAAO;YACN,KAAK,CAAC,KAAK,CAAC,GAAG,IAAe;gBAE7B,MAAM,IAAI,GAAG,IAAI,CAAC;gBAClB,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC;gBAChC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE;oBACjC,MAAM,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;iBAC5C;YACF,CAAC;SACD,CAAC;IACH,CAAC;IAED,OAAO,MAAyB,CAAC;AAClC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { TestRunnerOptions } from '../test-runner';
2
+ export declare function Describe(options?: TestRunnerOptions): ClassDecorator;
3
+ //# sourceMappingURL=describe.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/describe.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,iBAAiB,EACjB,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,QAAQ,CAAC,OAAO,GAAE,iBAAsB,GAAG,cAAc,CAIxE"}
@@ -0,0 +1,7 @@
1
+ import { TestRunner, } from '../test-runner';
2
+ export function Describe(options = {}) {
3
+ return (target) => {
4
+ TestRunner.run(target, options);
5
+ };
6
+ }
7
+ //# sourceMappingURL=describe.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.decorator.js","sourceRoot":"","sources":["../../src/decorators/describe.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,UAAU,GAEV,MAAM,gBAAgB,CAAC;AAExB,MAAM,UAAU,QAAQ,CAAC,UAA6B,EAAE;IACvD,OAAO,CAAC,MAAW,EAAQ,EAAE;QAC5B,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function ExpectException(error: Class<any, any[]>): MethodDecorator;
2
+ //# sourceMappingURL=expect-error.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-error.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/expect-error.decorator.ts"],"names":[],"mappings":"AAGA,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAazE"}
@@ -0,0 +1,18 @@
1
+ import { expect } from '../expection';
2
+ import { createTestDecorator } from './decorate-test';
3
+ export function ExpectException(error) {
4
+ return createTestDecorator(async (method) => {
5
+ let isThrowError = false;
6
+ try {
7
+ await method();
8
+ }
9
+ catch (err) {
10
+ isThrowError = true;
11
+ expect(err).toBeInstanceOf(error);
12
+ }
13
+ finally {
14
+ expect(isThrowError).toBeTruthy();
15
+ }
16
+ });
17
+ }
18
+ //# sourceMappingURL=expect-error.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expect-error.decorator.js","sourceRoot":"","sources":["../../src/decorators/expect-error.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,UAAU,eAAe,CAAC,KAAwB;IACvD,OAAO,mBAAmB,CAAC,KAAK,EAAC,MAA2B,EAAE,EAAE;QAC/D,IAAI,YAAY,GAAG,KAAK,CAAC;QAEzB,IAAI;YACH,MAAM,MAAM,EAAE,CAAC;SACf;QAAC,OAAO,GAAY,EAAE;YACtB,YAAY,GAAG,IAAI,CAAC;YACpB,MAAM,CAAC,GAAG,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;SAClC;gBAAS;YACT,MAAM,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE,CAAC;SAClC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './expect-error.decorator';
2
+ export * from './describe.decorator';
3
+ export * from './test.decorator';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './expect-error.decorator';
2
+ export * from './describe.decorator';
3
+ export * from './test.decorator';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare type MethodName = string | symbol;
2
+ export declare type Options = {
3
+ name?: string;
4
+ only?: boolean;
5
+ skip?: boolean;
6
+ todo?: boolean;
7
+ };
8
+ export declare type Method<Arguments extends any[] = never> = (...args: Arguments) => Promise<void> | void;
9
+ export declare function Test(options?: Options): MethodDecorator;
10
+ //# sourceMappingURL=test.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/test.decorator.ts"],"names":[],"mappings":"AAGA,oBAAY,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AACzC,oBAAY,OAAO,GAAG;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AACF,oBAAY,MAAM,CAAC,SAAS,SAAS,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAEnG,wBAAgB,IAAI,CAAC,OAAO,GAAE,OAAY,GAAG,eAAe,CAU3D"}
@@ -0,0 +1,8 @@
1
+ export function Test(options = {}) {
2
+ return (target, propertyKey) => {
3
+ const suite = target;
4
+ suite.testsMap ??= new Map();
5
+ suite.testsMap.set(propertyKey, options);
6
+ };
7
+ }
8
+ //# sourceMappingURL=test.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.decorator.js","sourceRoot":"","sources":["../../src/decorators/test.decorator.ts"],"names":[],"mappings":"AAYA,MAAM,UAAU,IAAI,CAAC,UAAmB,EAAE;IACzC,OAAO,CACN,MAAc,EACd,WAAuB,EAChB,EAAE;QACT,MAAM,KAAK,GAAG,MAAmB,CAAC;QAElC,KAAK,CAAC,QAAQ,KAAK,IAAI,GAAG,EAAE,CAAC;QAC7B,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import expectFunc from 'expect';
2
+ declare global {
3
+ const expect: typeof expectFunc;
4
+ }
5
+ export { expectFunc as expect };
6
+ //# sourceMappingURL=expection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expection.d.ts","sourceRoot":"","sources":["../src/expection.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,QAAQ,CAAC;AAIhC,OAAO,CAAC,MAAM,CAAC;IACX,MAAM,MAAM,EAAE,OAAO,UAAU,CAAC;CACnC;AAMD,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1,4 @@
1
+ import expectFunc from 'expect';
2
+ global.expect = expectFunc;
3
+ export { expectFunc as expect };
4
+ //# sourceMappingURL=expection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expection.js","sourceRoot":"","sources":["../src/expection.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,QAAQ,CAAC;AAE/B,MAAc,CAAC,MAAM,GAAG,UAAU,CAAC;AAUpC,OAAO,EAAE,UAAU,IAAI,MAAM,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ import '@hg-ts/types';
2
+ export { Describe, Test, ExpectException } from './decorators';
3
+ export { TestSuite } from './test-suite';
4
+ export { expect } from './expection';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ import '@hg-ts/types';
2
+ export { Describe, Test, ExpectException } from './decorators';
3
+ export { TestSuite } from './test-suite';
4
+ export { expect } from './expection';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,CAAC;AAEtB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { TestSuiteConstructor } from './test-suite';
2
+ export declare type TestRunnerOptions = {
3
+ name?: string;
4
+ only?: boolean;
5
+ skip?: boolean;
6
+ };
7
+ export declare type TestMethod = (...args: unknown[]) => Promise<void>;
8
+ export declare class TestRunner {
9
+ static run(suiteConstructor: TestSuiteConstructor, options?: TestRunnerOptions): void;
10
+ private static getDescribeFunction;
11
+ private static describe;
12
+ private static registerTests;
13
+ private static getTestMethod;
14
+ private static getTestRegisterMethod;
15
+ }
16
+ //# sourceMappingURL=test-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runner.d.ts","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAa,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpE,oBAAY,iBAAiB,GAAG;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,oBAAY,UAAU,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAI/D,qBAAa,UAAU;WACR,GAAG,CAChB,gBAAgB,EAAE,oBAAoB,EACtC,OAAO,GAAE,iBAAsB,GAC7B,IAAI;IAUP,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAiBlC,OAAO,CAAC,MAAM,CAAC,QAAQ;IAqBvB,OAAO,CAAC,MAAM,CAAC,aAAa;IAe5B,OAAO,CAAC,MAAM,CAAC,aAAa;IAa5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAWpC"}
@@ -0,0 +1,69 @@
1
+ import { expect } from './expection';
2
+ export class TestRunner {
3
+ static run(suiteConstructor, options = {}) {
4
+ const suite = new suiteConstructor();
5
+ suite.testsMap = suiteConstructor.prototype.testsMap;
6
+ const { name = suite.constructor.name } = options;
7
+ const describeFunction = this.getDescribeFunction(options);
8
+ describeFunction(name, this.describe.bind(this, suite));
9
+ }
10
+ static getDescribeFunction(options = {}) {
11
+ const { only = false, skip = false, } = options;
12
+ let describeFunction = describe;
13
+ if (only) {
14
+ describeFunction = describe.only;
15
+ }
16
+ else if (skip) {
17
+ describeFunction = describe.skip;
18
+ }
19
+ return describeFunction;
20
+ }
21
+ static describe(suite) {
22
+ before(async () => suite.setUp());
23
+ after(async () => suite.tearDown());
24
+ beforeEach(async () => suite.beforeEach());
25
+ afterEach(async () => {
26
+ expect.setState({
27
+ assertionCalls: 0,
28
+ expectedAssertionsNumber: null,
29
+ isExpectingAssertions: false,
30
+ });
31
+ await suite.afterEach();
32
+ });
33
+ if (!suite.testsMap) {
34
+ suite.testsMap = new Map();
35
+ }
36
+ suite.testsMap.forEach((options, methodName) => this.registerTests(suite, options, methodName));
37
+ }
38
+ static registerTests(suite, options, testName) {
39
+ const { name = testName.toString() } = options;
40
+ if (options.todo) {
41
+ it.skip(`TODO: ${name}`);
42
+ return;
43
+ }
44
+ const method = this.getTestMethod(suite, testName);
45
+ const registerMethod = this.getTestRegisterMethod(options);
46
+ registerMethod(name, method);
47
+ }
48
+ static getTestMethod(suite, methodName) {
49
+ const testMethod = suite[methodName].bind(suite);
50
+ return async (...args) => {
51
+ await testMethod(...args);
52
+ const { expectedAssertionsNumber, assertionCalls } = expect.getState();
53
+ if (typeof expectedAssertionsNumber === 'number') {
54
+ expect(assertionCalls).toBe(expectedAssertionsNumber);
55
+ }
56
+ };
57
+ }
58
+ static getTestRegisterMethod(options) {
59
+ let registerMethod = it;
60
+ if (options.skip) {
61
+ registerMethod = it.skip;
62
+ }
63
+ else if (options.only) {
64
+ registerMethod = it.only;
65
+ }
66
+ return registerMethod;
67
+ }
68
+ }
69
+ //# sourceMappingURL=test-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-runner.js","sourceRoot":"","sources":["../src/test-runner.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,10 @@
1
+ import type { MethodName, Options } from './decorators';
2
+ export declare type TestSuiteConstructor = new () => TestSuite;
3
+ export declare abstract class TestSuite {
4
+ testsMap: Map<MethodName, Options> | null;
5
+ setUp(): Promise<void>;
6
+ tearDown(): Promise<void>;
7
+ beforeEach(): Promise<void>;
8
+ afterEach(): Promise<void>;
9
+ }
10
+ //# sourceMappingURL=test-suite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-suite.d.ts","sourceRoot":"","sources":["../src/test-suite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,UAAU,EACV,OAAO,EACP,MAAM,cAAc,CAAC;AAEtB,oBAAY,oBAAoB,GAAG,UAAU,SAAS,CAAC;AACvD,8BAAsB,SAAS;IACvB,QAAQ,EAAE,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAEpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAEtB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAEzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAE3B,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CACvC"}
@@ -0,0 +1,8 @@
1
+ export class TestSuite {
2
+ testsMap;
3
+ async setUp() { }
4
+ async tearDown() { }
5
+ async beforeEach() { }
6
+ async afterEach() { }
7
+ }
8
+ //# sourceMappingURL=test-suite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-suite.js","sourceRoot":"","sources":["../src/test-suite.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,SAAS;IACvB,QAAQ,CAAkC;IAE1C,KAAK,CAAC,KAAK,KAAmB,CAAC;IAE/B,KAAK,CAAC,QAAQ,KAAmB,CAAC;IAElC,KAAK,CAAC,UAAU,KAAmB,CAAC;IAEpC,KAAK,CAAC,SAAS,KAAmB,CAAC;CAC1C"}
@@ -0,0 +1,28 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <testsuites>
3
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/describe.decorator.ts">
4
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/describe.decorator.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/describe.decorator" />
5
+ </testsuite>
6
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/expect-error.decorator.ts">
7
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/expect-error.decorator.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/expect-error.decorator" />
8
+ </testsuite>
9
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/index.ts">
10
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/index.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/index" />
11
+ </testsuite>
12
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/test.decorator.ts">
13
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/test.decorator.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/decorators/test.decorator" />
14
+ </testsuite>
15
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/expection.ts">
16
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/expection.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/expection" />
17
+ </testsuite>
18
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/index.ts">
19
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/index.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/index" />
20
+ </testsuite>
21
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/test-runner.ts">
22
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/test-runner.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/test-runner" />
23
+ </testsuite>
24
+ <testsuite package="org.eslint" time="0" tests="1" errors="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/test-suite.ts">
25
+ <testcase time="0" name="/Volumes/Work/ts/hg/framework/utils/tests/src/test-suite.ts" classname="/Volumes/Work/ts/hg/framework/utils/tests/src/test-suite" />
26
+ </testsuite>
27
+ </testsuites>
28
+
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@hg-ts/tests",
3
+ "version": "0.0.15",
4
+ "main": "dist/index.js",
5
+ "module": "dist-esm/index.js",
6
+ "repository": "git@gitlab.com:hyper-graph/framework.git",
7
+ "scripts": {
8
+ "prepack": "yarn build && yarn lint",
9
+ "build": "hg build",
10
+ "build:dev": "hg build:dev",
11
+ "lint": "hg lint",
12
+ "lint:fix": "hg lint:fix"
13
+ },
14
+ "devDependencies": {
15
+ "@hg-ts-config/eslint-config": "0.0.15",
16
+ "@hg-ts-config/typescript": "0.0.15",
17
+ "@hg-ts/cli": "0.0.15",
18
+ "@hg-ts/types": "0.0.15",
19
+ "@types/mocha": "9.1.1",
20
+ "@types/node": "18.7.6",
21
+ "@typescript-eslint/eslint-plugin": "5.33.1",
22
+ "@typescript-eslint/parser": "5.33.1",
23
+ "eslint": "8.24.0",
24
+ "eslint-formatter-codeframe": "7.32.1",
25
+ "mocha": "10.0.0",
26
+ "reflect-metadata": "0.1.13",
27
+ "tsc-watch": "5.0.3",
28
+ "tslib": "2.4.0",
29
+ "typescript": "4.7.4"
30
+ },
31
+ "peerDependencies": {
32
+ "mocha": "*",
33
+ "mocha-junit-reporter": "*",
34
+ "reflect-metadata": "*"
35
+ },
36
+ "dependencies": {
37
+ "expect": "28.1.3"
38
+ }
39
+ }
@@ -0,0 +1,22 @@
1
+ type TestDecorator = (callback: () => Promise<void>) => Promise<void>;
2
+
3
+ export function createTestDecorator(decorator: TestDecorator): MethodDecorator {
4
+ function result(
5
+ _target: unknown,
6
+ _key: string,
7
+ descriptor: TypedPropertyDescriptor<(...args: unknown[]) => Promise<void>>,
8
+ ): TypedPropertyDescriptor<(...args: unknown[]) => Promise<void>> {
9
+ return {
10
+ async value(...args: unknown[]): Promise<void> {
11
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
12
+ const self = this;
13
+ const method = descriptor.value;
14
+ if (typeof method === 'function') {
15
+ await decorator(method.bind(self, ...args));
16
+ }
17
+ },
18
+ };
19
+ }
20
+
21
+ return result as MethodDecorator;
22
+ }
@@ -0,0 +1,10 @@
1
+ import {
2
+ TestRunner,
3
+ TestRunnerOptions,
4
+ } from '../test-runner';
5
+
6
+ export function Describe(options: TestRunnerOptions = {}): ClassDecorator {
7
+ return (target: any): void => {
8
+ TestRunner.run(target, options);
9
+ };
10
+ }
@@ -0,0 +1,17 @@
1
+ import { expect } from '../expection';
2
+ import { createTestDecorator } from './decorate-test';
3
+
4
+ export function ExpectException(error: Class<any, any[]>): MethodDecorator {
5
+ return createTestDecorator(async(method: () => Promise<void>) => {
6
+ let isThrowError = false;
7
+
8
+ try {
9
+ await method();
10
+ } catch (err: unknown) {
11
+ isThrowError = true;
12
+ expect(err).toBeInstanceOf(error);
13
+ } finally {
14
+ expect(isThrowError).toBeTruthy();
15
+ }
16
+ });
17
+ }
@@ -0,0 +1,3 @@
1
+ export * from './expect-error.decorator';
2
+ export * from './describe.decorator';
3
+ export * from './test.decorator';
@@ -0,0 +1,23 @@
1
+ import type { TestSuite } from '../test-suite';
2
+
3
+
4
+ export type MethodName = string | symbol;
5
+ export type Options = {
6
+ name?: string;
7
+ only?: boolean;
8
+ skip?: boolean;
9
+ todo?: boolean;
10
+ };
11
+ export type Method<Arguments extends any[] = never> = (...args: Arguments) => Promise<void> | void;
12
+
13
+ export function Test(options: Options = {}): MethodDecorator {
14
+ return (
15
+ target: Object,
16
+ propertyKey: MethodName,
17
+ ): void => {
18
+ const suite = target as TestSuite;
19
+
20
+ suite.testsMap ??= new Map();
21
+ suite.testsMap.set(propertyKey, options);
22
+ };
23
+ }
@@ -0,0 +1,13 @@
1
+ import expectFunc from 'expect';
2
+
3
+ (global as any).expect = expectFunc;
4
+
5
+ declare global {
6
+ const expect: typeof expectFunc;
7
+ }
8
+
9
+ declare namespace jest {
10
+ export type Mock = any;
11
+ }
12
+
13
+ export { expectFunc as expect };
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import '@hg-ts/types';
2
+
3
+ export { Describe, Test, ExpectException } from './decorators';
4
+
5
+ export { TestSuite } from './test-suite';
6
+ export { expect } from './expection';
@@ -0,0 +1,117 @@
1
+ import { expect } from './expection';
2
+ import type {
3
+ ExclusiveSuiteFunction,
4
+ ExclusiveTestFunction,
5
+ PendingSuiteFunction,
6
+ PendingTestFunction,
7
+ SuiteFunction,
8
+ TestFunction,
9
+ } from 'mocha';
10
+ import type {
11
+ MethodName,
12
+ Options,
13
+ } from './decorators';
14
+ import type { TestSuite, TestSuiteConstructor } from './test-suite';
15
+
16
+ export type TestRunnerOptions = {
17
+ name?: string;
18
+ only?: boolean;
19
+ skip?: boolean;
20
+ };
21
+
22
+ export type TestMethod = (...args: unknown[]) => Promise<void>;
23
+ type Describe = ExclusiveSuiteFunction | PendingSuiteFunction | SuiteFunction;
24
+ type ItFunction = ExclusiveTestFunction | PendingTestFunction | TestFunction;
25
+
26
+ export class TestRunner {
27
+ public static run(
28
+ suiteConstructor: TestSuiteConstructor,
29
+ options: TestRunnerOptions = {},
30
+ ): void {
31
+ const suite = new suiteConstructor();
32
+ suite.testsMap = suiteConstructor.prototype.testsMap;
33
+ const { name = suite.constructor.name } = options;
34
+
35
+ const describeFunction = this.getDescribeFunction(options);
36
+
37
+ describeFunction(name, this.describe.bind(this, suite));
38
+ }
39
+
40
+ private static getDescribeFunction(options: TestRunnerOptions = {}): Describe {
41
+ const {
42
+ only = false,
43
+ skip = false,
44
+ } = options;
45
+
46
+ let describeFunction: Describe = describe;
47
+
48
+ if (only) {
49
+ describeFunction = describe.only;
50
+ } else if (skip) {
51
+ describeFunction = describe.skip;
52
+ }
53
+
54
+ return describeFunction;
55
+ }
56
+
57
+ private static describe(suite: TestSuite): void {
58
+ before(async() => suite.setUp());
59
+ after(async() => suite.tearDown());
60
+
61
+ beforeEach(async() => suite.beforeEach());
62
+ afterEach(async() => {
63
+ expect.setState({
64
+ assertionCalls: 0,
65
+ expectedAssertionsNumber: null,
66
+ isExpectingAssertions: false,
67
+ });
68
+ await suite.afterEach();
69
+ });
70
+
71
+ if (!suite.testsMap) {
72
+ suite.testsMap = new Map();
73
+ }
74
+
75
+ suite.testsMap.forEach((options, methodName) => this.registerTests(suite, options, methodName));
76
+ }
77
+
78
+ private static registerTests(suite: TestSuite, options: Options, testName: MethodName): void {
79
+ const { name = testName.toString() } = options;
80
+
81
+ if (options.todo) {
82
+ it.skip(`TODO: ${name}`);
83
+ return;
84
+ }
85
+
86
+ const method = this.getTestMethod(suite, testName);
87
+
88
+ const registerMethod = this.getTestRegisterMethod(options);
89
+
90
+ registerMethod(name, method);
91
+ }
92
+
93
+ private static getTestMethod(suite: TestSuite, methodName: MethodName): TestMethod {
94
+ const testMethod = ((suite as any)[methodName] as (...args: unknown[]) => Promise<void>).bind(suite);
95
+
96
+ return async(...args: any[]): Promise<void> => {
97
+ await testMethod(...args);
98
+ const { expectedAssertionsNumber, assertionCalls } = expect.getState();
99
+
100
+ if (typeof expectedAssertionsNumber === 'number') {
101
+ expect(assertionCalls).toBe(expectedAssertionsNumber);
102
+ }
103
+ };
104
+ }
105
+
106
+ private static getTestRegisterMethod(options: Options): ItFunction {
107
+ let registerMethod: ItFunction = it;
108
+
109
+ if (options.skip) {
110
+ registerMethod = it.skip;
111
+ } else if (options.only) {
112
+ registerMethod = it.only;
113
+ }
114
+
115
+ return registerMethod;
116
+ }
117
+ }
@@ -0,0 +1,17 @@
1
+ import type {
2
+ MethodName,
3
+ Options,
4
+ } from './decorators';
5
+
6
+ export type TestSuiteConstructor = new () => TestSuite;
7
+ export abstract class TestSuite {
8
+ public testsMap: Map<MethodName, Options> | null;
9
+
10
+ public async setUp(): Promise<void> {}
11
+
12
+ public async tearDown(): Promise<void> {}
13
+
14
+ public async beforeEach(): Promise<void> {}
15
+
16
+ public async afterEach(): Promise<void> {}
17
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@hg-ts-config/typescript/esm",
3
+ "compilerOptions": {
4
+ "baseUrl": "src",
5
+ "rootDir": "src",
6
+ "outDir": "dist-esm"
7
+ },
8
+ "exclude": ["dist-esm", "dist"]
9
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@hg-ts-config/typescript",
3
+ "compilerOptions": {
4
+ "module": "CommonJS",
5
+ "baseUrl": "src",
6
+ "rootDir": "src",
7
+ "outDir": "dist"
8
+ },
9
+ "exclude": ["dist-esm", "dist"]
10
+ }