@sprucelabs/test-utils 5.3.1 → 5.3.3

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.
@@ -10,8 +10,6 @@ export default class AbstractSpruceTest {
10
10
  protected wait(ms?: number): Promise<unknown>;
11
11
  protected log(...args: any[]): void;
12
12
  protected cwd: string;
13
- protected beforeAll(): Promise<void>;
14
- protected afterAll(): Promise<void>;
15
13
  protected beforeEach(): Promise<void>;
16
14
  protected afterEach(): Promise<void>;
17
15
  }
@@ -41,10 +41,6 @@ class AbstractSpruceTest {
41
41
  log(...args) {
42
42
  AbstractSpruceTest.log(...args);
43
43
  }
44
- async beforeAll() {
45
- this.cwd = process.cwd();
46
- }
47
- async afterAll() { }
48
44
  async beforeEach() { }
49
45
  async afterEach() { }
50
46
  }
@@ -12,17 +12,20 @@ class Test {
12
12
  }
13
13
  }
14
14
  /** Hooks up before, after, etc. */
15
- function hookupTestClass(target) {
15
+ function hookupTestClass(target, h) {
16
16
  if (target.__isTestingHookedUp) {
17
17
  return;
18
18
  }
19
- target.__isTestingHookedUp = true;
20
- const hooks = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
19
+ target.__isTestingHookedUp = !h;
20
+ const hooks = h ?? ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
21
21
  hooks.forEach((hook) => {
22
22
  // Have they defined a hook
23
23
  if (!target[hook]) {
24
24
  return;
25
25
  }
26
+ if (Test.ActiveTestClass && !h && hook === 'beforeAll') {
27
+ throw new Error(`beforeAll() and afterAll() must be static`);
28
+ }
26
29
  // @ts-ignore
27
30
  if (global[hook]) {
28
31
  // @ts-ignore
@@ -54,7 +57,7 @@ function suite() {
54
57
  return function (Target) {
55
58
  Test.ActiveTestClass = Target;
56
59
  // Test.activeTest.__isTestingHookedUp = false
57
- // hookupTestClass(Test.activeTest)
60
+ hookupTestClass(Target, ['beforeAll', 'afterAll']);
58
61
  };
59
62
  }
60
63
  /** Only decorator */
@@ -10,8 +10,6 @@ export default class AbstractSpruceTest {
10
10
  protected wait(ms?: number): Promise<unknown>;
11
11
  protected log(...args: any[]): void;
12
12
  protected cwd: string;
13
- protected beforeAll(): Promise<void>;
14
- protected afterAll(): Promise<void>;
15
13
  protected beforeEach(): Promise<void>;
16
14
  protected afterEach(): Promise<void>;
17
15
  }
@@ -36,10 +36,6 @@ export default class AbstractSpruceTest {
36
36
  log(...args) {
37
37
  AbstractSpruceTest.log(...args);
38
38
  }
39
- async beforeAll() {
40
- this.cwd = process.cwd();
41
- }
42
- async afterAll() { }
43
39
  async beforeEach() { }
44
40
  async afterEach() { }
45
41
  }
@@ -8,17 +8,20 @@ class Test {
8
8
  }
9
9
  }
10
10
  /** Hooks up before, after, etc. */
11
- function hookupTestClass(target) {
11
+ function hookupTestClass(target, h) {
12
12
  if (target.__isTestingHookedUp) {
13
13
  return;
14
14
  }
15
- target.__isTestingHookedUp = true;
16
- const hooks = ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
15
+ target.__isTestingHookedUp = !h;
16
+ const hooks = h !== null && h !== void 0 ? h : ['beforeAll', 'beforeEach', 'afterAll', 'afterEach'];
17
17
  hooks.forEach((hook) => {
18
18
  // Have they defined a hook
19
19
  if (!target[hook]) {
20
20
  return;
21
21
  }
22
+ if (Test.ActiveTestClass && !h && hook === 'beforeAll') {
23
+ throw new Error(`beforeAll() and afterAll() must be static`);
24
+ }
22
25
  // @ts-ignore
23
26
  if (global[hook]) {
24
27
  // @ts-ignore
@@ -50,7 +53,7 @@ export function suite() {
50
53
  return function (Target) {
51
54
  Test.ActiveTestClass = Target;
52
55
  // Test.activeTest.__isTestingHookedUp = false
53
- // hookupTestClass(Test.activeTest)
56
+ hookupTestClass(Target, ['beforeAll', 'afterAll']);
54
57
  };
55
58
  }
56
59
  /** Only decorator */
@@ -5,6 +5,7 @@ export { default } from './AbstractSpruceTest';
5
5
  export { default as assert } from './assert/assert';
6
6
  export * from './assert/assert';
7
7
  export { default as test } from './decorators';
8
+ export * from './decorators';
8
9
  export { default as assertUtil } from './assert/assert.utility';
9
10
  export { default as StackCleaner } from './StackCleaner';
10
11
  export { default as Spier } from './utilities/spies/Spier';
@@ -5,6 +5,7 @@ export { default } from './AbstractSpruceTest.js';
5
5
  export { default as assert } from './assert/assert.js';
6
6
  export * from './assert/assert.js';
7
7
  export { default as test } from './decorators.js';
8
+ export * from './decorators.js';
8
9
  export { default as assertUtil } from './assert/assert.utility.js';
9
10
  export { default as StackCleaner } from './StackCleaner.js';
10
11
  export { default as Spier } from './utilities/spies/Spier.js';
package/build/index.d.ts CHANGED
@@ -5,6 +5,7 @@ export { default } from './AbstractSpruceTest';
5
5
  export { default as assert } from './assert/assert';
6
6
  export * from './assert/assert';
7
7
  export { default as test } from './decorators';
8
+ export * from './decorators';
8
9
  export { default as assertUtil } from './assert/assert.utility';
9
10
  export { default as StackCleaner } from './StackCleaner';
10
11
  export { default as Spier } from './utilities/spies/Spier';
package/build/index.js CHANGED
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "assert", { enumerable: true, get: function () {
31
31
  __exportStar(require("./assert/assert"), exports);
32
32
  var decorators_1 = require("./decorators");
33
33
  Object.defineProperty(exports, "test", { enumerable: true, get: function () { return __importDefault(decorators_1).default; } });
34
+ __exportStar(require("./decorators"), exports);
34
35
  var assert_utility_1 = require("./assert/assert.utility");
35
36
  Object.defineProperty(exports, "assertUtil", { enumerable: true, get: function () { return __importDefault(assert_utility_1).default; } });
36
37
  var StackCleaner_1 = require("./StackCleaner");
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "5.3.1",
6
+ "version": "5.3.3",
7
7
  "files": [
8
8
  "build"
9
9
  ],