@sprucelabs/test-utils 5.4.2 → 5.4.3
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 +1 -1
- package/build/decorators.js +17 -3
- package/build/esm/decorators.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
package/build/decorators.js
CHANGED
@@ -21,6 +21,16 @@ class SpruceTestResolver {
|
|
21
21
|
}
|
22
22
|
}
|
23
23
|
exports.SpruceTestResolver = SpruceTestResolver;
|
24
|
+
//recursive function to get static method by name looping up through constructor chain
|
25
|
+
function resolveMethod(Target, name) {
|
26
|
+
if (Target[name]) {
|
27
|
+
return Target[name];
|
28
|
+
}
|
29
|
+
if (Target.constructor && Target.constructor !== Target) {
|
30
|
+
return resolveMethod(Target.constructor, name);
|
31
|
+
}
|
32
|
+
return null;
|
33
|
+
}
|
24
34
|
/** Hooks up before, after, etc. */
|
25
35
|
function hookupTestClassToJestLifecycle(Target, h) {
|
26
36
|
if (Target.__isTestingHookedUp) {
|
@@ -29,10 +39,9 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
29
39
|
Target.__isTestingHookedUp = !h;
|
30
40
|
const hooks = h ?? ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
|
31
41
|
hooks.forEach((hook) => {
|
32
|
-
const cb = Target
|
42
|
+
const cb = resolveMethod(Target, hook);
|
33
43
|
// Have they defined a hook
|
34
44
|
if (!cb) {
|
35
|
-
debugger;
|
36
45
|
return;
|
37
46
|
}
|
38
47
|
// @ts-ignore
|
@@ -48,7 +57,12 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
48
57
|
delete SpruceTestResolver.__activeTest;
|
49
58
|
}
|
50
59
|
else {
|
51
|
-
|
60
|
+
if (SpruceTestResolver.ActiveTestClass) {
|
61
|
+
await cb.apply(Target.constructor);
|
62
|
+
}
|
63
|
+
else {
|
64
|
+
await cb.apply(Target);
|
65
|
+
}
|
52
66
|
}
|
53
67
|
});
|
54
68
|
}
|
package/build/esm/decorators.js
CHANGED
@@ -15,6 +15,16 @@ export class SpruceTestResolver {
|
|
15
15
|
return this.__activeTest;
|
16
16
|
}
|
17
17
|
}
|
18
|
+
//recursive function to get static method by name looping up through constructor chain
|
19
|
+
function resolveMethod(Target, name) {
|
20
|
+
if (Target[name]) {
|
21
|
+
return Target[name];
|
22
|
+
}
|
23
|
+
if (Target.constructor && Target.constructor !== Target) {
|
24
|
+
return resolveMethod(Target.constructor, name);
|
25
|
+
}
|
26
|
+
return null;
|
27
|
+
}
|
18
28
|
/** Hooks up before, after, etc. */
|
19
29
|
function hookupTestClassToJestLifecycle(Target, h) {
|
20
30
|
if (Target.__isTestingHookedUp) {
|
@@ -23,11 +33,9 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
23
33
|
Target.__isTestingHookedUp = !h;
|
24
34
|
const hooks = h !== null && h !== void 0 ? h : ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
|
25
35
|
hooks.forEach((hook) => {
|
26
|
-
|
27
|
-
const cb = (_a = Target[hook]) !== null && _a !== void 0 ? _a : (_b = Target === null || Target === void 0 ? void 0 : Target.constructor) === null || _b === void 0 ? void 0 : _b[hook];
|
36
|
+
const cb = resolveMethod(Target, hook);
|
28
37
|
// Have they defined a hook
|
29
38
|
if (!cb) {
|
30
|
-
debugger;
|
31
39
|
return;
|
32
40
|
}
|
33
41
|
// @ts-ignore
|
@@ -43,7 +51,12 @@ function hookupTestClassToJestLifecycle(Target, h) {
|
|
43
51
|
delete SpruceTestResolver.__activeTest;
|
44
52
|
}
|
45
53
|
else {
|
46
|
-
|
54
|
+
if (SpruceTestResolver.ActiveTestClass) {
|
55
|
+
await cb.apply(Target.constructor);
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
await cb.apply(Target);
|
59
|
+
}
|
47
60
|
}
|
48
61
|
});
|
49
62
|
}
|