@sprucelabs/test-utils 5.5.17 → 5.5.19

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
  export default class AbstractSpruceTest {
2
- protected static cwd: string;
2
+ static cwd: string;
3
3
  protected static beforeAll(): Promise<void>;
4
4
  protected static afterAll(): Promise<void>;
5
5
  protected static beforeEach(): Promise<void>;
@@ -7,7 +7,7 @@ export default class AbstractSpruceTest {
7
7
  protected static resolvePath(...filePath: string[]): string;
8
8
  protected static wait(ms?: number): Promise<unknown>;
9
9
  protected static log(...args: any[]): void;
10
- protected cwd: string;
10
+ cwd: string;
11
11
  protected wait(ms?: number): Promise<unknown>;
12
12
  protected log(...args: any[]): void;
13
13
  protected resolvePath(...filePath: string[]): string;
@@ -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
  export default class AbstractSpruceTest {
2
- protected static cwd: string;
2
+ static cwd: string;
3
3
  protected static beforeAll(): Promise<void>;
4
4
  protected static afterAll(): Promise<void>;
5
5
  protected static beforeEach(): Promise<void>;
@@ -7,7 +7,7 @@ export default class AbstractSpruceTest {
7
7
  protected static resolvePath(...filePath: string[]): string;
8
8
  protected static wait(ms?: number): Promise<unknown>;
9
9
  protected static log(...args: any[]): void;
10
- protected cwd: string;
10
+ cwd: string;
11
11
  protected wait(ms?: number): Promise<unknown>;
12
12
  protected log(...args: any[]): void;
13
13
  protected resolvePath(...filePath: string[]): string;
@@ -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.17",
6
+ "version": "5.5.19",
7
7
  "files": [
8
8
  "build"
9
9
  ],