nole 3.0.0 → 3.2.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 (84) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +514 -294
  3. package/bin/nole.js +145 -110
  4. package/dist/cjs/const.js +45 -0
  5. package/dist/cjs/core.js +61 -0
  6. package/dist/cjs/dynamic.js +56 -0
  7. package/dist/cjs/handle/after-each-hooks.js +29 -0
  8. package/dist/cjs/handle/after-hooks.js +27 -0
  9. package/dist/cjs/handle/before-each-hooks.js +29 -0
  10. package/dist/cjs/handle/before-hooks.js +37 -0
  11. package/dist/cjs/handle/cleanup-hooks.js +37 -0
  12. package/dist/cjs/handle/specs.js +52 -0
  13. package/dist/cjs/index.js +14 -0
  14. package/dist/cjs/package.json +1 -0
  15. package/dist/cjs/run.js +216 -0
  16. package/dist/cjs/symbol.js +6 -0
  17. package/dist/cjs/test-wrap.js +33 -0
  18. package/dist/cjs/utils/executor.js +23 -0
  19. package/dist/cjs/utils/time_difference.js +26 -0
  20. package/dist/cjs/utils/time_factor.js +31 -0
  21. package/dist/core.d.ts +3 -1
  22. package/dist/core.d.ts.map +1 -1
  23. package/dist/core.js +2 -2
  24. package/dist/dynamic.d.ts +2 -0
  25. package/dist/dynamic.d.ts.map +1 -1
  26. package/dist/dynamic.js +16 -1
  27. package/dist/handle/before-hooks.d.ts.map +1 -1
  28. package/dist/handle/before-hooks.js +12 -2
  29. package/dist/handle/specs.d.ts.map +1 -1
  30. package/dist/handle/specs.js +12 -3
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -2
  34. package/dist/run.d.ts.map +1 -1
  35. package/dist/run.js +16 -7
  36. package/dist/symbol.d.ts +1 -0
  37. package/dist/symbol.d.ts.map +1 -1
  38. package/dist/symbol.js +3 -2
  39. package/dist/test-wrap.d.ts +1 -0
  40. package/dist/test-wrap.d.ts.map +1 -1
  41. package/dist/test-wrap.js +1 -1
  42. package/dist/utils/time_difference.d.ts.map +1 -1
  43. package/package.json +68 -57
  44. package/dist/utils/executor.test.d.ts +0 -8
  45. package/dist/utils/executor.test.d.ts.map +0 -1
  46. package/dist/utils/executor.test.js +0 -22
  47. package/dist/utils/time_difference.test.d.ts +0 -6
  48. package/dist/utils/time_difference.test.d.ts.map +0 -1
  49. package/dist/utils/time_difference.test.js +0 -11
  50. package/dist/utils/time_factor.test.d.ts +0 -6
  51. package/dist/utils/time_factor.test.d.ts.map +0 -1
  52. package/dist/utils/time_factor.test.js +0 -27
  53. package/src/const.ts +0 -11
  54. package/src/core.ts +0 -89
  55. package/src/dynamic.ts +0 -53
  56. package/src/handle/after-each-hooks.ts +0 -41
  57. package/src/handle/after-hooks.ts +0 -38
  58. package/src/handle/before-each-hooks.ts +0 -40
  59. package/src/handle/before-hooks.ts +0 -39
  60. package/src/handle/cleanup-hooks.ts +0 -55
  61. package/src/handle/specs.ts +0 -68
  62. package/src/index.ts +0 -3
  63. package/src/run.ts +0 -259
  64. package/src/symbol.ts +0 -1
  65. package/src/test-wrap.ts +0 -48
  66. package/src/utils/executor.test.ts +0 -24
  67. package/src/utils/executor.ts +0 -22
  68. package/src/utils/time_difference.test.ts +0 -11
  69. package/src/utils/time_difference.ts +0 -26
  70. package/src/utils/time_factor.test.ts +0 -28
  71. package/src/utils/time_factor.ts +0 -33
  72. package/test/basic.test.ts +0 -23
  73. package/test/before.test.ts +0 -41
  74. package/test/clean-up.test.ts +0 -48
  75. package/test/dynamic-skip.test.ts +0 -6
  76. package/test/dynamic.test.ts +0 -28
  77. package/test/extend.test.ts +0 -43
  78. package/test/hook.test.ts +0 -26
  79. package/test/multi-dependency.test.ts +0 -43
  80. package/test/multiple-uppercased-chars.test.ts +0 -20
  81. package/test/skip-all.test.ts +0 -10
  82. package/test/tsconfig.json +0 -24
  83. package/test/turkish-chars.test.ts +0 -20
  84. package/tsconfig.json +0 -16
@@ -1,41 +0,0 @@
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 handleAfterEachHooks(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.AfterEach) continue;
16
-
17
- let hookName = colors.bold(
18
- colors.yellow(
19
- test.name +
20
- (propertyKey != "afterEach"
21
- ? `.${propertyKey}:afterEach`
22
- : ":afterEach"),
23
- ),
24
- );
25
-
26
- try {
27
- await Executor(
28
- test.testInstance[propertyKey].bind(test.testInstance),
29
- timeout,
30
- );
31
-
32
- let timeText = TimeFactor(0, timeout);
33
-
34
- console.log(`${OK_TEXT} ${timeText} ${hookName}()`);
35
- } catch (e) {
36
- console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
37
- console.error((e as any)?.stack ?? e);
38
- throw e;
39
- }
40
- }
41
- }
@@ -1,38 +0,0 @@
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 handleAfterHooks(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.After) continue;
16
-
17
- let hookName = colors.bold(
18
- colors.yellow(
19
- test.name +
20
- (propertyKey != "after" ? `.${propertyKey}:after` : ":after"),
21
- ),
22
- );
23
-
24
- try {
25
- await Executor(
26
- test.testInstance[propertyKey].bind(test.testInstance),
27
- timeout,
28
- );
29
- let timeText = TimeFactor(0, timeout);
30
-
31
- console.log(`${OK_TEXT} ${timeText} ${hookName}()`);
32
- } catch (e) {
33
- console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
34
- console.error((e as any)?.stack ?? e);
35
- throw e;
36
- }
37
- }
38
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,39 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
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
- }
@@ -1,68 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- export { HookType } from "./test-wrap.js";
2
- export { Test } from "./core.js";
3
- export { skipTest, getTest, addTest } from "./dynamic.js";
package/src/run.ts DELETED
@@ -1,259 +0,0 @@
1
- import { HookType, TestWrap } from "./test-wrap.js";
2
- import { BaseTest, type TestClassInfo } from "./core.js";
3
- import { TEST_CLASS_KEY } from "./symbol.js";
4
- import { handleBeforeHooks } from "./handle/before-hooks.js";
5
- import { handleSpecs } from "./handle/specs.js";
6
- import { handleAfterHooks } from "./handle/after-hooks.js";
7
- import { handleCleanUp } from "./handle/cleanup-hooks.js";
8
- import { colors, FAILED_TEXT } from "./const.js";
9
-
10
- let allTests: Map<new () => BaseTest, TestWrap> = new Map();
11
- let notTestedYet: Map<new () => BaseTest, TestWrap> = new Map();
12
-
13
- export async function ManualRun(originalTests: Set<new () => BaseTest>) {
14
- for (let test of originalTests) {
15
- if (allTests.has(test)) {
16
- continue;
17
- }
18
-
19
- const wrap = new TestWrap(test);
20
-
21
- allTests.set(test, wrap);
22
- notTestedYet.set(test, wrap);
23
- }
24
-
25
- extractInformationFromClasses(notTestedYet);
26
-
27
- if (!notTestedYet.size) {
28
- throw new Error("No specs found");
29
- }
30
-
31
- while (notTestedYet.size) {
32
- let entry = pickNext(notTestedYet);
33
-
34
- if (entry) {
35
- let test = entry[1];
36
- // console.log(colors.bold(colors.cyan(`Running test: ${test.name}`)));
37
-
38
- notTestedYet.delete(test.target);
39
- createInstanceIfNotExists(test);
40
- handleDependencies(test);
41
-
42
- await handleBeforeHooks(test);
43
- await handleSpecs(test);
44
- await handleAfterHooks(test);
45
-
46
- test.isFinished = true;
47
-
48
- if (test.dependents.length == 0) {
49
- await handleCleanUp(test);
50
- }
51
- } else {
52
- dependencyLock(notTestedYet);
53
- }
54
- }
55
- }
56
-
57
- function extractInformationFromClasses(
58
- tests: Map<new () => BaseTest, TestWrap>,
59
- ) {
60
- for (let [target, test] of tests.entries()) {
61
- updateInformationForClass(target, test, tests);
62
- }
63
- }
64
-
65
- export function updateInformationForClass(
66
- target: new () => BaseTest,
67
- test: TestWrap,
68
- tests: Map<new () => BaseTest, TestWrap>,
69
- ) {
70
- const config = target[TEST_CLASS_KEY] as TestClassInfo;
71
-
72
- if (config.skip) {
73
- test.skipClass = { reason: config.skip };
74
- }
75
-
76
- test.dependencies = config.dependencies
77
- ? Array.from(
78
- config.dependencies.entries().map(([key, dep]) => {
79
- const actual = dep();
80
- let testWrap = tests.get(actual);
81
-
82
- if (!testWrap) {
83
- testWrap = new TestWrap(actual);
84
- tests.set(actual, testWrap);
85
- allTests.set(actual, testWrap);
86
- }
87
-
88
- testWrap.dependents.push(test);
89
-
90
- return {
91
- propertyKey: key,
92
- dependency: testWrap,
93
- };
94
- }),
95
- )
96
- : [];
97
-
98
- if (config.before) {
99
- const beforeTests = config.before();
100
-
101
- for (let i = 0; i < beforeTests.length; i++) {
102
- const actual = beforeTests[i];
103
-
104
- let testWrap = tests.get(actual);
105
-
106
- if (!testWrap) {
107
- testWrap = new TestWrap(actual);
108
- tests.set(actual, testWrap);
109
- allTests.set(actual, testWrap);
110
- }
111
-
112
- testWrap.dependencies.push({
113
- propertyKey: "_before_" + i,
114
- dependency: test,
115
- });
116
-
117
- test.dependents.push(testWrap);
118
- }
119
- }
120
-
121
- if (config.after) {
122
- const afterTests = config.after();
123
-
124
- for (let i = 0; i < afterTests.length; i++) {
125
- const actual = afterTests[i];
126
-
127
- let testWrap = tests.get(actual);
128
-
129
- if (!testWrap) {
130
- testWrap = new TestWrap(actual);
131
- tests.set(actual, testWrap);
132
- allTests.set(actual, testWrap);
133
- }
134
-
135
- test.dependencies.push({
136
- propertyKey: "_after_" + i,
137
- dependency: testWrap,
138
- });
139
-
140
- testWrap.dependents.push(test);
141
- }
142
- }
143
- }
144
-
145
- function pickNext(tests: Map<new () => BaseTest, TestWrap>) {
146
- for (let entry of tests.entries()) {
147
- let test = entry[1];
148
- if (test.isFinished) continue;
149
- if (!test.dependencies.every((x) => x.dependency.isFinished)) continue;
150
-
151
- return entry;
152
- }
153
- }
154
-
155
- export function createInstanceIfNotExists(test: TestWrap) {
156
- if (!test.testInstance) {
157
- const instance = new test.target();
158
-
159
- test.testInstance = instance;
160
- }
161
-
162
- if (!test.specDetection) {
163
- specDetection(test);
164
- test.specDetection = true;
165
- }
166
- }
167
-
168
- function specDetection(test: TestWrap) {
169
- const instance = test.testInstance;
170
- for (let key of getAllMethods(instance)) {
171
- if (typeof key !== "string") {
172
- continue;
173
- }
174
-
175
- let lowerKey = key.toLowerCase();
176
-
177
- if (lowerKey.startsWith("skip")) {
178
- test.skip.set(key, { reason: "marked as skipped" });
179
- }
180
-
181
- if (
182
- lowerKey.startsWith("hook") ||
183
- lowerKey === "cleanup" ||
184
- lowerKey === "before" ||
185
- lowerKey === "after" ||
186
- lowerKey === "beforeeach" ||
187
- lowerKey === "aftereach"
188
- ) {
189
- let type = HookType.Before;
190
-
191
- if (lowerKey.endsWith("before")) {
192
- type = HookType.Before;
193
- } else if (lowerKey.endsWith("after")) {
194
- type = HookType.After;
195
- } else if (lowerKey.endsWith("beforeeach")) {
196
- type = HookType.BeforeEach;
197
- } else if (lowerKey.endsWith("aftereach")) {
198
- type = HookType.AfterEach;
199
- } else if (lowerKey.endsWith("cleanup")) {
200
- type = HookType.CleanUp;
201
- }
202
-
203
- test.hooks.set(key, { type });
204
- continue;
205
- }
206
-
207
- test.specs.set(key, {});
208
- }
209
- }
210
-
211
- function getAllMethods(instance) {
212
- let props = new Set();
213
- let currentObj = instance;
214
-
215
- while (currentObj && currentObj !== Object.prototype) {
216
- Object.getOwnPropertyNames(currentObj).forEach((prop) => {
217
- if (typeof currentObj[prop] === "function" && prop !== "constructor") {
218
- props.add(prop);
219
- }
220
- });
221
- currentObj = Object.getPrototypeOf(currentObj);
222
- }
223
-
224
- return Array.from(props);
225
- }
226
-
227
- function handleDependencies(test: TestWrap) {
228
- for (let dependency of test.dependencies) {
229
- test.testInstance[dependency.propertyKey] =
230
- dependency.dependency.testInstance;
231
- }
232
- }
233
-
234
- function dependencyLock(tests: Map<new () => BaseTest, TestWrap>) {
235
- console.error(
236
- FAILED_TEXT +
237
- colors.red("Looks like there is confict issue for dependency resolving!"),
238
- );
239
-
240
- console.error("Possible conflicts;");
241
- for (let [, test] of tests) {
242
- console.error(
243
- `- class ${test.name} { ${test.dependencies
244
- .filter((x) => !x.dependency.isFinished)
245
- .map((x) => `@Dependency(${x.dependency.name}) ${x.propertyKey}`)
246
- .join(", ")} }`,
247
- );
248
- }
249
-
250
- throw new Error("Dependency lock occurred!");
251
- }
252
-
253
- export function getTestMap() {
254
- return allTests;
255
- }
256
-
257
- export function getFutureTestMap() {
258
- return notTestedYet;
259
- }
package/src/symbol.ts DELETED
@@ -1 +0,0 @@
1
- export const TEST_CLASS_KEY = Symbol("TEST_CLASS_KEY");
package/src/test-wrap.ts DELETED
@@ -1,48 +0,0 @@
1
- import { BaseTest, type TestClassInfo } from "./core.js";
2
- import { TEST_CLASS_KEY } from "./symbol.js";
3
-
4
- export interface IDependency {
5
- propertyKey: string;
6
- dependency: TestWrap;
7
- }
8
-
9
- export interface ISpec {}
10
-
11
- export interface IHook {
12
- type: HookType;
13
- }
14
-
15
- export interface ISkip {
16
- reason: string;
17
- }
18
-
19
- // Old code, but works fine, so I won't change it for now
20
- export class TestWrap {
21
- dependencies: IDependency[] = [];
22
- dependents: TestWrap[] = [];
23
- skip = new Map<string, ISkip>();
24
- skipClass: ISkip | null = null;
25
- specs = new Map<string, ISpec>();
26
- hooks = new Map<string, IHook>();
27
- isFinished: boolean = false; // cleanup ignored
28
- cleanUpCalled: boolean = false;
29
- testInstance: any;
30
- specDetection: boolean = false;
31
- config: TestClassInfo;
32
-
33
- constructor(public target: new () => BaseTest) {
34
- this.config = target[TEST_CLASS_KEY];
35
- }
36
-
37
- get name() {
38
- return this.target.name;
39
- }
40
- }
41
-
42
- export enum HookType {
43
- Before, // Trigger when test case is ready to handle
44
- After, // Trigger when test case did all the specs
45
- BeforeEach, // Trigger before each spec
46
- AfterEach, // Trigger after each spec
47
- CleanUp, // Trigger after all dependents tested (You can safely remove connections etc.)
48
- }
@@ -1,24 +0,0 @@
1
- import * as assert from "assert";
2
- import { Executor } from "./executor.js";
3
- import { Test } from "../index.js";
4
-
5
- export class ExecutorTest extends Test() {
6
- async evaluate() {
7
- await Executor(() => 1, 1);
8
- await Executor(async () => 1, 1);
9
- }
10
-
11
- async throws() {
12
- await assert.rejects(() => {
13
- return Executor(() => {
14
- throw new Error("throws");
15
- }, 1);
16
- });
17
- }
18
-
19
- async timeout() {
20
- await assert.rejects(() => {
21
- return Executor(() => new Promise(() => {}), 10);
22
- });
23
- }
24
- }
@@ -1,22 +0,0 @@
1
- export function Executor(fn: Function, timeout: number): Promise<void> {
2
- return new Promise(async (resolve, reject) => {
3
- let _timeout: NodeJS.Timeout | null = null;
4
-
5
- try {
6
- let expectPromise = fn();
7
- if (expectPromise && expectPromise.then) {
8
- _timeout = setTimeout(function () {
9
- reject(new Error("Timeout occurred! value: " + timeout));
10
- }, timeout);
11
-
12
- await expectPromise;
13
- }
14
- } catch (e) {
15
- reject(e);
16
- }
17
-
18
- clearTimeout(_timeout!);
19
-
20
- resolve();
21
- });
22
- }
@@ -1,11 +0,0 @@
1
- import * as assert from "assert";
2
- import { Test } from "../index.js";
3
- import { Executor } from "./executor.js";
4
- import { TimeDifference } from "./time_difference.js";
5
-
6
- export class TimeDifferenceTest extends Test() {
7
- async evaluate() {
8
- const td = TimeDifference.begin();
9
- td.end();
10
- }
11
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Calculates the time difference in nanoseconds
3
- */
4
- export class TimeDifference {
5
- private startAt: [number, number];
6
-
7
- private constructor() {
8
- this.startAt = process.hrtime();
9
- }
10
-
11
- /**
12
- * Creates the instance at the begining
13
- */
14
- public static begin() {
15
- return new TimeDifference();
16
- }
17
-
18
- /**
19
- * Finishes the time, returns data in milliseconds
20
- */
21
- end(): number {
22
- let diff = process.hrtime(this.startAt);
23
-
24
- return diff[0] * 1000 + diff[1] / 1e6;
25
- }
26
- }