nole 2.1.2 → 2.2.1
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/README.md +47 -0
- package/bin/nole.js +80 -58
- package/dist/data.js +2 -2
- package/dist/data.js.map +1 -1
- package/dist/decorators.d.ts +2 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +51 -27
- package/dist/decorators.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +40 -24
- package/dist/run.js.map +1 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/utils/executor.js +1 -1
- package/dist/utils/executor.test.js +1 -1
- package/dist/utils/executor.test.js.map +1 -1
- package/dist/utils/time_difference.d.ts.map +1 -1
- package/dist/utils/time_difference.js.map +1 -1
- package/dist/utils/time_difference.test.js.map +1 -1
- package/dist/utils/time_factor.d.ts.map +1 -1
- package/dist/utils/time_factor.js +19 -14
- package/dist/utils/time_factor.js.map +1 -1
- package/dist/utils/time_factor.test.js +1 -1
- package/package.json +1 -1
- package/src/data.ts +3 -3
- package/src/decorators.ts +106 -48
- package/src/dynamic.ts +1 -1
- package/src/index.ts +13 -4
- package/src/run.ts +106 -42
- package/src/test.ts +10 -8
- package/src/utils/executor.test.ts +3 -3
- package/src/utils/executor.ts +2 -2
- package/src/utils/time_difference.test.ts +1 -1
- package/src/utils/time_difference.ts +1 -3
- package/src/utils/time_factor.test.ts +1 -1
- package/src/utils/time_factor.ts +24 -9
- package/test/basic.test.ts +8 -4
- package/test/before.test.ts +54 -0
- package/test/clean-up.test.ts +3 -5
- package/test/dynamic-skip.test.ts +1 -1
- package/test/dynamic.test.ts +1 -1
- package/test/hook.test.ts +3 -3
- package/test/multi-dependency.test.ts +31 -9
- package/test/multiple-uppercased-chars.test.ts +8 -7
- package/test/skip-all.test.ts +7 -7
- package/test/turkish-chars.test.ts +8 -7
package/src/run.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { HashMap } from "./data.js";
|
|
2
2
|
import { TimeDifference } from "./utils/time_difference.js";
|
|
3
3
|
import { TimeFactor } from "./utils/time_factor.js";
|
|
4
|
-
import * as clrs from
|
|
4
|
+
import * as clrs from "colors/safe.js";
|
|
5
5
|
import { Executor } from "./utils/executor.js";
|
|
6
6
|
import { HookType, Test } from "./test.js";
|
|
7
7
|
|
|
8
8
|
const colors = (clrs as any).default;
|
|
9
9
|
|
|
10
|
-
const OK_TEXT = colors.bold(colors.green(
|
|
11
|
-
const SKIP_TEXT = colors.bold(colors.yellow(
|
|
12
|
-
const DYNAMIC_SKIP_TEXT = colors.bold(colors.blue(
|
|
13
|
-
const FAILED_TEXT = colors.bold(colors.red(
|
|
14
|
-
const HOOK_FAILED_TEXT = colors.bold(colors.red(
|
|
10
|
+
const OK_TEXT = colors.bold(colors.green(" (ok) "));
|
|
11
|
+
const SKIP_TEXT = colors.bold(colors.yellow(" (skip) "));
|
|
12
|
+
const DYNAMIC_SKIP_TEXT = colors.bold(colors.blue(" (dskip) "));
|
|
13
|
+
const FAILED_TEXT = colors.bold(colors.red(" (failed) "));
|
|
14
|
+
const HOOK_FAILED_TEXT = colors.bold(colors.red(" (hook failed) "));
|
|
15
15
|
|
|
16
16
|
interface Options {
|
|
17
|
-
log: Function
|
|
18
|
-
orderDebug: boolean
|
|
17
|
+
log: Function;
|
|
18
|
+
orderDebug: boolean;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function ManualRun(options: Options) {
|
|
@@ -31,7 +31,7 @@ export function ManualRun(options: Options) {
|
|
|
31
31
|
|
|
32
32
|
if (!hashMap.size) {
|
|
33
33
|
log(`${FAILED_TEXT} no specs found`);
|
|
34
|
-
throw new Error(
|
|
34
|
+
throw new Error("No specs found");
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
while (hashMap.size) {
|
|
@@ -66,7 +66,7 @@ export function ManualRun(options: Options) {
|
|
|
66
66
|
function PickNextTestFromHashMap(hashMap: Map<any, Test>) {
|
|
67
67
|
for (let test of hashMap.values()) {
|
|
68
68
|
if (test.isFinished) continue;
|
|
69
|
-
if (!test.dependencies.every(x => x.dependency.isFinished)) continue;
|
|
69
|
+
if (!test.dependencies.every((x) => x.dependency.isFinished)) continue;
|
|
70
70
|
|
|
71
71
|
return test;
|
|
72
72
|
}
|
|
@@ -74,13 +74,14 @@ function PickNextTestFromHashMap(hashMap: Map<any, Test>) {
|
|
|
74
74
|
|
|
75
75
|
function CreateInstanceIfNotExists(test: Test) {
|
|
76
76
|
if (!test.testInstance) {
|
|
77
|
-
test.testInstance = new
|
|
77
|
+
test.testInstance = new test.target();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function HandleDependencies(test: Test) {
|
|
82
82
|
for (let dependency of test.dependencies) {
|
|
83
|
-
test.testInstance[dependency.propertyKey] =
|
|
83
|
+
test.testInstance[dependency.propertyKey] =
|
|
84
|
+
dependency.dependency.testInstance;
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
|
|
@@ -88,17 +89,24 @@ async function HandleBeforeHooks(test: Test, options: Options) {
|
|
|
88
89
|
for (let [propertyKey, hook] of test.hooks.entries()) {
|
|
89
90
|
if (hook.type != HookType.Before) continue;
|
|
90
91
|
|
|
91
|
-
let hookName = colors.bold(
|
|
92
|
+
let hookName = colors.bold(
|
|
93
|
+
colors.yellow(
|
|
94
|
+
test.name +
|
|
95
|
+
(propertyKey != "before" ? `.${propertyKey}:before` : ":before")
|
|
96
|
+
)
|
|
97
|
+
);
|
|
92
98
|
|
|
93
99
|
try {
|
|
94
100
|
if (!options.orderDebug) {
|
|
95
|
-
await Executor(
|
|
101
|
+
await Executor(
|
|
102
|
+
test.testInstance[propertyKey].bind(test.testInstance),
|
|
103
|
+
hook.timeout
|
|
104
|
+
);
|
|
96
105
|
} else {
|
|
97
106
|
let timeText = TimeFactor(0, hook.timeout);
|
|
98
107
|
|
|
99
108
|
options.log(`${OK_TEXT} ${timeText} ${hookName}()`);
|
|
100
109
|
}
|
|
101
|
-
|
|
102
110
|
} catch (e) {
|
|
103
111
|
console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
|
|
104
112
|
console.error((e as any)?.stack ?? e);
|
|
@@ -110,19 +118,27 @@ async function HandleBeforeHooks(test: Test, options: Options) {
|
|
|
110
118
|
async function HandleBeforeEachHooks(test: Test, options: Options) {
|
|
111
119
|
for (let [propertyKey, hook] of test.hooks.entries()) {
|
|
112
120
|
if (hook.type != HookType.BeforeEach) continue;
|
|
113
|
-
let hookName = colors.bold(
|
|
114
|
-
|
|
121
|
+
let hookName = colors.bold(
|
|
122
|
+
colors.yellow(
|
|
123
|
+
test.name +
|
|
124
|
+
(propertyKey != "beforeEach"
|
|
125
|
+
? `.${propertyKey}:beforeEach`
|
|
126
|
+
: ":beforeEach")
|
|
127
|
+
)
|
|
128
|
+
);
|
|
129
|
+
|
|
115
130
|
try {
|
|
116
131
|
if (!options.orderDebug) {
|
|
117
|
-
await Executor(
|
|
132
|
+
await Executor(
|
|
133
|
+
test.testInstance[propertyKey].bind(test.testInstance),
|
|
134
|
+
hook.timeout
|
|
135
|
+
);
|
|
118
136
|
} else {
|
|
119
137
|
let timeText = TimeFactor(0, hook.timeout);
|
|
120
138
|
|
|
121
139
|
options.log(`${OK_TEXT} ${timeText} ${hookName}()`);
|
|
122
140
|
}
|
|
123
|
-
|
|
124
141
|
} catch (e) {
|
|
125
|
-
|
|
126
142
|
console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
|
|
127
143
|
console.error((e as any)?.stack ?? e);
|
|
128
144
|
throw e;
|
|
@@ -133,18 +149,27 @@ async function HandleBeforeEachHooks(test: Test, options: Options) {
|
|
|
133
149
|
async function HandleAfterEachHooks(test: Test, options: Options) {
|
|
134
150
|
for (let [propertyKey, hook] of test.hooks.entries()) {
|
|
135
151
|
if (hook.type != HookType.AfterEach) continue;
|
|
136
|
-
|
|
137
|
-
let hookName = colors.bold(
|
|
152
|
+
|
|
153
|
+
let hookName = colors.bold(
|
|
154
|
+
colors.yellow(
|
|
155
|
+
test.name +
|
|
156
|
+
(propertyKey != "afterEach"
|
|
157
|
+
? `.${propertyKey}:afterEach`
|
|
158
|
+
: ":afterEach")
|
|
159
|
+
)
|
|
160
|
+
);
|
|
138
161
|
|
|
139
162
|
try {
|
|
140
163
|
if (!options.orderDebug) {
|
|
141
|
-
await Executor(
|
|
164
|
+
await Executor(
|
|
165
|
+
test.testInstance[propertyKey].bind(test.testInstance),
|
|
166
|
+
hook.timeout
|
|
167
|
+
);
|
|
142
168
|
} else {
|
|
143
169
|
let timeText = TimeFactor(0, hook.timeout);
|
|
144
170
|
|
|
145
171
|
options.log(`${OK_TEXT} ${timeText} ${hookName}()`);
|
|
146
172
|
}
|
|
147
|
-
|
|
148
173
|
} catch (e) {
|
|
149
174
|
console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
|
|
150
175
|
console.error((e as any)?.stack ?? e);
|
|
@@ -157,12 +182,18 @@ async function HandleSpecs(test: Test, options: Options) {
|
|
|
157
182
|
const log = options.log;
|
|
158
183
|
|
|
159
184
|
for (let [propertyKey, spec] of test.specs.entries()) {
|
|
160
|
-
let testName = colors.bold(colors.yellow(test.name +
|
|
185
|
+
let testName = colors.bold(colors.yellow(test.name + "." + propertyKey));
|
|
161
186
|
|
|
162
187
|
const shouldPropertySkip = test.skip.has(propertyKey);
|
|
163
188
|
if (shouldPropertySkip || test.skipClass) {
|
|
164
|
-
let reason = shouldPropertySkip
|
|
165
|
-
|
|
189
|
+
let reason = shouldPropertySkip
|
|
190
|
+
? test.skip.get(propertyKey)!.reason
|
|
191
|
+
: test.skipClass!.reason;
|
|
192
|
+
log(
|
|
193
|
+
`${SKIP_TEXT} ${" ".repeat(9)} ${testName}() ${
|
|
194
|
+
reason ? "{" + reason + "}" : ""
|
|
195
|
+
}`
|
|
196
|
+
);
|
|
166
197
|
continue;
|
|
167
198
|
}
|
|
168
199
|
|
|
@@ -172,7 +203,10 @@ async function HandleSpecs(test: Test, options: Options) {
|
|
|
172
203
|
|
|
173
204
|
try {
|
|
174
205
|
if (!options.orderDebug) {
|
|
175
|
-
await Executor(
|
|
206
|
+
await Executor(
|
|
207
|
+
test.testInstance[propertyKey].bind(test.testInstance),
|
|
208
|
+
spec.timeout
|
|
209
|
+
);
|
|
176
210
|
}
|
|
177
211
|
|
|
178
212
|
let timeText = TimeFactor(start.end(), spec.timeout);
|
|
@@ -181,7 +215,11 @@ async function HandleSpecs(test: Test, options: Options) {
|
|
|
181
215
|
} catch (e) {
|
|
182
216
|
if ((e as any)?._nole_anchor) {
|
|
183
217
|
let reason = (e as any).reason;
|
|
184
|
-
log(
|
|
218
|
+
log(
|
|
219
|
+
`${DYNAMIC_SKIP_TEXT} ${" ".repeat(8)} ${testName}() ${
|
|
220
|
+
reason ? "{" + reason + "}" : ""
|
|
221
|
+
}`
|
|
222
|
+
);
|
|
185
223
|
continue;
|
|
186
224
|
}
|
|
187
225
|
|
|
@@ -200,17 +238,24 @@ async function HandleAfterHooks(test: Test, options: Options) {
|
|
|
200
238
|
for (let [propertyKey, hook] of test.hooks.entries()) {
|
|
201
239
|
if (hook.type != HookType.After) continue;
|
|
202
240
|
|
|
203
|
-
let hookName = colors.bold(
|
|
241
|
+
let hookName = colors.bold(
|
|
242
|
+
colors.yellow(
|
|
243
|
+
test.name +
|
|
244
|
+
(propertyKey != "after" ? `.${propertyKey}:after` : ":after")
|
|
245
|
+
)
|
|
246
|
+
);
|
|
204
247
|
|
|
205
248
|
try {
|
|
206
249
|
if (!options.orderDebug) {
|
|
207
|
-
await Executor(
|
|
250
|
+
await Executor(
|
|
251
|
+
test.testInstance[propertyKey].bind(test.testInstance),
|
|
252
|
+
hook.timeout
|
|
253
|
+
);
|
|
208
254
|
} else {
|
|
209
255
|
let timeText = TimeFactor(0, hook.timeout);
|
|
210
256
|
|
|
211
257
|
options.log(`${OK_TEXT} ${timeText} ${hookName}()`);
|
|
212
258
|
}
|
|
213
|
-
|
|
214
259
|
} catch (e) {
|
|
215
260
|
console.error(`${HOOK_FAILED_TEXT} ${hookName}()`);
|
|
216
261
|
console.error((e as any)?.stack ?? e);
|
|
@@ -219,10 +264,14 @@ async function HandleAfterHooks(test: Test, options: Options) {
|
|
|
219
264
|
}
|
|
220
265
|
}
|
|
221
266
|
|
|
222
|
-
|
|
223
267
|
async function HandleCleanUp(test: Test, options: Options) {
|
|
224
268
|
if (test.cleanUpCalled) return;
|
|
225
|
-
if (
|
|
269
|
+
if (
|
|
270
|
+
!test.dependents.every(
|
|
271
|
+
(dependent) => dependent.isFinished && dependent.cleanUpCalled
|
|
272
|
+
)
|
|
273
|
+
)
|
|
274
|
+
return;
|
|
226
275
|
|
|
227
276
|
test.cleanUpCalled = true;
|
|
228
277
|
|
|
@@ -231,12 +280,20 @@ async function HandleCleanUp(test: Test, options: Options) {
|
|
|
231
280
|
for (let [propertyKey, hook] of test.hooks.entries()) {
|
|
232
281
|
if (hook.type != HookType.CleanUp) continue;
|
|
233
282
|
|
|
234
|
-
let hookName = colors.bold(
|
|
283
|
+
let hookName = colors.bold(
|
|
284
|
+
colors.yellow(
|
|
285
|
+
test.name +
|
|
286
|
+
(propertyKey != "cleanUp" ? `.${propertyKey}:cleanUp` : ":cleanUp")
|
|
287
|
+
)
|
|
288
|
+
);
|
|
235
289
|
let start = TimeDifference.begin();
|
|
236
290
|
|
|
237
291
|
try {
|
|
238
292
|
if (!options.orderDebug) {
|
|
239
|
-
await Executor(
|
|
293
|
+
await Executor(
|
|
294
|
+
test.testInstance[propertyKey].bind(test.testInstance),
|
|
295
|
+
hook.timeout
|
|
296
|
+
);
|
|
240
297
|
}
|
|
241
298
|
|
|
242
299
|
let timeText = TimeFactor(start.end(), hook.timeout);
|
|
@@ -255,13 +312,20 @@ async function HandleCleanUp(test: Test, options: Options) {
|
|
|
255
312
|
}
|
|
256
313
|
|
|
257
314
|
function DependencyLock(hashMap: Map<any, Test>) {
|
|
258
|
-
console.error(
|
|
315
|
+
console.error(
|
|
316
|
+
FAILED_TEXT +
|
|
317
|
+
colors.red("Looks like there is confict issue for dependency resolving!")
|
|
318
|
+
);
|
|
259
319
|
|
|
260
|
-
console.error(
|
|
320
|
+
console.error("Possible conflicts;");
|
|
261
321
|
for (let test of hashMap.values()) {
|
|
262
|
-
|
|
263
|
-
|
|
322
|
+
console.error(
|
|
323
|
+
`- class ${test.name} { ${test.dependencies
|
|
324
|
+
.filter((x) => !x.dependency.isFinished)
|
|
325
|
+
.map((x) => `@Dependency(${x.dependency.name}) ${x.propertyKey}`)
|
|
326
|
+
.join(", ")} }`
|
|
327
|
+
);
|
|
264
328
|
}
|
|
265
329
|
|
|
266
|
-
throw new Error(
|
|
267
|
-
}
|
|
330
|
+
throw new Error("Dependency lock occurred!");
|
|
331
|
+
}
|
package/src/test.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export interface IDependency {
|
|
2
|
-
propertyKey: string
|
|
3
|
-
dependency: Test
|
|
2
|
+
propertyKey: string;
|
|
3
|
+
dependency: Test;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export interface ISpec {
|
|
7
|
-
timeout: number
|
|
7
|
+
timeout: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface IHook {
|
|
11
|
-
type: HookType
|
|
12
|
-
timeout: number
|
|
11
|
+
type: HookType;
|
|
12
|
+
timeout: number;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export interface ISkip {
|
|
16
|
-
reason: string
|
|
16
|
+
reason: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export class Test {
|
|
@@ -39,7 +39,9 @@ export enum HookType {
|
|
|
39
39
|
After, // Trigger when test case did all the specs
|
|
40
40
|
BeforeEach, // Trigger before each spec
|
|
41
41
|
AfterEach, // Trigger after each spec
|
|
42
|
-
CleanUp // Trigger after all dependents tested (You can safely remove connections etc.)
|
|
42
|
+
CleanUp, // Trigger after all dependents tested (You can safely remove connections etc.)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export interface ClassDefition<T> {
|
|
45
|
+
export interface ClassDefition<T> {
|
|
46
|
+
new (): T;
|
|
47
|
+
}
|
|
@@ -13,15 +13,15 @@ export class ExecutorTest {
|
|
|
13
13
|
async throws() {
|
|
14
14
|
await assert.rejects(() => {
|
|
15
15
|
return Executor(() => {
|
|
16
|
-
throw new Error(
|
|
16
|
+
throw new Error("throws");
|
|
17
17
|
}, 1);
|
|
18
|
-
})
|
|
18
|
+
});
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
@Spec()
|
|
22
22
|
async timeout() {
|
|
23
23
|
await assert.rejects(() => {
|
|
24
24
|
return Executor(() => new Promise(() => {}), 10);
|
|
25
|
-
})
|
|
25
|
+
});
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/utils/executor.ts
CHANGED
|
@@ -6,7 +6,7 @@ export function Executor(fn: Function, timeout: number): Promise<void> {
|
|
|
6
6
|
let expectPromise = fn();
|
|
7
7
|
if (expectPromise && expectPromise.then) {
|
|
8
8
|
_timeout = setTimeout(function () {
|
|
9
|
-
reject(new Error(
|
|
9
|
+
reject(new Error("Timeout occurred! value: " + timeout));
|
|
10
10
|
}, timeout);
|
|
11
11
|
|
|
12
12
|
await expectPromise;
|
|
@@ -19,4 +19,4 @@ export function Executor(fn: Function, timeout: number): Promise<void> {
|
|
|
19
19
|
|
|
20
20
|
resolve();
|
|
21
21
|
});
|
|
22
|
-
}
|
|
22
|
+
}
|
|
@@ -8,7 +8,6 @@ export class TimeDifference {
|
|
|
8
8
|
this.startAt = process.hrtime();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
/**
|
|
13
12
|
* Creates the instance at the begining
|
|
14
13
|
*/
|
|
@@ -16,7 +15,6 @@ export class TimeDifference {
|
|
|
16
15
|
return new TimeDifference();
|
|
17
16
|
}
|
|
18
17
|
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Finishes the time, returns data in milliseconds
|
|
22
20
|
*/
|
|
@@ -25,4 +23,4 @@ export class TimeDifference {
|
|
|
25
23
|
|
|
26
24
|
return diff[0] * 1000 + diff[1] / 1e6;
|
|
27
25
|
}
|
|
28
|
-
}
|
|
26
|
+
}
|
package/src/utils/time_factor.ts
CHANGED
|
@@ -1,20 +1,35 @@
|
|
|
1
|
-
import * as clrs from
|
|
1
|
+
import * as clrs from "colors/safe.js";
|
|
2
2
|
|
|
3
3
|
const colors = (clrs as any).default;
|
|
4
4
|
|
|
5
5
|
export function TimeFactor(diff: number, timeout: number) {
|
|
6
|
-
if (diff < timeout / 5)
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (diff < timeout / 5) {
|
|
7
|
+
return colors.green(TimeResolve(diff).padStart(9, " "));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (diff < timeout / 2) {
|
|
11
|
+
return colors.yellow(TimeResolve(diff).padStart(9, " "));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return colors.red(TimeResolve(diff).padStart(9, " "));
|
|
9
15
|
}
|
|
10
16
|
|
|
11
17
|
export function TimeResolve(ms: number) {
|
|
12
|
-
if (ms < 1000)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
if (ms < 1000) {
|
|
19
|
+
return ((ms * 100) | 0) / 100 + " ms";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (ms < 60 * 1000) {
|
|
23
|
+
return ((ms / 10) | 0) / 100 + " s";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (ms < 60 * 60 * 1000) {
|
|
27
|
+
return ((ms / 600) | 0) / 100 + " m";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return ((ms / 36000) | 0) / 100 + " h";
|
|
16
31
|
}
|
|
17
32
|
|
|
18
33
|
export function Delay(ms: number): Promise<void> {
|
|
19
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
34
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
35
|
}
|
package/test/basic.test.ts
CHANGED
|
@@ -5,7 +5,9 @@ export class BasicTest {
|
|
|
5
5
|
|
|
6
6
|
@Spec()
|
|
7
7
|
async checkEqual() {
|
|
8
|
-
await new Promise(resolve => {
|
|
8
|
+
await new Promise((resolve) => {
|
|
9
|
+
setTimeout(resolve, 1010);
|
|
10
|
+
});
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -13,8 +15,10 @@ export class DependencyTest {
|
|
|
13
15
|
@Dependency(BasicTest)
|
|
14
16
|
basicTest!: BasicTest;
|
|
15
17
|
|
|
16
|
-
@Spec()
|
|
17
|
-
|
|
18
|
+
@Spec()
|
|
19
|
+
async check() {
|
|
20
|
+
if (this.basicTest.variable !== 1) {
|
|
21
|
+
throw new Error("Dependency test failed!");
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
}
|
|
20
|
-
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { strict as assert } from "assert";
|
|
2
|
+
import { Before, Spec, After, Hook, HookType, Dependents } from "../src/index.js";
|
|
3
|
+
|
|
4
|
+
// @After(() => [AlwaysExecuteFirst])
|
|
5
|
+
export class AlwaysExecuteLater {
|
|
6
|
+
alwaysExecuteFirst: AlwaysExecuteFirst;
|
|
7
|
+
|
|
8
|
+
@Spec()
|
|
9
|
+
test() {
|
|
10
|
+
assert(this.alwaysExecuteFirst.value === 1);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Hook(HookType.CleanUp)
|
|
14
|
+
cleanUp() {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Dependents(() => [AlwaysExecuteLater])
|
|
18
|
+
export class AlwaysExecuteFirst {
|
|
19
|
+
value = 0;
|
|
20
|
+
|
|
21
|
+
@Spec()
|
|
22
|
+
test() {
|
|
23
|
+
this.value = 1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Hook(HookType.CleanUp)
|
|
27
|
+
cleanUp() {}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@After(() => [AlwaysExecuteFirst2])
|
|
31
|
+
export class AlwaysExecuteLater2 {
|
|
32
|
+
alwaysExecuteFirst2: AlwaysExecuteFirst2;
|
|
33
|
+
|
|
34
|
+
@Spec()
|
|
35
|
+
test() {
|
|
36
|
+
assert(this.alwaysExecuteFirst2.value === 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Hook(HookType.CleanUp)
|
|
40
|
+
cleanUp() {}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// @Before(() => [AlwaysExecuteLater2])
|
|
44
|
+
export class AlwaysExecuteFirst2 {
|
|
45
|
+
value = 0;
|
|
46
|
+
|
|
47
|
+
@Spec()
|
|
48
|
+
test() {
|
|
49
|
+
this.value = 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Hook(HookType.CleanUp)
|
|
53
|
+
cleanUp() {}
|
|
54
|
+
}
|
package/test/clean-up.test.ts
CHANGED
|
@@ -11,11 +11,10 @@ export class CleanUpLayer1Test {
|
|
|
11
11
|
@Hook(HookType.CleanUp)
|
|
12
12
|
async cleanUp() {
|
|
13
13
|
this.data = null;
|
|
14
|
-
console.log(
|
|
14
|
+
console.log("layer 1 clean up completed!");
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
18
|
export class CleanUpLayer2Test {
|
|
20
19
|
data: any;
|
|
21
20
|
|
|
@@ -30,11 +29,10 @@ export class CleanUpLayer2Test {
|
|
|
30
29
|
@Hook(HookType.CleanUp)
|
|
31
30
|
async cleanUp() {
|
|
32
31
|
this.data = null;
|
|
33
|
-
console.log(
|
|
32
|
+
console.log("layer 2 clean up completed!");
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
|
|
38
36
|
export class CleanUpLayer3Test {
|
|
39
37
|
data: any;
|
|
40
38
|
|
|
@@ -49,6 +47,6 @@ export class CleanUpLayer3Test {
|
|
|
49
47
|
@Hook(HookType.CleanUp)
|
|
50
48
|
async cleanUp() {
|
|
51
49
|
this.data = null;
|
|
52
|
-
console.log(
|
|
50
|
+
console.log("layer 3 clean up completed!");
|
|
53
51
|
}
|
|
54
52
|
}
|
package/test/dynamic.test.ts
CHANGED
package/test/hook.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as assert from
|
|
1
|
+
import * as assert from "assert";
|
|
2
2
|
import { Spec, Hook, Skip, HookType } from "../src/index.js";
|
|
3
3
|
|
|
4
4
|
export class HookTest {
|
|
@@ -14,7 +14,7 @@ export class HookTest {
|
|
|
14
14
|
assert.equal(this.array.pop(), 4);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
@Skip(
|
|
17
|
+
@Skip("no need")
|
|
18
18
|
@Spec()
|
|
19
19
|
async hasToBe4Again() {
|
|
20
20
|
assert.equal(this.array.pop(), 4);
|
|
@@ -24,4 +24,4 @@ export class HookTest {
|
|
|
24
24
|
async hasToBe4AgainButNotSkipped() {
|
|
25
25
|
assert.equal(this.array.pop(), 4);
|
|
26
26
|
}
|
|
27
|
-
}
|
|
27
|
+
}
|
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
import * as assert from
|
|
1
|
+
import * as assert from "assert";
|
|
2
2
|
import { Dependencies, Spec } from "../src/index.js";
|
|
3
|
-
import { BasicTest } from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { BasicTest } from "./basic.test.js";
|
|
4
|
+
import {
|
|
5
|
+
CleanUpLayer1Test,
|
|
6
|
+
CleanUpLayer2Test,
|
|
7
|
+
CleanUpLayer3Test,
|
|
8
|
+
} from "./clean-up.test.js";
|
|
9
|
+
import { DynamicSkipTest } from "./dynamic-skip.test.js";
|
|
10
|
+
import { HookTest } from "./hook.test.js";
|
|
11
|
+
|
|
12
|
+
@Dependencies(() => [
|
|
13
|
+
BasicTest,
|
|
14
|
+
CleanUpLayer1Test,
|
|
15
|
+
CleanUpLayer2Test,
|
|
16
|
+
CleanUpLayer3Test,
|
|
17
|
+
DynamicSkipTest,
|
|
18
|
+
HookTest,
|
|
19
|
+
MultiDependency,
|
|
20
|
+
])
|
|
21
|
+
export class MultiLazyDependency {
|
|
22
|
+
basicTest: BasicTest;
|
|
23
|
+
|
|
24
|
+
@Spec()
|
|
25
|
+
test() {
|
|
26
|
+
assert.strictEqual(this.basicTest.variable, 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
7
29
|
|
|
8
30
|
@Dependencies([
|
|
9
31
|
BasicTest,
|
|
@@ -11,13 +33,13 @@ import { HookTest } from './hook.test.js';
|
|
|
11
33
|
CleanUpLayer2Test,
|
|
12
34
|
CleanUpLayer3Test,
|
|
13
35
|
DynamicSkipTest,
|
|
14
|
-
HookTest
|
|
36
|
+
HookTest,
|
|
15
37
|
])
|
|
16
38
|
export class MultiDependency {
|
|
17
39
|
basicTest: BasicTest;
|
|
18
40
|
|
|
19
|
-
@Spec()
|
|
41
|
+
@Spec()
|
|
20
42
|
test() {
|
|
21
|
-
assert.strictEqual(this.basicTest.variable, 1);
|
|
43
|
+
assert.strictEqual(this.basicTest.variable, 1);
|
|
22
44
|
}
|
|
23
|
-
}
|
|
45
|
+
}
|