@sprucelabs/test-utils 5.5.18 → 5.5.20

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.
@@ -1,5 +1,5 @@
1
1
  /** Test decorator */
2
- declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
2
+ declare function test(description?: string, ...args: any[]): (Target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
3
3
  declare namespace test {
4
4
  var only: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
5
5
  var todo: (description?: string, ..._args: any[]) => (target: any, propertyKey: string) => void;
@@ -40,6 +40,7 @@ if (typeof it === 'undefined') {
40
40
  //@ts-ignore
41
41
  global.it = () => { };
42
42
  }
43
+ let areLifecycleHooksInPlace = false;
43
44
  //recursive function to get static method by name looping up through constructor chain
44
45
  function resolveMethod(Target, name) {
45
46
  if (Target[name]) {
@@ -52,10 +53,10 @@ function resolveMethod(Target, name) {
52
53
  }
53
54
  /** Hooks up before, after, etc. */
54
55
  function hookupTestClassToJestLifecycle(Target) {
55
- if (Target.__areLifecycleHooksInPlace) {
56
+ if (areLifecycleHooksInPlace) {
56
57
  return;
57
58
  }
58
- Target.__areLifecycleHooksInPlace = true;
59
+ areLifecycleHooksInPlace = true;
59
60
  const hooks = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
60
61
  hooks.forEach((hook) => {
61
62
  // @ts-ignore
@@ -125,15 +126,18 @@ async function runBeforeEach(Target) {
125
126
  }
126
127
  /** Test decorator */
127
128
  function test(description, ...args) {
128
- return function (target, propertyKey, descriptor) {
129
- hookupTestClassToJestLifecycle(target);
129
+ return function (Target, propertyKey, descriptor) {
130
+ hookupTestClassToJestLifecycle(Target);
130
131
  // Make sure each test gets the spruce
131
132
  it(description ?? propertyKey, async () => {
132
- const testClass = SpruceTestResolver_1.default.resolveTestClass(target);
133
- const bound = descriptor.value.bind(testClass);
133
+ const Resolved = SpruceTestResolver_1.default.resolveTestClass(Target);
134
+ if (!Resolved[propertyKey]) {
135
+ throw new Error(`The test '${propertyKey}()' should NOT be static when tests run with suite()`);
136
+ }
137
+ const bound = descriptor.value.bind(Resolved);
134
138
  //@ts-ignore
135
139
  global.activeTest = {
136
- file: target.name,
140
+ file: Target.name,
137
141
  test: propertyKey,
138
142
  };
139
143
  return bound(...args);
@@ -1,5 +1,5 @@
1
1
  /** Test decorator */
2
- declare function test(description?: string, ...args: any[]): (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
2
+ declare function test(description?: string, ...args: any[]): (Target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
3
3
  declare namespace test {
4
4
  var only: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
5
5
  var todo: (description?: string, ..._args: any[]) => (target: any, propertyKey: string) => void;
@@ -3,6 +3,7 @@ if (typeof it === 'undefined') {
3
3
  //@ts-ignore
4
4
  global.it = () => { };
5
5
  }
6
+ let areLifecycleHooksInPlace = false;
6
7
  //recursive function to get static method by name looping up through constructor chain
7
8
  function resolveMethod(Target, name) {
8
9
  if (Target[name]) {
@@ -15,10 +16,10 @@ function resolveMethod(Target, name) {
15
16
  }
16
17
  /** Hooks up before, after, etc. */
17
18
  function hookupTestClassToJestLifecycle(Target) {
18
- if (Target.__areLifecycleHooksInPlace) {
19
+ if (areLifecycleHooksInPlace) {
19
20
  return;
20
21
  }
21
- Target.__areLifecycleHooksInPlace = true;
22
+ areLifecycleHooksInPlace = true;
22
23
  const hooks = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
23
24
  hooks.forEach((hook) => {
24
25
  // @ts-ignore
@@ -91,15 +92,18 @@ async function runBeforeEach(Target) {
91
92
  }
92
93
  /** Test decorator */
93
94
  export default function test(description, ...args) {
94
- return function (target, propertyKey, descriptor) {
95
- hookupTestClassToJestLifecycle(target);
95
+ return function (Target, propertyKey, descriptor) {
96
+ hookupTestClassToJestLifecycle(Target);
96
97
  // Make sure each test gets the spruce
97
98
  it(description !== null && description !== void 0 ? description : propertyKey, async () => {
98
- const testClass = SpruceTestResolver.resolveTestClass(target);
99
- const bound = descriptor.value.bind(testClass);
99
+ const Resolved = SpruceTestResolver.resolveTestClass(Target);
100
+ if (!Resolved[propertyKey]) {
101
+ throw new Error(`The test '${propertyKey}()' should NOT be static when tests run with suite()`);
102
+ }
103
+ const bound = descriptor.value.bind(Resolved);
100
104
  //@ts-ignore
101
105
  global.activeTest = {
102
- file: target.name,
106
+ file: Target.name,
103
107
  test: propertyKey,
104
108
  };
105
109
  return bound(...args);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "5.5.18",
6
+ "version": "5.5.20",
7
7
  "files": [
8
8
  "build"
9
9
  ],
@@ -60,7 +60,7 @@
60
60
  "watch.tsc": "tsc -w"
61
61
  },
62
62
  "dependencies": {
63
- "@sprucelabs/error": "^6.0.584",
63
+ "@sprucelabs/error": "^6.0.585",
64
64
  "deep-equal": "^2.2.3",
65
65
  "just-clone": "^6.2.0",
66
66
  "lodash": "^4.17.21",
@@ -72,13 +72,13 @@
72
72
  "@sprucelabs/jest-json-reporter": "^8.0.585",
73
73
  "@sprucelabs/jest-sheets-reporter": "^2.0.20",
74
74
  "@sprucelabs/semantic-release": "^5.0.2",
75
- "@sprucelabs/test": "^9.0.75",
75
+ "@sprucelabs/test": "^9.0.76",
76
76
  "@types/deep-equal": "^1.0.4",
77
77
  "@types/jest": "^29.5.14",
78
78
  "@types/lodash": "^4.17.16",
79
- "@types/node": "^22.13.9",
79
+ "@types/node": "^22.13.10",
80
80
  "chokidar-cli": "^3.0.0",
81
- "eslint": "^9.21.0",
81
+ "eslint": "^9.22.0",
82
82
  "eslint-config-spruce": "^11.2.26",
83
83
  "jest": "^29.7.0",
84
84
  "jest-circus": "^29.7.0",