@sprucelabs/test-utils 5.3.4 → 5.4.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/build/decorators.d.ts +6 -0
- package/build/decorators.js +21 -7
- package/build/esm/decorators.d.ts +6 -0
- package/build/esm/decorators.js +19 -7
- package/package.json +1 -1
package/build/decorators.d.ts
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
export declare class SpruceTestDecoratorResolver {
|
2
|
+
static ActiveTestClass?: any;
|
3
|
+
private static __activeTest;
|
4
|
+
static resolveActiveTest(target: any): any;
|
5
|
+
static getActiveTest(): any;
|
6
|
+
}
|
1
7
|
/** Test decorator */
|
2
8
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
3
9
|
declare namespace test {
|
package/build/decorators.js
CHANGED
@@ -1,16 +1,24 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SpruceTestDecoratorResolver = void 0;
|
3
4
|
exports.default = test;
|
4
5
|
exports.suite = suite;
|
5
6
|
if (typeof it === 'undefined') {
|
6
7
|
//@ts-ignore
|
7
8
|
global.it = () => { };
|
8
9
|
}
|
9
|
-
class
|
10
|
+
class SpruceTestDecoratorResolver {
|
10
11
|
static resolveActiveTest(target) {
|
11
|
-
|
12
|
+
this.__activeTest = this.ActiveTestClass
|
13
|
+
? new this.ActiveTestClass()
|
14
|
+
: target;
|
15
|
+
return this.__activeTest;
|
16
|
+
}
|
17
|
+
static getActiveTest() {
|
18
|
+
return this.__activeTest;
|
12
19
|
}
|
13
20
|
}
|
21
|
+
exports.SpruceTestDecoratorResolver = SpruceTestDecoratorResolver;
|
14
22
|
/** Hooks up before, after, etc. */
|
15
23
|
function hookupTestClass(target, h) {
|
16
24
|
if (target.__isTestingHookedUp) {
|
@@ -23,13 +31,19 @@ function hookupTestClass(target, h) {
|
|
23
31
|
if (!target[hook]) {
|
24
32
|
return;
|
25
33
|
}
|
26
|
-
if (
|
34
|
+
if (SpruceTestDecoratorResolver.ActiveTestClass &&
|
35
|
+
!h &&
|
36
|
+
hook === 'beforeAll') {
|
27
37
|
throw new Error(`beforeAll() and afterAll() must be static`);
|
28
38
|
}
|
29
39
|
// @ts-ignore
|
30
40
|
if (global[hook]) {
|
31
41
|
// @ts-ignore
|
32
42
|
global[hook](async () => {
|
43
|
+
if (hook === 'afterAll') {
|
44
|
+
//@ts-ignore
|
45
|
+
SpruceTestDecoratorResolver.__activeTest = null;
|
46
|
+
}
|
33
47
|
return target[hook]();
|
34
48
|
});
|
35
49
|
}
|
@@ -42,7 +56,7 @@ function test(description, ...args) {
|
|
42
56
|
hookupTestClass(target);
|
43
57
|
// Make sure each test gets the spruce
|
44
58
|
it(description ?? propertyKey, async () => {
|
45
|
-
const testClass =
|
59
|
+
const testClass = SpruceTestDecoratorResolver.resolveActiveTest(target);
|
46
60
|
const bound = descriptor.value.bind(testClass);
|
47
61
|
//@ts-ignore
|
48
62
|
global.activeTest = {
|
@@ -55,7 +69,7 @@ function test(description, ...args) {
|
|
55
69
|
}
|
56
70
|
function suite() {
|
57
71
|
return function (Target) {
|
58
|
-
|
72
|
+
SpruceTestDecoratorResolver.ActiveTestClass = Target;
|
59
73
|
// Test.activeTest.__isTestingHookedUp = false
|
60
74
|
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
61
75
|
};
|
@@ -67,7 +81,7 @@ test.only = (description, ...args) => {
|
|
67
81
|
hookupTestClass(target);
|
68
82
|
// Make sure each test gets the spruce
|
69
83
|
it.only(description ?? propertyKey, async () => {
|
70
|
-
const bound = descriptor.value.bind(
|
84
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
71
85
|
return bound(...args);
|
72
86
|
});
|
73
87
|
};
|
@@ -88,7 +102,7 @@ test.skip = (description, ...args) => {
|
|
88
102
|
hookupTestClass(target);
|
89
103
|
// Make sure each test gets the spruce
|
90
104
|
it.skip(description ?? propertyKey, async () => {
|
91
|
-
const bound = descriptor.value.bind(
|
105
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
92
106
|
return bound(...args);
|
93
107
|
});
|
94
108
|
};
|
@@ -1,3 +1,9 @@
|
|
1
|
+
export declare class SpruceTestDecoratorResolver {
|
2
|
+
static ActiveTestClass?: any;
|
3
|
+
private static __activeTest;
|
4
|
+
static resolveActiveTest(target: any): any;
|
5
|
+
static getActiveTest(): any;
|
6
|
+
}
|
1
7
|
/** Test decorator */
|
2
8
|
declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
3
9
|
declare namespace test {
|
package/build/esm/decorators.js
CHANGED
@@ -2,9 +2,15 @@ if (typeof it === 'undefined') {
|
|
2
2
|
//@ts-ignore
|
3
3
|
global.it = () => { };
|
4
4
|
}
|
5
|
-
class
|
5
|
+
export class SpruceTestDecoratorResolver {
|
6
6
|
static resolveActiveTest(target) {
|
7
|
-
|
7
|
+
this.__activeTest = this.ActiveTestClass
|
8
|
+
? new this.ActiveTestClass()
|
9
|
+
: target;
|
10
|
+
return this.__activeTest;
|
11
|
+
}
|
12
|
+
static getActiveTest() {
|
13
|
+
return this.__activeTest;
|
8
14
|
}
|
9
15
|
}
|
10
16
|
/** Hooks up before, after, etc. */
|
@@ -19,13 +25,19 @@ function hookupTestClass(target, h) {
|
|
19
25
|
if (!target[hook]) {
|
20
26
|
return;
|
21
27
|
}
|
22
|
-
if (
|
28
|
+
if (SpruceTestDecoratorResolver.ActiveTestClass &&
|
29
|
+
!h &&
|
30
|
+
hook === 'beforeAll') {
|
23
31
|
throw new Error(`beforeAll() and afterAll() must be static`);
|
24
32
|
}
|
25
33
|
// @ts-ignore
|
26
34
|
if (global[hook]) {
|
27
35
|
// @ts-ignore
|
28
36
|
global[hook](async () => {
|
37
|
+
if (hook === 'afterAll') {
|
38
|
+
//@ts-ignore
|
39
|
+
SpruceTestDecoratorResolver.__activeTest = null;
|
40
|
+
}
|
29
41
|
return target[hook]();
|
30
42
|
});
|
31
43
|
}
|
@@ -38,7 +50,7 @@ export default function test(description, ...args) {
|
|
38
50
|
hookupTestClass(target);
|
39
51
|
// Make sure each test gets the spruce
|
40
52
|
it(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
41
|
-
const testClass =
|
53
|
+
const testClass = SpruceTestDecoratorResolver.resolveActiveTest(target);
|
42
54
|
const bound = descriptor.value.bind(testClass);
|
43
55
|
//@ts-ignore
|
44
56
|
global.activeTest = {
|
@@ -51,7 +63,7 @@ export default function test(description, ...args) {
|
|
51
63
|
}
|
52
64
|
export function suite() {
|
53
65
|
return function (Target) {
|
54
|
-
|
66
|
+
SpruceTestDecoratorResolver.ActiveTestClass = Target;
|
55
67
|
// Test.activeTest.__isTestingHookedUp = false
|
56
68
|
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
57
69
|
};
|
@@ -63,7 +75,7 @@ test.only = (description, ...args) => {
|
|
63
75
|
hookupTestClass(target);
|
64
76
|
// Make sure each test gets the spruce
|
65
77
|
it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
66
|
-
const bound = descriptor.value.bind(
|
78
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
67
79
|
return bound(...args);
|
68
80
|
});
|
69
81
|
};
|
@@ -84,7 +96,7 @@ test.skip = (description, ...args) => {
|
|
84
96
|
hookupTestClass(target);
|
85
97
|
// Make sure each test gets the spruce
|
86
98
|
it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
87
|
-
const bound = descriptor.value.bind(
|
99
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
88
100
|
return bound(...args);
|
89
101
|
});
|
90
102
|
};
|