@sprucelabs/test-utils 5.5.5 → 5.5.7
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/build/decorators.d.ts +24 -24
- package/build/decorators.js +48 -48
- package/build/esm/decorators.d.ts +24 -24
- package/build/esm/decorators.js +48 -48
- package/package.json +1 -1
package/build/decorators.d.ts
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
type TestLifecycleListener = () => any | Promise<any>;
|
2
2
|
type TestLifecycleListenerWithTest = (Test: any) => any | Promise<any>;
|
3
3
|
export declare class TestLifecycleListeners {
|
4
|
-
static
|
5
|
-
static
|
6
|
-
static
|
7
|
-
static
|
8
|
-
static
|
9
|
-
static
|
10
|
-
static
|
11
|
-
static
|
12
|
-
static
|
13
|
-
static
|
14
|
-
static
|
15
|
-
static
|
16
|
-
static
|
17
|
-
static
|
18
|
-
static
|
19
|
-
static
|
4
|
+
static willBeforeAllListeners: TestLifecycleListener[];
|
5
|
+
static didBeforeAllListeners: TestLifecycleListener[];
|
6
|
+
static willBeforeEachListeners: TestLifecycleListenerWithTest[];
|
7
|
+
static didBeforeEachListeners: TestLifecycleListenerWithTest[];
|
8
|
+
static willAfterEachListeners: TestLifecycleListenerWithTest[];
|
9
|
+
static didAfterEachListeners: TestLifecycleListenerWithTest[];
|
10
|
+
static willAfterAllListeners: TestLifecycleListener[];
|
11
|
+
static didAfterAllListeners: TestLifecycleListener[];
|
12
|
+
static emitWillRunBeforeAll(): Promise<void>;
|
13
|
+
static emitDidRunBeforeAll(): Promise<void>;
|
14
|
+
static emitWillRunBeforeEach(): Promise<void>;
|
15
|
+
static emitDidRunBeforeEach(): Promise<void>;
|
16
|
+
static emitWillRunAfterEach(): Promise<void>;
|
17
|
+
static emitDidRunAfterEach(): Promise<void>;
|
18
|
+
static emitWillRunAfterAll(): Promise<void>;
|
19
|
+
static emitDidRunAfterAll(): Promise<void>;
|
20
20
|
}
|
21
21
|
export declare class SpruceTestResolver {
|
22
22
|
static ActiveTestClass?: any;
|
23
23
|
private static __activeTest;
|
24
24
|
static resolveTestClass(target: any): any;
|
25
25
|
static getActiveTest(): any;
|
26
|
-
static
|
27
|
-
static
|
28
|
-
static
|
29
|
-
static
|
30
|
-
static
|
31
|
-
static
|
32
|
-
static
|
33
|
-
static
|
26
|
+
static onWillCallBeforeAll(cb: TestLifecycleListener): void;
|
27
|
+
static onDidBeforeAll(cb: TestLifecycleListener): void;
|
28
|
+
static onWillCallBeforeEach(cb: TestLifecycleListenerWithTest): void;
|
29
|
+
static onDidCallBeforeEach(cb: TestLifecycleListenerWithTest): void;
|
30
|
+
static onWillCallAfterEach(cb: TestLifecycleListenerWithTest): void;
|
31
|
+
static onDidCallAfterEach(cb: TestLifecycleListenerWithTest): void;
|
32
|
+
static onWillCallAfterAll(cb: TestLifecycleListener): void;
|
33
|
+
static onDidCallAfterAll(cb: TestLifecycleListener): void;
|
34
34
|
}
|
35
35
|
/** Test decorator */
|
36
36
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
package/build/decorators.js
CHANGED
@@ -8,56 +8,56 @@ if (typeof it === 'undefined') {
|
|
8
8
|
global.it = () => { };
|
9
9
|
}
|
10
10
|
class TestLifecycleListeners {
|
11
|
-
static async
|
12
|
-
for (const cb of this.
|
11
|
+
static async emitWillRunBeforeAll() {
|
12
|
+
for (const cb of this.willBeforeAllListeners) {
|
13
13
|
await cb();
|
14
14
|
}
|
15
15
|
}
|
16
|
-
static async
|
17
|
-
for (const cb of this.
|
16
|
+
static async emitDidRunBeforeAll() {
|
17
|
+
for (const cb of this.didBeforeAllListeners) {
|
18
18
|
await cb();
|
19
19
|
}
|
20
20
|
}
|
21
|
-
static async
|
22
|
-
for (const cb of this.
|
21
|
+
static async emitWillRunBeforeEach() {
|
22
|
+
for (const cb of this.willBeforeEachListeners) {
|
23
23
|
await cb(SpruceTestResolver.getActiveTest());
|
24
24
|
}
|
25
25
|
}
|
26
|
-
static async
|
27
|
-
for (const cb of this.
|
26
|
+
static async emitDidRunBeforeEach() {
|
27
|
+
for (const cb of this.didBeforeEachListeners) {
|
28
28
|
await cb(SpruceTestResolver.getActiveTest());
|
29
29
|
}
|
30
30
|
}
|
31
|
-
static async
|
32
|
-
for (const cb of this.
|
31
|
+
static async emitWillRunAfterEach() {
|
32
|
+
for (const cb of this.willAfterEachListeners) {
|
33
33
|
await cb(SpruceTestResolver.getActiveTest());
|
34
34
|
}
|
35
35
|
}
|
36
|
-
static async
|
37
|
-
for (const cb of this.
|
36
|
+
static async emitDidRunAfterEach() {
|
37
|
+
for (const cb of this.didAfterEachListeners) {
|
38
38
|
await cb(SpruceTestResolver.getActiveTest());
|
39
39
|
}
|
40
40
|
}
|
41
|
-
static async
|
42
|
-
for (const cb of this.
|
41
|
+
static async emitWillRunAfterAll() {
|
42
|
+
for (const cb of this.willAfterAllListeners) {
|
43
43
|
await cb();
|
44
44
|
}
|
45
45
|
}
|
46
|
-
static async
|
47
|
-
for (const cb of this.
|
46
|
+
static async emitDidRunAfterAll() {
|
47
|
+
for (const cb of this.didAfterAllListeners) {
|
48
48
|
await cb();
|
49
49
|
}
|
50
50
|
}
|
51
51
|
}
|
52
52
|
exports.TestLifecycleListeners = TestLifecycleListeners;
|
53
|
-
TestLifecycleListeners.
|
54
|
-
TestLifecycleListeners.
|
55
|
-
TestLifecycleListeners.
|
56
|
-
TestLifecycleListeners.
|
57
|
-
TestLifecycleListeners.
|
58
|
-
TestLifecycleListeners.
|
59
|
-
TestLifecycleListeners.
|
60
|
-
TestLifecycleListeners.
|
53
|
+
TestLifecycleListeners.willBeforeAllListeners = [];
|
54
|
+
TestLifecycleListeners.didBeforeAllListeners = [];
|
55
|
+
TestLifecycleListeners.willBeforeEachListeners = [];
|
56
|
+
TestLifecycleListeners.didBeforeEachListeners = [];
|
57
|
+
TestLifecycleListeners.willAfterEachListeners = [];
|
58
|
+
TestLifecycleListeners.didAfterEachListeners = [];
|
59
|
+
TestLifecycleListeners.willAfterAllListeners = [];
|
60
|
+
TestLifecycleListeners.didAfterAllListeners = [];
|
61
61
|
class SpruceTestResolver {
|
62
62
|
static resolveTestClass(target) {
|
63
63
|
if (!this.__activeTest) {
|
@@ -70,29 +70,29 @@ class SpruceTestResolver {
|
|
70
70
|
static getActiveTest() {
|
71
71
|
return this.__activeTest;
|
72
72
|
}
|
73
|
-
static
|
74
|
-
TestLifecycleListeners.
|
73
|
+
static onWillCallBeforeAll(cb) {
|
74
|
+
TestLifecycleListeners.willBeforeAllListeners.push(cb);
|
75
75
|
}
|
76
|
-
static
|
77
|
-
TestLifecycleListeners.
|
76
|
+
static onDidBeforeAll(cb) {
|
77
|
+
TestLifecycleListeners.didBeforeAllListeners.push(cb);
|
78
78
|
}
|
79
|
-
static
|
80
|
-
TestLifecycleListeners.
|
79
|
+
static onWillCallBeforeEach(cb) {
|
80
|
+
TestLifecycleListeners.willBeforeEachListeners.push(cb);
|
81
81
|
}
|
82
|
-
static
|
83
|
-
TestLifecycleListeners.
|
82
|
+
static onDidCallBeforeEach(cb) {
|
83
|
+
TestLifecycleListeners.didBeforeEachListeners.push(cb);
|
84
84
|
}
|
85
|
-
static
|
86
|
-
TestLifecycleListeners.
|
85
|
+
static onWillCallAfterEach(cb) {
|
86
|
+
TestLifecycleListeners.willAfterEachListeners.push(cb);
|
87
87
|
}
|
88
|
-
static
|
89
|
-
TestLifecycleListeners.
|
88
|
+
static onDidCallAfterEach(cb) {
|
89
|
+
TestLifecycleListeners.didAfterEachListeners.push(cb);
|
90
90
|
}
|
91
|
-
static
|
92
|
-
TestLifecycleListeners.
|
91
|
+
static onWillCallAfterAll(cb) {
|
92
|
+
TestLifecycleListeners.willAfterAllListeners.push(cb);
|
93
93
|
}
|
94
|
-
static
|
95
|
-
TestLifecycleListeners.
|
94
|
+
static onDidCallAfterAll(cb) {
|
95
|
+
TestLifecycleListeners.didAfterAllListeners.push(cb);
|
96
96
|
}
|
97
97
|
}
|
98
98
|
exports.SpruceTestResolver = SpruceTestResolver;
|
@@ -125,23 +125,23 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
125
125
|
global[hook](async () => {
|
126
126
|
if (hook === 'beforeEach') {
|
127
127
|
SpruceTestResolver.resolveTestClass(Target);
|
128
|
-
await TestLifecycleListeners.
|
128
|
+
await TestLifecycleListeners.emitWillRunBeforeEach();
|
129
129
|
await runBeforeEach(Target);
|
130
|
-
await TestLifecycleListeners.
|
130
|
+
await TestLifecycleListeners.emitDidRunBeforeEach();
|
131
131
|
}
|
132
132
|
else if (hook === 'afterEach') {
|
133
|
-
await TestLifecycleListeners.
|
133
|
+
await TestLifecycleListeners.emitWillRunAfterEach();
|
134
134
|
await runAfterEach(Target);
|
135
|
-
await TestLifecycleListeners.
|
135
|
+
await TestLifecycleListeners.emitDidRunAfterEach();
|
136
136
|
// @ts-ignore
|
137
137
|
delete SpruceTestResolver.__activeTest;
|
138
138
|
}
|
139
139
|
else {
|
140
140
|
if (hook === 'beforeAll') {
|
141
|
-
await TestLifecycleListeners.
|
141
|
+
await TestLifecycleListeners.emitWillRunBeforeAll();
|
142
142
|
}
|
143
143
|
else if (hook === 'afterAll') {
|
144
|
-
await TestLifecycleListeners.
|
144
|
+
await TestLifecycleListeners.emitWillRunAfterAll();
|
145
145
|
}
|
146
146
|
if (SpruceTestResolver.ActiveTestClass) {
|
147
147
|
await cb.apply(Target.constructor);
|
@@ -150,10 +150,10 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
150
150
|
await cb.apply(Target);
|
151
151
|
}
|
152
152
|
if (hook === 'beforeAll') {
|
153
|
-
await TestLifecycleListeners.
|
153
|
+
await TestLifecycleListeners.emitDidRunBeforeAll();
|
154
154
|
}
|
155
155
|
else if (hook === 'afterAll') {
|
156
|
-
await TestLifecycleListeners.
|
156
|
+
await TestLifecycleListeners.emitDidRunAfterAll();
|
157
157
|
}
|
158
158
|
}
|
159
159
|
});
|
@@ -1,36 +1,36 @@
|
|
1
1
|
type TestLifecycleListener = () => any | Promise<any>;
|
2
2
|
type TestLifecycleListenerWithTest = (Test: any) => any | Promise<any>;
|
3
3
|
export declare class TestLifecycleListeners {
|
4
|
-
static
|
5
|
-
static
|
6
|
-
static
|
7
|
-
static
|
8
|
-
static
|
9
|
-
static
|
10
|
-
static
|
11
|
-
static
|
12
|
-
static
|
13
|
-
static
|
14
|
-
static
|
15
|
-
static
|
16
|
-
static
|
17
|
-
static
|
18
|
-
static
|
19
|
-
static
|
4
|
+
static willBeforeAllListeners: TestLifecycleListener[];
|
5
|
+
static didBeforeAllListeners: TestLifecycleListener[];
|
6
|
+
static willBeforeEachListeners: TestLifecycleListenerWithTest[];
|
7
|
+
static didBeforeEachListeners: TestLifecycleListenerWithTest[];
|
8
|
+
static willAfterEachListeners: TestLifecycleListenerWithTest[];
|
9
|
+
static didAfterEachListeners: TestLifecycleListenerWithTest[];
|
10
|
+
static willAfterAllListeners: TestLifecycleListener[];
|
11
|
+
static didAfterAllListeners: TestLifecycleListener[];
|
12
|
+
static emitWillRunBeforeAll(): Promise<void>;
|
13
|
+
static emitDidRunBeforeAll(): Promise<void>;
|
14
|
+
static emitWillRunBeforeEach(): Promise<void>;
|
15
|
+
static emitDidRunBeforeEach(): Promise<void>;
|
16
|
+
static emitWillRunAfterEach(): Promise<void>;
|
17
|
+
static emitDidRunAfterEach(): Promise<void>;
|
18
|
+
static emitWillRunAfterAll(): Promise<void>;
|
19
|
+
static emitDidRunAfterAll(): Promise<void>;
|
20
20
|
}
|
21
21
|
export declare class SpruceTestResolver {
|
22
22
|
static ActiveTestClass?: any;
|
23
23
|
private static __activeTest;
|
24
24
|
static resolveTestClass(target: any): any;
|
25
25
|
static getActiveTest(): any;
|
26
|
-
static
|
27
|
-
static
|
28
|
-
static
|
29
|
-
static
|
30
|
-
static
|
31
|
-
static
|
32
|
-
static
|
33
|
-
static
|
26
|
+
static onWillCallBeforeAll(cb: TestLifecycleListener): void;
|
27
|
+
static onDidBeforeAll(cb: TestLifecycleListener): void;
|
28
|
+
static onWillCallBeforeEach(cb: TestLifecycleListenerWithTest): void;
|
29
|
+
static onDidCallBeforeEach(cb: TestLifecycleListenerWithTest): void;
|
30
|
+
static onWillCallAfterEach(cb: TestLifecycleListenerWithTest): void;
|
31
|
+
static onDidCallAfterEach(cb: TestLifecycleListenerWithTest): void;
|
32
|
+
static onWillCallAfterAll(cb: TestLifecycleListener): void;
|
33
|
+
static onDidCallAfterAll(cb: TestLifecycleListener): void;
|
34
34
|
}
|
35
35
|
/** Test decorator */
|
36
36
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
package/build/esm/decorators.js
CHANGED
@@ -3,55 +3,55 @@ if (typeof it === 'undefined') {
|
|
3
3
|
global.it = () => { };
|
4
4
|
}
|
5
5
|
export class TestLifecycleListeners {
|
6
|
-
static async
|
7
|
-
for (const cb of this.
|
6
|
+
static async emitWillRunBeforeAll() {
|
7
|
+
for (const cb of this.willBeforeAllListeners) {
|
8
8
|
await cb();
|
9
9
|
}
|
10
10
|
}
|
11
|
-
static async
|
12
|
-
for (const cb of this.
|
11
|
+
static async emitDidRunBeforeAll() {
|
12
|
+
for (const cb of this.didBeforeAllListeners) {
|
13
13
|
await cb();
|
14
14
|
}
|
15
15
|
}
|
16
|
-
static async
|
17
|
-
for (const cb of this.
|
16
|
+
static async emitWillRunBeforeEach() {
|
17
|
+
for (const cb of this.willBeforeEachListeners) {
|
18
18
|
await cb(SpruceTestResolver.getActiveTest());
|
19
19
|
}
|
20
20
|
}
|
21
|
-
static async
|
22
|
-
for (const cb of this.
|
21
|
+
static async emitDidRunBeforeEach() {
|
22
|
+
for (const cb of this.didBeforeEachListeners) {
|
23
23
|
await cb(SpruceTestResolver.getActiveTest());
|
24
24
|
}
|
25
25
|
}
|
26
|
-
static async
|
27
|
-
for (const cb of this.
|
26
|
+
static async emitWillRunAfterEach() {
|
27
|
+
for (const cb of this.willAfterEachListeners) {
|
28
28
|
await cb(SpruceTestResolver.getActiveTest());
|
29
29
|
}
|
30
30
|
}
|
31
|
-
static async
|
32
|
-
for (const cb of this.
|
31
|
+
static async emitDidRunAfterEach() {
|
32
|
+
for (const cb of this.didAfterEachListeners) {
|
33
33
|
await cb(SpruceTestResolver.getActiveTest());
|
34
34
|
}
|
35
35
|
}
|
36
|
-
static async
|
37
|
-
for (const cb of this.
|
36
|
+
static async emitWillRunAfterAll() {
|
37
|
+
for (const cb of this.willAfterAllListeners) {
|
38
38
|
await cb();
|
39
39
|
}
|
40
40
|
}
|
41
|
-
static async
|
42
|
-
for (const cb of this.
|
41
|
+
static async emitDidRunAfterAll() {
|
42
|
+
for (const cb of this.didAfterAllListeners) {
|
43
43
|
await cb();
|
44
44
|
}
|
45
45
|
}
|
46
46
|
}
|
47
|
-
TestLifecycleListeners.
|
48
|
-
TestLifecycleListeners.
|
49
|
-
TestLifecycleListeners.
|
50
|
-
TestLifecycleListeners.
|
51
|
-
TestLifecycleListeners.
|
52
|
-
TestLifecycleListeners.
|
53
|
-
TestLifecycleListeners.
|
54
|
-
TestLifecycleListeners.
|
47
|
+
TestLifecycleListeners.willBeforeAllListeners = [];
|
48
|
+
TestLifecycleListeners.didBeforeAllListeners = [];
|
49
|
+
TestLifecycleListeners.willBeforeEachListeners = [];
|
50
|
+
TestLifecycleListeners.didBeforeEachListeners = [];
|
51
|
+
TestLifecycleListeners.willAfterEachListeners = [];
|
52
|
+
TestLifecycleListeners.didAfterEachListeners = [];
|
53
|
+
TestLifecycleListeners.willAfterAllListeners = [];
|
54
|
+
TestLifecycleListeners.didAfterAllListeners = [];
|
55
55
|
export class SpruceTestResolver {
|
56
56
|
static resolveTestClass(target) {
|
57
57
|
if (!this.__activeTest) {
|
@@ -64,29 +64,29 @@ export class SpruceTestResolver {
|
|
64
64
|
static getActiveTest() {
|
65
65
|
return this.__activeTest;
|
66
66
|
}
|
67
|
-
static
|
68
|
-
TestLifecycleListeners.
|
67
|
+
static onWillCallBeforeAll(cb) {
|
68
|
+
TestLifecycleListeners.willBeforeAllListeners.push(cb);
|
69
69
|
}
|
70
|
-
static
|
71
|
-
TestLifecycleListeners.
|
70
|
+
static onDidBeforeAll(cb) {
|
71
|
+
TestLifecycleListeners.didBeforeAllListeners.push(cb);
|
72
72
|
}
|
73
|
-
static
|
74
|
-
TestLifecycleListeners.
|
73
|
+
static onWillCallBeforeEach(cb) {
|
74
|
+
TestLifecycleListeners.willBeforeEachListeners.push(cb);
|
75
75
|
}
|
76
|
-
static
|
77
|
-
TestLifecycleListeners.
|
76
|
+
static onDidCallBeforeEach(cb) {
|
77
|
+
TestLifecycleListeners.didBeforeEachListeners.push(cb);
|
78
78
|
}
|
79
|
-
static
|
80
|
-
TestLifecycleListeners.
|
79
|
+
static onWillCallAfterEach(cb) {
|
80
|
+
TestLifecycleListeners.willAfterEachListeners.push(cb);
|
81
81
|
}
|
82
|
-
static
|
83
|
-
TestLifecycleListeners.
|
82
|
+
static onDidCallAfterEach(cb) {
|
83
|
+
TestLifecycleListeners.didAfterEachListeners.push(cb);
|
84
84
|
}
|
85
|
-
static
|
86
|
-
TestLifecycleListeners.
|
85
|
+
static onWillCallAfterAll(cb) {
|
86
|
+
TestLifecycleListeners.willAfterAllListeners.push(cb);
|
87
87
|
}
|
88
|
-
static
|
89
|
-
TestLifecycleListeners.
|
88
|
+
static onDidCallAfterAll(cb) {
|
89
|
+
TestLifecycleListeners.didAfterAllListeners.push(cb);
|
90
90
|
}
|
91
91
|
}
|
92
92
|
//recursive function to get static method by name looping up through constructor chain
|
@@ -118,23 +118,23 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
118
118
|
global[hook](async () => {
|
119
119
|
if (hook === 'beforeEach') {
|
120
120
|
SpruceTestResolver.resolveTestClass(Target);
|
121
|
-
await TestLifecycleListeners.
|
121
|
+
await TestLifecycleListeners.emitWillRunBeforeEach();
|
122
122
|
await runBeforeEach(Target);
|
123
|
-
await TestLifecycleListeners.
|
123
|
+
await TestLifecycleListeners.emitDidRunBeforeEach();
|
124
124
|
}
|
125
125
|
else if (hook === 'afterEach') {
|
126
|
-
await TestLifecycleListeners.
|
126
|
+
await TestLifecycleListeners.emitWillRunAfterEach();
|
127
127
|
await runAfterEach(Target);
|
128
|
-
await TestLifecycleListeners.
|
128
|
+
await TestLifecycleListeners.emitDidRunAfterEach();
|
129
129
|
// @ts-ignore
|
130
130
|
delete SpruceTestResolver.__activeTest;
|
131
131
|
}
|
132
132
|
else {
|
133
133
|
if (hook === 'beforeAll') {
|
134
|
-
await TestLifecycleListeners.
|
134
|
+
await TestLifecycleListeners.emitWillRunBeforeAll();
|
135
135
|
}
|
136
136
|
else if (hook === 'afterAll') {
|
137
|
-
await TestLifecycleListeners.
|
137
|
+
await TestLifecycleListeners.emitWillRunAfterAll();
|
138
138
|
}
|
139
139
|
if (SpruceTestResolver.ActiveTestClass) {
|
140
140
|
await cb.apply(Target.constructor);
|
@@ -143,10 +143,10 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
143
143
|
await cb.apply(Target);
|
144
144
|
}
|
145
145
|
if (hook === 'beforeAll') {
|
146
|
-
await TestLifecycleListeners.
|
146
|
+
await TestLifecycleListeners.emitDidRunBeforeAll();
|
147
147
|
}
|
148
148
|
else if (hook === 'afterAll') {
|
149
|
-
await TestLifecycleListeners.
|
149
|
+
await TestLifecycleListeners.emitDidRunAfterAll();
|
150
150
|
}
|
151
151
|
}
|
152
152
|
});
|