@sprucelabs/test-utils 5.3.4 → 5.3.5
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.js +8 -6
- package/build/esm/decorators.js +8 -6
- package/package.json +1 -1
package/build/decorators.js
CHANGED
@@ -6,7 +6,7 @@ if (typeof it === 'undefined') {
|
|
6
6
|
//@ts-ignore
|
7
7
|
global.it = () => { };
|
8
8
|
}
|
9
|
-
class
|
9
|
+
class SpruceTestDecoratorResolver {
|
10
10
|
static resolveActiveTest(target) {
|
11
11
|
return this.ActiveTestClass ? new this.ActiveTestClass() : target;
|
12
12
|
}
|
@@ -23,7 +23,9 @@ function hookupTestClass(target, h) {
|
|
23
23
|
if (!target[hook]) {
|
24
24
|
return;
|
25
25
|
}
|
26
|
-
if (
|
26
|
+
if (SpruceTestDecoratorResolver.ActiveTestClass &&
|
27
|
+
!h &&
|
28
|
+
hook === 'beforeAll') {
|
27
29
|
throw new Error(`beforeAll() and afterAll() must be static`);
|
28
30
|
}
|
29
31
|
// @ts-ignore
|
@@ -42,7 +44,7 @@ function test(description, ...args) {
|
|
42
44
|
hookupTestClass(target);
|
43
45
|
// Make sure each test gets the spruce
|
44
46
|
it(description ?? propertyKey, async () => {
|
45
|
-
const testClass =
|
47
|
+
const testClass = SpruceTestDecoratorResolver.resolveActiveTest(target);
|
46
48
|
const bound = descriptor.value.bind(testClass);
|
47
49
|
//@ts-ignore
|
48
50
|
global.activeTest = {
|
@@ -55,7 +57,7 @@ function test(description, ...args) {
|
|
55
57
|
}
|
56
58
|
function suite() {
|
57
59
|
return function (Target) {
|
58
|
-
|
60
|
+
SpruceTestDecoratorResolver.ActiveTestClass = Target;
|
59
61
|
// Test.activeTest.__isTestingHookedUp = false
|
60
62
|
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
61
63
|
};
|
@@ -67,7 +69,7 @@ test.only = (description, ...args) => {
|
|
67
69
|
hookupTestClass(target);
|
68
70
|
// Make sure each test gets the spruce
|
69
71
|
it.only(description ?? propertyKey, async () => {
|
70
|
-
const bound = descriptor.value.bind(
|
72
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
71
73
|
return bound(...args);
|
72
74
|
});
|
73
75
|
};
|
@@ -88,7 +90,7 @@ test.skip = (description, ...args) => {
|
|
88
90
|
hookupTestClass(target);
|
89
91
|
// Make sure each test gets the spruce
|
90
92
|
it.skip(description ?? propertyKey, async () => {
|
91
|
-
const bound = descriptor.value.bind(
|
93
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
92
94
|
return bound(...args);
|
93
95
|
});
|
94
96
|
};
|
package/build/esm/decorators.js
CHANGED
@@ -2,7 +2,7 @@ if (typeof it === 'undefined') {
|
|
2
2
|
//@ts-ignore
|
3
3
|
global.it = () => { };
|
4
4
|
}
|
5
|
-
class
|
5
|
+
class SpruceTestDecoratorResolver {
|
6
6
|
static resolveActiveTest(target) {
|
7
7
|
return this.ActiveTestClass ? new this.ActiveTestClass() : target;
|
8
8
|
}
|
@@ -19,7 +19,9 @@ function hookupTestClass(target, h) {
|
|
19
19
|
if (!target[hook]) {
|
20
20
|
return;
|
21
21
|
}
|
22
|
-
if (
|
22
|
+
if (SpruceTestDecoratorResolver.ActiveTestClass &&
|
23
|
+
!h &&
|
24
|
+
hook === 'beforeAll') {
|
23
25
|
throw new Error(`beforeAll() and afterAll() must be static`);
|
24
26
|
}
|
25
27
|
// @ts-ignore
|
@@ -38,7 +40,7 @@ export default function test(description, ...args) {
|
|
38
40
|
hookupTestClass(target);
|
39
41
|
// Make sure each test gets the spruce
|
40
42
|
it(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
41
|
-
const testClass =
|
43
|
+
const testClass = SpruceTestDecoratorResolver.resolveActiveTest(target);
|
42
44
|
const bound = descriptor.value.bind(testClass);
|
43
45
|
//@ts-ignore
|
44
46
|
global.activeTest = {
|
@@ -51,7 +53,7 @@ export default function test(description, ...args) {
|
|
51
53
|
}
|
52
54
|
export function suite() {
|
53
55
|
return function (Target) {
|
54
|
-
|
56
|
+
SpruceTestDecoratorResolver.ActiveTestClass = Target;
|
55
57
|
// Test.activeTest.__isTestingHookedUp = false
|
56
58
|
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
57
59
|
};
|
@@ -63,7 +65,7 @@ test.only = (description, ...args) => {
|
|
63
65
|
hookupTestClass(target);
|
64
66
|
// Make sure each test gets the spruce
|
65
67
|
it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
66
|
-
const bound = descriptor.value.bind(
|
68
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
67
69
|
return bound(...args);
|
68
70
|
});
|
69
71
|
};
|
@@ -84,7 +86,7 @@ test.skip = (description, ...args) => {
|
|
84
86
|
hookupTestClass(target);
|
85
87
|
// Make sure each test gets the spruce
|
86
88
|
it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
87
|
-
const bound = descriptor.value.bind(
|
89
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
88
90
|
return bound(...args);
|
89
91
|
});
|
90
92
|
};
|