nole 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yaml +34 -0
- package/LICENSE.md +21 -0
- package/README.md +474 -294
- package/bin/nole.js +145 -110
- package/dist/core.js +1 -1
- package/dist/dynamic.d.ts +1 -0
- package/dist/dynamic.d.ts.map +1 -1
- package/dist/dynamic.js +11 -1
- package/dist/handle/before-hooks.d.ts.map +1 -1
- package/dist/handle/before-hooks.js +12 -2
- package/dist/handle/specs.d.ts.map +1 -1
- package/dist/handle/specs.js +12 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/pipeline.test.d.ts +7 -0
- package/dist/pipeline.test.d.ts.map +1 -0
- package/dist/pipeline.test.js +124 -0
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +14 -6
- package/dist/symbol.d.ts.map +1 -1
- package/dist/symbol.js +2 -2
- package/dist/test-wrap.d.ts +1 -0
- package/dist/test-wrap.d.ts.map +1 -1
- package/dist/test-wrap.js +1 -1
- package/dist/utils/executor.test.d.ts.map +1 -1
- package/dist/utils/time_difference.d.ts.map +1 -1
- package/dist/utils/time_difference.test.d.ts.map +1 -1
- package/dist/utils/time_factor.test.d.ts.map +1 -1
- package/package.json +57 -57
- package/tsconfig.json +18 -16
- package/src/const.ts +0 -11
- package/src/core.ts +0 -89
- package/src/dynamic.ts +0 -53
- package/src/handle/after-each-hooks.ts +0 -41
- package/src/handle/after-hooks.ts +0 -38
- package/src/handle/before-each-hooks.ts +0 -40
- package/src/handle/before-hooks.ts +0 -39
- package/src/handle/cleanup-hooks.ts +0 -55
- package/src/handle/specs.ts +0 -68
- package/src/index.ts +0 -3
- package/src/run.ts +0 -259
- package/src/symbol.ts +0 -1
- package/src/test-wrap.ts +0 -48
- package/src/utils/executor.test.ts +0 -24
- package/src/utils/executor.ts +0 -22
- package/src/utils/time_difference.test.ts +0 -11
- package/src/utils/time_difference.ts +0 -26
- package/src/utils/time_factor.test.ts +0 -28
- package/src/utils/time_factor.ts +0 -33
- package/test/basic.test.ts +0 -23
- package/test/before.test.ts +0 -41
- package/test/clean-up.test.ts +0 -48
- package/test/dynamic-skip.test.ts +0 -6
- package/test/dynamic.test.ts +0 -28
- package/test/extend.test.ts +0 -43
- package/test/hook.test.ts +0 -26
- package/test/multi-dependency.test.ts +0 -43
- package/test/multiple-uppercased-chars.test.ts +0 -20
- package/test/skip-all.test.ts +0 -10
- package/test/tsconfig.json +0 -24
- package/test/turkish-chars.test.ts +0 -20
|
@@ -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
|
-
}
|
package/src/handle/specs.ts
DELETED
|
@@ -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
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
|
-
}
|
package/src/utils/executor.ts
DELETED
|
@@ -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
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Test } from "../index.js";
|
|
2
|
-
import { Delay, TimeFactor } from "./time_factor.js";
|
|
3
|
-
|
|
4
|
-
export class TimeFactorTest extends Test() {
|
|
5
|
-
async evaluate() {
|
|
6
|
-
await Delay(1);
|
|
7
|
-
|
|
8
|
-
for (const n of [
|
|
9
|
-
100,
|
|
10
|
-
1000,
|
|
11
|
-
60 * 1000,
|
|
12
|
-
120 * 1000,
|
|
13
|
-
60 * 60 * 1000,
|
|
14
|
-
65 * 60 * 1000,
|
|
15
|
-
25 * 60 * 60 * 1000,
|
|
16
|
-
]) {
|
|
17
|
-
TimeFactor(n / 1000, n);
|
|
18
|
-
TimeFactor(n / 500, n);
|
|
19
|
-
TimeFactor(n / 10, n);
|
|
20
|
-
TimeFactor(n / 6, n);
|
|
21
|
-
TimeFactor(n / 4, n);
|
|
22
|
-
TimeFactor(n / 2, n);
|
|
23
|
-
TimeFactor(n / 1.5, n);
|
|
24
|
-
TimeFactor(n, n);
|
|
25
|
-
TimeFactor(n * 2, n);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/utils/time_factor.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { colors } from "../const.js";
|
|
2
|
-
|
|
3
|
-
export function TimeFactor(diff: number, timeout: number) {
|
|
4
|
-
if (diff < timeout / 5) {
|
|
5
|
-
return colors.green(TimeResolve(diff).padStart(9, " "));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (diff < timeout / 2) {
|
|
9
|
-
return colors.yellow(TimeResolve(diff).padStart(9, " "));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return colors.red(TimeResolve(diff).padStart(9, " "));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function TimeResolve(ms: number) {
|
|
16
|
-
if (ms < 1000) {
|
|
17
|
-
return ((ms * 100) | 0) / 100 + " ms";
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (ms < 60 * 1000) {
|
|
21
|
-
return ((ms / 10) | 0) / 100 + " s";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (ms < 60 * 60 * 1000) {
|
|
25
|
-
return ((ms / 600) | 0) / 100 + " m";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return ((ms / 36000) | 0) / 100 + " h";
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function Delay(ms: number): Promise<void> {
|
|
32
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33
|
-
}
|
package/test/basic.test.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Test } from "../dist/index.js";
|
|
2
|
-
|
|
3
|
-
class BasicTest extends Test({ timeout: 750 }) {
|
|
4
|
-
variable = 1;
|
|
5
|
-
|
|
6
|
-
async checkEqual() {
|
|
7
|
-
await new Promise((resolve) => {
|
|
8
|
-
setTimeout(resolve, 500);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class DependencyTest extends Test({
|
|
14
|
-
dependencies: {
|
|
15
|
-
basicTest: () => BasicTest,
|
|
16
|
-
},
|
|
17
|
-
}) {
|
|
18
|
-
async check() {
|
|
19
|
-
if (this.basicTest.variable !== 1) {
|
|
20
|
-
throw new Error("Dependency test failed!");
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
package/test/before.test.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { strict as assert } from "assert";
|
|
2
|
-
|
|
3
|
-
import { Test } from "../dist/core.js";
|
|
4
|
-
import { getTest } from "../dist/index.js";
|
|
5
|
-
|
|
6
|
-
export class AlwaysExecuteLater extends Test({
|
|
7
|
-
after: () => [AlwaysExecuteFirst],
|
|
8
|
-
}) {
|
|
9
|
-
test() {
|
|
10
|
-
const alwaysExecuteFirst = getTest(() => AlwaysExecuteFirst);
|
|
11
|
-
assert(alwaysExecuteFirst.value === 1);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class AlwaysExecuteFirst extends Test() {
|
|
15
|
-
value = 0;
|
|
16
|
-
|
|
17
|
-
test() {
|
|
18
|
-
this.value = 1;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class AlwaysExecuteLater2 extends Test({}) {
|
|
23
|
-
test() {
|
|
24
|
-
const alwaysExecuteFirst2 = getTest(() => AlwaysExecuteFirst2);
|
|
25
|
-
assert(alwaysExecuteFirst2.value === 1);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
cleanUp() {}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class AlwaysExecuteFirst2 extends Test({
|
|
32
|
-
before: () => [AlwaysExecuteLater2],
|
|
33
|
-
}) {
|
|
34
|
-
value = 0;
|
|
35
|
-
|
|
36
|
-
test() {
|
|
37
|
-
this.value = 1;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
cleanUp() {}
|
|
41
|
-
}
|
package/test/clean-up.test.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Test } from "../dist/index";
|
|
2
|
-
|
|
3
|
-
export class CleanUpLayer1Test extends Test() {
|
|
4
|
-
data: any;
|
|
5
|
-
|
|
6
|
-
async start() {
|
|
7
|
-
this.data = { somethingImportant: 1 };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async cleanUp() {
|
|
11
|
-
this.data = null;
|
|
12
|
-
console.log("layer 1 clean up completed!");
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class CleanUpLayer2Test extends Test({
|
|
17
|
-
dependencies: {
|
|
18
|
-
previousLayer: () => CleanUpLayer1Test,
|
|
19
|
-
},
|
|
20
|
-
}) {
|
|
21
|
-
data: any;
|
|
22
|
-
|
|
23
|
-
async start() {
|
|
24
|
-
this.data = { somethingImportant: 1 };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async cleanUp() {
|
|
28
|
-
this.data = null;
|
|
29
|
-
console.log("layer 2 clean up completed!");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class CleanUpLayer3Test extends Test({
|
|
34
|
-
dependencies: {
|
|
35
|
-
previousLayer: () => CleanUpLayer2Test,
|
|
36
|
-
},
|
|
37
|
-
}) {
|
|
38
|
-
data: any;
|
|
39
|
-
|
|
40
|
-
async start() {
|
|
41
|
-
this.data = { somethingImportant: 1 };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async cleanUp() {
|
|
45
|
-
this.data = null;
|
|
46
|
-
console.log("layer 3 clean up completed!");
|
|
47
|
-
}
|
|
48
|
-
}
|