@sprucelabs/test-utils 5.2.12 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,4 +7,11 @@ 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 wait(ms?: number): Promise<unknown>;
11
+ protected log(...args: any[]): void;
12
+ protected cwd: string;
13
+ protected beforeAll(): Promise<void>;
14
+ protected afterAll(): Promise<void>;
15
+ protected beforeEach(): Promise<void>;
16
+ protected afterEach(): Promise<void>;
10
17
  }
@@ -30,9 +30,22 @@ class AbstractSpruceTest {
30
30
  setTimeout(() => resolve(true), ms);
31
31
  });
32
32
  }
33
+ //instance declariations
33
34
  static log(...args) {
34
35
  const str = args.map((a) => `${a}`).join(' ');
35
36
  process.stderr.write(str);
36
37
  }
38
+ async wait(ms = 1000) {
39
+ return AbstractSpruceTest.wait(ms);
40
+ }
41
+ log(...args) {
42
+ AbstractSpruceTest.log(...args);
43
+ }
44
+ async beforeAll() {
45
+ this.cwd = process.cwd();
46
+ }
47
+ async afterAll() { }
48
+ async beforeEach() { }
49
+ async afterEach() { }
37
50
  }
38
51
  exports.default = AbstractSpruceTest;
@@ -6,3 +6,4 @@ declare namespace test {
6
6
  var skip: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
7
7
  }
8
8
  export default test;
9
+ export declare function suite(): (Target: any) => void;
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = test;
4
+ exports.suite = suite;
4
5
  if (typeof it === 'undefined') {
5
6
  //@ts-ignore
6
7
  global.it = () => { };
7
8
  }
9
+ class Test {
10
+ static resolveActiveTest(target) {
11
+ return this.ActiveTestClass ? new this.ActiveTestClass() : target;
12
+ }
13
+ }
8
14
  /** Hooks up before, after, etc. */
9
15
  function hookupTestClass(target) {
10
16
  if (target.__isTestingHookedUp) {
@@ -31,9 +37,10 @@ function test(description, ...args) {
31
37
  return function (target, propertyKey, descriptor) {
32
38
  // Lets attach before/after
33
39
  hookupTestClass(target);
34
- const bound = descriptor.value.bind(target);
35
40
  // Make sure each test gets the spruce
36
41
  it(description ?? propertyKey, async () => {
42
+ const testClass = Test.resolveActiveTest(target);
43
+ const bound = descriptor.value.bind(testClass);
37
44
  //@ts-ignore
38
45
  global.activeTest = {
39
46
  file: target.name,
@@ -43,14 +50,23 @@ function test(description, ...args) {
43
50
  });
44
51
  };
45
52
  }
53
+ function suite() {
54
+ return function (Target) {
55
+ Test.ActiveTestClass = Target;
56
+ // Test.activeTest.__isTestingHookedUp = false
57
+ // hookupTestClass(Test.activeTest)
58
+ };
59
+ }
46
60
  /** Only decorator */
47
61
  test.only = (description, ...args) => {
48
62
  return function (target, propertyKey, descriptor) {
49
63
  // Lets attach before/after
50
64
  hookupTestClass(target);
51
- const bound = descriptor.value.bind(target);
52
65
  // Make sure each test gets the spruce
53
66
  it.only(description ?? propertyKey, async () => {
67
+ debugger;
68
+ const bound = descriptor.value.bind(Test.resolveActiveTest(target));
69
+ debugger;
54
70
  return bound(...args);
55
71
  });
56
72
  };
@@ -69,9 +85,9 @@ test.skip = (description, ...args) => {
69
85
  return function (target, propertyKey, descriptor) {
70
86
  // Lets attach before/after
71
87
  hookupTestClass(target);
72
- const bound = descriptor.value.bind(target);
73
88
  // Make sure each test gets the spruce
74
89
  it.skip(description ?? propertyKey, async () => {
90
+ const bound = descriptor.value.bind(Test.resolveActiveTest(target));
75
91
  return bound(...args);
76
92
  });
77
93
  };
@@ -7,4 +7,11 @@ 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 wait(ms?: number): Promise<unknown>;
11
+ protected log(...args: any[]): void;
12
+ protected cwd: string;
13
+ protected beforeAll(): Promise<void>;
14
+ protected afterAll(): Promise<void>;
15
+ protected beforeEach(): Promise<void>;
16
+ protected afterEach(): Promise<void>;
10
17
  }
@@ -25,8 +25,21 @@ export default class AbstractSpruceTest {
25
25
  setTimeout(() => resolve(true), ms);
26
26
  });
27
27
  }
28
+ //instance declariations
28
29
  static log(...args) {
29
30
  const str = args.map((a) => `${a}`).join(' ');
30
31
  process.stderr.write(str);
31
32
  }
33
+ async wait(ms = 1000) {
34
+ return AbstractSpruceTest.wait(ms);
35
+ }
36
+ log(...args) {
37
+ AbstractSpruceTest.log(...args);
38
+ }
39
+ async beforeAll() {
40
+ this.cwd = process.cwd();
41
+ }
42
+ async afterAll() { }
43
+ async beforeEach() { }
44
+ async afterEach() { }
32
45
  }
@@ -6,3 +6,4 @@ declare namespace test {
6
6
  var skip: (description?: string, ...args: any[]) => (target: any, propertyKey: string, descriptor: PropertyDescriptor) => void;
7
7
  }
8
8
  export default test;
9
+ export declare function suite(): (Target: any) => void;
@@ -2,6 +2,11 @@ if (typeof it === 'undefined') {
2
2
  //@ts-ignore
3
3
  global.it = () => { };
4
4
  }
5
+ class Test {
6
+ static resolveActiveTest(target) {
7
+ return this.ActiveTestClass ? new this.ActiveTestClass() : target;
8
+ }
9
+ }
5
10
  /** Hooks up before, after, etc. */
6
11
  function hookupTestClass(target) {
7
12
  if (target.__isTestingHookedUp) {
@@ -28,9 +33,10 @@ export default function test(description, ...args) {
28
33
  return function (target, propertyKey, descriptor) {
29
34
  // Lets attach before/after
30
35
  hookupTestClass(target);
31
- const bound = descriptor.value.bind(target);
32
36
  // Make sure each test gets the spruce
33
37
  it(description !== null && description !== void 0 ? description : propertyKey, async () => {
38
+ const testClass = Test.resolveActiveTest(target);
39
+ const bound = descriptor.value.bind(testClass);
34
40
  //@ts-ignore
35
41
  global.activeTest = {
36
42
  file: target.name,
@@ -40,14 +46,23 @@ export default function test(description, ...args) {
40
46
  });
41
47
  };
42
48
  }
49
+ export function suite() {
50
+ return function (Target) {
51
+ Test.ActiveTestClass = Target;
52
+ // Test.activeTest.__isTestingHookedUp = false
53
+ // hookupTestClass(Test.activeTest)
54
+ };
55
+ }
43
56
  /** Only decorator */
44
57
  test.only = (description, ...args) => {
45
58
  return function (target, propertyKey, descriptor) {
46
59
  // Lets attach before/after
47
60
  hookupTestClass(target);
48
- const bound = descriptor.value.bind(target);
49
61
  // Make sure each test gets the spruce
50
62
  it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
63
+ debugger;
64
+ const bound = descriptor.value.bind(Test.resolveActiveTest(target));
65
+ debugger;
51
66
  return bound(...args);
52
67
  });
53
68
  };
@@ -66,9 +81,9 @@ test.skip = (description, ...args) => {
66
81
  return function (target, propertyKey, descriptor) {
67
82
  // Lets attach before/after
68
83
  hookupTestClass(target);
69
- const bound = descriptor.value.bind(target);
70
84
  // Make sure each test gets the spruce
71
85
  it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
86
+ const bound = descriptor.value.bind(Test.resolveActiveTest(target));
72
87
  return bound(...args);
73
88
  });
74
89
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "5.2.12",
6
+ "version": "5.3.0",
7
7
  "files": [
8
8
  "build"
9
9
  ],
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@sprucelabs/esm-postbuild": "^6.0.547",
72
- "@sprucelabs/jest-json-reporter": "^8.0.577",
72
+ "@sprucelabs/jest-json-reporter": "^8.0.578",
73
73
  "@sprucelabs/jest-sheets-reporter": "^2.0.20",
74
74
  "@sprucelabs/semantic-release": "^5.0.2",
75
75
  "@sprucelabs/test": "^9.0.71",