nole 2.2.1 → 3.0.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.
Files changed (112) hide show
  1. package/README.md +142 -236
  2. package/bin/nole.js +44 -42
  3. package/dist/const.d.ts +8 -0
  4. package/dist/const.d.ts.map +1 -0
  5. package/dist/const.js +9 -0
  6. package/dist/core.d.ts +22 -0
  7. package/dist/core.d.ts.map +1 -0
  8. package/dist/core.js +56 -0
  9. package/dist/dynamic.d.ts +4 -1
  10. package/dist/dynamic.d.ts.map +1 -1
  11. package/dist/dynamic.js +35 -11
  12. package/dist/handle/after-each-hooks.d.ts +3 -0
  13. package/dist/handle/after-each-hooks.d.ts.map +1 -0
  14. package/dist/handle/after-each-hooks.js +26 -0
  15. package/dist/handle/after-hooks.d.ts +3 -0
  16. package/dist/handle/after-hooks.d.ts.map +1 -0
  17. package/dist/handle/after-hooks.js +24 -0
  18. package/dist/handle/before-each-hooks.d.ts +3 -0
  19. package/dist/handle/before-each-hooks.d.ts.map +1 -0
  20. package/dist/handle/before-each-hooks.js +26 -0
  21. package/dist/handle/before-hooks.d.ts +3 -0
  22. package/dist/handle/before-hooks.d.ts.map +1 -0
  23. package/dist/handle/before-hooks.js +24 -0
  24. package/dist/handle/cleanup-hooks.d.ts +3 -0
  25. package/dist/handle/cleanup-hooks.d.ts.map +1 -0
  26. package/dist/handle/cleanup-hooks.js +34 -0
  27. package/dist/handle/specs.d.ts +3 -0
  28. package/dist/handle/specs.d.ts.map +1 -0
  29. package/dist/handle/specs.js +41 -0
  30. package/dist/index.d.ts +3 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -4
  33. package/dist/run.d.ts +7 -6
  34. package/dist/run.d.ts.map +1 -1
  35. package/dist/run.js +201 -239
  36. package/dist/symbol.d.ts +2 -0
  37. package/dist/symbol.d.ts.map +1 -0
  38. package/dist/symbol.js +2 -0
  39. package/dist/test-wrap.d.ts +37 -0
  40. package/dist/test-wrap.d.ts.map +1 -0
  41. package/dist/test-wrap.js +30 -0
  42. package/dist/utils/executor.d.ts +1 -1
  43. package/dist/utils/executor.js +20 -20
  44. package/dist/utils/executor.test.d.ts +7 -5
  45. package/dist/utils/executor.test.d.ts.map +1 -1
  46. package/dist/utils/executor.test.js +22 -49
  47. package/dist/utils/time_difference.d.ts +15 -6
  48. package/dist/utils/time_difference.d.ts.map +1 -1
  49. package/dist/utils/time_difference.js +22 -13
  50. package/dist/utils/time_difference.test.d.ts +5 -3
  51. package/dist/utils/time_difference.test.d.ts.map +1 -1
  52. package/dist/utils/time_difference.test.js +11 -24
  53. package/dist/utils/time_factor.d.ts +3 -3
  54. package/dist/utils/time_factor.d.ts.map +1 -1
  55. package/dist/utils/time_factor.js +26 -27
  56. package/dist/utils/time_factor.test.d.ts +5 -3
  57. package/dist/utils/time_factor.test.d.ts.map +1 -1
  58. package/dist/utils/time_factor.test.js +27 -42
  59. package/package.json +11 -8
  60. package/src/const.ts +11 -0
  61. package/src/core.ts +89 -0
  62. package/src/dynamic.ts +43 -1
  63. package/src/handle/after-each-hooks.ts +41 -0
  64. package/src/handle/after-hooks.ts +38 -0
  65. package/src/handle/before-each-hooks.ts +40 -0
  66. package/src/handle/before-hooks.ts +39 -0
  67. package/src/handle/cleanup-hooks.ts +55 -0
  68. package/src/handle/specs.ts +68 -0
  69. package/src/index.ts +3 -13
  70. package/src/run.ts +184 -256
  71. package/src/symbol.ts +1 -0
  72. package/src/{test.ts → test-wrap.ts} +13 -12
  73. package/src/utils/executor.test.ts +2 -5
  74. package/src/utils/executor.ts +1 -1
  75. package/src/utils/time_difference.test.ts +2 -3
  76. package/src/utils/time_factor.test.ts +2 -3
  77. package/src/utils/time_factor.ts +1 -3
  78. package/test/basic.test.ts +8 -9
  79. package/test/before.test.ts +14 -27
  80. package/test/clean-up.test.ts +12 -16
  81. package/test/dynamic-skip.test.ts +2 -4
  82. package/test/dynamic.test.ts +23 -8
  83. package/test/extend.test.ts +43 -0
  84. package/test/hook.test.ts +9 -10
  85. package/test/multi-dependency.test.ts +25 -27
  86. package/test/multiple-uppercased-chars.test.ts +8 -7
  87. package/test/skip-all.test.ts +4 -13
  88. package/test/turkish-chars.test.ts +8 -7
  89. package/tsconfig.json +9 -18
  90. package/dist/data.d.ts +0 -3
  91. package/dist/data.d.ts.map +0 -1
  92. package/dist/data.js +0 -9
  93. package/dist/data.js.map +0 -1
  94. package/dist/decorators.d.ts +0 -9
  95. package/dist/decorators.d.ts.map +0 -1
  96. package/dist/decorators.js +0 -118
  97. package/dist/decorators.js.map +0 -1
  98. package/dist/dynamic.js.map +0 -1
  99. package/dist/index.js.map +0 -1
  100. package/dist/run.js.map +0 -1
  101. package/dist/test.d.ts +0 -39
  102. package/dist/test.d.ts.map +0 -1
  103. package/dist/test.js +0 -25
  104. package/dist/test.js.map +0 -1
  105. package/dist/utils/executor.js.map +0 -1
  106. package/dist/utils/executor.test.js.map +0 -1
  107. package/dist/utils/time_difference.js.map +0 -1
  108. package/dist/utils/time_difference.test.js.map +0 -1
  109. package/dist/utils/time_factor.js.map +0 -1
  110. package/dist/utils/time_factor.test.js.map +0 -1
  111. package/src/data.ts +0 -13
  112. package/src/decorators.ts +0 -208
@@ -0,0 +1,40 @@
1
+ import { HookType, TestWrap } from "../test-wrap.js";
2
+ import { Executor } from "../utils/executor.js";
3
+ import { TimeFactor } from "../utils/time_factor.js";
4
+ import {
5
+ colors,
6
+ DEFAULT_TIMEOUT,
7
+ HOOK_FAILED_TEXT,
8
+ OK_TEXT,
9
+ } from "../const.js";
10
+
11
+ export async function handleBeforeEachHooks(test: TestWrap) {
12
+ const timeout = test.config.timeout ?? DEFAULT_TIMEOUT;
13
+
14
+ for (let [propertyKey, hook] of test.hooks.entries()) {
15
+ if (hook.type != HookType.BeforeEach) continue;
16
+ let hookName = colors.bold(
17
+ colors.yellow(
18
+ test.name +
19
+ (propertyKey != "beforeEach"
20
+ ? `.${propertyKey}:beforeEach`
21
+ : ":beforeEach"),
22
+ ),
23
+ );
24
+
25
+ try {
26
+ await Executor(
27
+ test.testInstance[propertyKey].bind(test.testInstance),
28
+ timeout,
29
+ );
30
+
31
+ let timeText = TimeFactor(0, timeout);
32
+
33
+ console.log(`${OK_TEXT} ${timeText} ${hookName}()`);
34
+ } catch (e) {
35
+ console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
36
+ console.error((e as any)?.stack ?? e);
37
+ throw e;
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,39 @@
1
+ import { HookType, TestWrap } from "../test-wrap.js";
2
+ import { Executor } from "../utils/executor.js";
3
+ import { TimeFactor } from "../utils/time_factor.js";
4
+ import {
5
+ colors,
6
+ DEFAULT_TIMEOUT,
7
+ HOOK_FAILED_TEXT,
8
+ OK_TEXT,
9
+ } from "../const.js";
10
+
11
+ export async function handleBeforeHooks(test: TestWrap) {
12
+ const timeout = test.config.timeout ?? DEFAULT_TIMEOUT;
13
+
14
+ for (let [propertyKey, hook] of test.hooks.entries()) {
15
+ if (hook.type != HookType.Before) continue;
16
+
17
+ let hookName = colors.bold(
18
+ colors.yellow(
19
+ test.name +
20
+ (propertyKey != "before" ? `.${propertyKey}:before` : ":before"),
21
+ ),
22
+ );
23
+
24
+ try {
25
+ await Executor(
26
+ test.testInstance[propertyKey].bind(test.testInstance),
27
+ timeout,
28
+ );
29
+
30
+ let timeText = TimeFactor(0, timeout);
31
+
32
+ console.log(`${OK_TEXT} ${timeText} ${hookName}()`);
33
+ } catch (e) {
34
+ console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
35
+ console.error((e as any)?.stack ?? e);
36
+ throw e;
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,55 @@
1
+ import { HookType, TestWrap } from "../test-wrap.js";
2
+ import { Executor } from "../utils/executor.js";
3
+ import { TimeDifference } from "../utils/time_difference.js";
4
+ import { TimeFactor } from "../utils/time_factor.js";
5
+ import {
6
+ colors,
7
+ DEFAULT_TIMEOUT,
8
+ HOOK_FAILED_TEXT,
9
+ OK_TEXT,
10
+ } from "../const.js";
11
+
12
+ export async function handleCleanUp(test: TestWrap) {
13
+ const timeout = test.config.timeout ?? DEFAULT_TIMEOUT;
14
+
15
+ if (test.cleanUpCalled) return;
16
+ if (
17
+ !test.dependents.every(
18
+ (dependent) => dependent.isFinished && dependent.cleanUpCalled,
19
+ )
20
+ )
21
+ return;
22
+
23
+ test.cleanUpCalled = true;
24
+
25
+ for (let [propertyKey, hook] of test.hooks.entries()) {
26
+ if (hook.type != HookType.CleanUp) continue;
27
+
28
+ let hookName = colors.bold(
29
+ colors.yellow(
30
+ test.name +
31
+ (propertyKey != "cleanUp" ? `.${propertyKey}:cleanUp` : ":cleanUp"),
32
+ ),
33
+ );
34
+ let start = TimeDifference.begin();
35
+
36
+ try {
37
+ await Executor(
38
+ test.testInstance[propertyKey].bind(test.testInstance),
39
+ timeout,
40
+ );
41
+
42
+ let timeText = TimeFactor(start.end(), timeout);
43
+
44
+ console.log(`${OK_TEXT} ${timeText} ${hookName}()`);
45
+ } catch (e) {
46
+ console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
47
+ console.error((e as any)?.stack ?? e);
48
+ throw e;
49
+ }
50
+ }
51
+
52
+ for (let tree of test.dependencies) {
53
+ await handleCleanUp(tree.dependency);
54
+ }
55
+ }
@@ -0,0 +1,68 @@
1
+ import { HookType, TestWrap } from "../test-wrap.js";
2
+ import { Executor } from "../utils/executor.js";
3
+ import { TimeDifference } from "../utils/time_difference.js";
4
+ import { TimeFactor } from "../utils/time_factor.js";
5
+ import { handleAfterEachHooks } from "./after-each-hooks.js";
6
+ import { handleBeforeEachHooks } from "./before-each-hooks.js";
7
+ import {
8
+ colors,
9
+ DEFAULT_TIMEOUT,
10
+ DYNAMIC_SKIP_TEXT,
11
+ FAILED_TEXT,
12
+ OK_TEXT,
13
+ SKIP_TEXT,
14
+ } from "../const.js";
15
+
16
+ export async function handleSpecs(test: TestWrap) {
17
+ const timeout = test.config.timeout ?? DEFAULT_TIMEOUT;
18
+
19
+ for (let [propertyKey, spec] of test.specs.entries()) {
20
+ let testName = colors.bold(colors.yellow(test.name + "." + propertyKey));
21
+
22
+ const shouldPropertySkip = test.skip.has(propertyKey);
23
+ if (shouldPropertySkip || test.skipClass) {
24
+ let reason = shouldPropertySkip
25
+ ? test.skip.get(propertyKey)!.reason
26
+ : test.skipClass!.reason;
27
+ console.log(
28
+ `${SKIP_TEXT} ${" ".repeat(9)} ${testName}() ${
29
+ reason ? "{" + reason + "}" : ""
30
+ }`,
31
+ );
32
+ continue;
33
+ }
34
+
35
+ await handleBeforeEachHooks(test);
36
+
37
+ let start = TimeDifference.begin();
38
+
39
+ try {
40
+ await Executor(
41
+ test.testInstance[propertyKey].bind(test.testInstance),
42
+ timeout,
43
+ );
44
+
45
+ let timeText = TimeFactor(start.end(), timeout);
46
+
47
+ console.log(`${OK_TEXT} ${timeText} ${testName}()`);
48
+ } catch (e) {
49
+ if ((e as any)?._nole_anchor) {
50
+ let reason = (e as any).reason;
51
+ console.log(
52
+ `${DYNAMIC_SKIP_TEXT} ${" ".repeat(8)} ${testName}() ${
53
+ reason ? "{" + reason + "}" : ""
54
+ }`,
55
+ );
56
+ continue;
57
+ }
58
+
59
+ let timeText = TimeFactor(start.end(), timeout);
60
+
61
+ console.error(`${FAILED_TEXT} ${timeText} ${testName}()`);
62
+ console.error((e as any)?.stack ?? e);
63
+ throw e;
64
+ }
65
+
66
+ await handleAfterEachHooks(test);
67
+ }
68
+ }
package/src/index.ts CHANGED
@@ -1,13 +1,3 @@
1
- export {
2
- Dependency,
3
- Spec,
4
- Hook,
5
- Skip,
6
- SkipClass,
7
- Dependencies,
8
- Dependencies as After,
9
- Dependents as Before,
10
- Dependents,
11
- } from "./decorators.js";
12
- export { HookType } from "./test.js";
13
- export { skipTest } from "./dynamic.js";
1
+ export { HookType } from "./test-wrap.js";
2
+ export { Test } from "./core.js";
3
+ export { skipTest, getTest, addTest } from "./dynamic.js";