@sprucelabs/test-utils 5.3.2 → 5.3.4
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.
@@ -7,11 +7,10 @@ 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
11
|
protected wait(ms?: number): Promise<unknown>;
|
11
12
|
protected log(...args: any[]): void;
|
12
|
-
protected
|
13
|
-
protected beforeAll(): Promise<void>;
|
14
|
-
protected afterAll(): Promise<void>;
|
13
|
+
protected resolvePath(...filePath: string[]): string;
|
15
14
|
protected beforeEach(): Promise<void>;
|
16
15
|
protected afterEach(): Promise<void>;
|
17
16
|
}
|
@@ -5,6 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
const path_1 = __importDefault(require("path"));
|
7
7
|
class AbstractSpruceTest {
|
8
|
+
constructor() {
|
9
|
+
//instance declariations
|
10
|
+
this.cwd = process.cwd();
|
11
|
+
}
|
8
12
|
static async beforeAll() {
|
9
13
|
this.cwd = process.cwd();
|
10
14
|
}
|
@@ -30,21 +34,30 @@ class AbstractSpruceTest {
|
|
30
34
|
setTimeout(() => resolve(true), ms);
|
31
35
|
});
|
32
36
|
}
|
33
|
-
//instance declariations
|
34
37
|
static log(...args) {
|
35
38
|
const str = args.map((a) => `${a}`).join(' ');
|
36
39
|
process.stderr.write(str);
|
37
40
|
}
|
38
41
|
async wait(ms = 1000) {
|
39
|
-
return
|
42
|
+
return new Promise((resolve) => {
|
43
|
+
setTimeout(() => resolve(true), ms);
|
44
|
+
});
|
40
45
|
}
|
41
46
|
log(...args) {
|
42
|
-
|
47
|
+
const str = args.map((a) => `${a}`).join(' ');
|
48
|
+
process.stderr.write(str);
|
43
49
|
}
|
44
|
-
|
45
|
-
|
50
|
+
resolvePath(...filePath) {
|
51
|
+
const cwd = this.cwd;
|
52
|
+
let builtPath = path_1.default.join(...filePath);
|
53
|
+
if (builtPath[0] !== '/') {
|
54
|
+
if (builtPath.substr(0, 2) === './') {
|
55
|
+
builtPath = builtPath.substr(1);
|
56
|
+
}
|
57
|
+
builtPath = path_1.default.join(cwd, builtPath);
|
58
|
+
}
|
59
|
+
return builtPath;
|
46
60
|
}
|
47
|
-
async afterAll() { }
|
48
61
|
async beforeEach() { }
|
49
62
|
async afterEach() { }
|
50
63
|
}
|
package/build/decorators.js
CHANGED
@@ -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 =
|
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
|
-
|
60
|
+
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
58
61
|
};
|
59
62
|
}
|
60
63
|
/** Only decorator */
|
@@ -7,11 +7,10 @@ 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
11
|
protected wait(ms?: number): Promise<unknown>;
|
11
12
|
protected log(...args: any[]): void;
|
12
|
-
protected
|
13
|
-
protected beforeAll(): Promise<void>;
|
14
|
-
protected afterAll(): Promise<void>;
|
13
|
+
protected resolvePath(...filePath: string[]): string;
|
15
14
|
protected beforeEach(): Promise<void>;
|
16
15
|
protected afterEach(): Promise<void>;
|
17
16
|
}
|
@@ -1,5 +1,9 @@
|
|
1
1
|
import path from 'path';
|
2
2
|
export default class AbstractSpruceTest {
|
3
|
+
constructor() {
|
4
|
+
//instance declariations
|
5
|
+
this.cwd = process.cwd();
|
6
|
+
}
|
3
7
|
static async beforeAll() {
|
4
8
|
this.cwd = process.cwd();
|
5
9
|
}
|
@@ -25,21 +29,30 @@ export default class AbstractSpruceTest {
|
|
25
29
|
setTimeout(() => resolve(true), ms);
|
26
30
|
});
|
27
31
|
}
|
28
|
-
//instance declariations
|
29
32
|
static log(...args) {
|
30
33
|
const str = args.map((a) => `${a}`).join(' ');
|
31
34
|
process.stderr.write(str);
|
32
35
|
}
|
33
36
|
async wait(ms = 1000) {
|
34
|
-
return
|
37
|
+
return new Promise((resolve) => {
|
38
|
+
setTimeout(() => resolve(true), ms);
|
39
|
+
});
|
35
40
|
}
|
36
41
|
log(...args) {
|
37
|
-
|
42
|
+
const str = args.map((a) => `${a}`).join(' ');
|
43
|
+
process.stderr.write(str);
|
38
44
|
}
|
39
|
-
|
40
|
-
|
45
|
+
resolvePath(...filePath) {
|
46
|
+
const cwd = this.cwd;
|
47
|
+
let builtPath = path.join(...filePath);
|
48
|
+
if (builtPath[0] !== '/') {
|
49
|
+
if (builtPath.substr(0, 2) === './') {
|
50
|
+
builtPath = builtPath.substr(1);
|
51
|
+
}
|
52
|
+
builtPath = path.join(cwd, builtPath);
|
53
|
+
}
|
54
|
+
return builtPath;
|
41
55
|
}
|
42
|
-
async afterAll() { }
|
43
56
|
async beforeEach() { }
|
44
57
|
async afterEach() { }
|
45
58
|
}
|
package/build/esm/decorators.js
CHANGED
@@ -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 =
|
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
|
-
|
56
|
+
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
54
57
|
};
|
55
58
|
}
|
56
59
|
/** Only decorator */
|