@sprucelabs/test-utils 5.3.3 → 5.3.5
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,9 +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 resolvePath(...filePath: string[]): string;
|
13
14
|
protected beforeEach(): Promise<void>;
|
14
15
|
protected afterEach(): Promise<void>;
|
15
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,16 +34,29 @@ 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);
|
49
|
+
}
|
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;
|
43
60
|
}
|
44
61
|
async beforeEach() { }
|
45
62
|
async afterEach() { }
|
package/build/decorators.js
CHANGED
@@ -6,7 +6,7 @@ if (typeof it === 'undefined') {
|
|
6
6
|
//@ts-ignore
|
7
7
|
global.it = () => { };
|
8
8
|
}
|
9
|
-
class
|
9
|
+
class SpruceTestDecoratorResolver {
|
10
10
|
static resolveActiveTest(target) {
|
11
11
|
return this.ActiveTestClass ? new this.ActiveTestClass() : target;
|
12
12
|
}
|
@@ -23,7 +23,9 @@ function hookupTestClass(target, h) {
|
|
23
23
|
if (!target[hook]) {
|
24
24
|
return;
|
25
25
|
}
|
26
|
-
if (
|
26
|
+
if (SpruceTestDecoratorResolver.ActiveTestClass &&
|
27
|
+
!h &&
|
28
|
+
hook === 'beforeAll') {
|
27
29
|
throw new Error(`beforeAll() and afterAll() must be static`);
|
28
30
|
}
|
29
31
|
// @ts-ignore
|
@@ -42,7 +44,7 @@ function test(description, ...args) {
|
|
42
44
|
hookupTestClass(target);
|
43
45
|
// Make sure each test gets the spruce
|
44
46
|
it(description ?? propertyKey, async () => {
|
45
|
-
const testClass =
|
47
|
+
const testClass = SpruceTestDecoratorResolver.resolveActiveTest(target);
|
46
48
|
const bound = descriptor.value.bind(testClass);
|
47
49
|
//@ts-ignore
|
48
50
|
global.activeTest = {
|
@@ -55,7 +57,7 @@ function test(description, ...args) {
|
|
55
57
|
}
|
56
58
|
function suite() {
|
57
59
|
return function (Target) {
|
58
|
-
|
60
|
+
SpruceTestDecoratorResolver.ActiveTestClass = Target;
|
59
61
|
// Test.activeTest.__isTestingHookedUp = false
|
60
62
|
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
61
63
|
};
|
@@ -67,7 +69,7 @@ test.only = (description, ...args) => {
|
|
67
69
|
hookupTestClass(target);
|
68
70
|
// Make sure each test gets the spruce
|
69
71
|
it.only(description ?? propertyKey, async () => {
|
70
|
-
const bound = descriptor.value.bind(
|
72
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
71
73
|
return bound(...args);
|
72
74
|
});
|
73
75
|
};
|
@@ -88,7 +90,7 @@ test.skip = (description, ...args) => {
|
|
88
90
|
hookupTestClass(target);
|
89
91
|
// Make sure each test gets the spruce
|
90
92
|
it.skip(description ?? propertyKey, async () => {
|
91
|
-
const bound = descriptor.value.bind(
|
93
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
92
94
|
return bound(...args);
|
93
95
|
});
|
94
96
|
};
|
@@ -7,9 +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 resolvePath(...filePath: string[]): string;
|
13
14
|
protected beforeEach(): Promise<void>;
|
14
15
|
protected afterEach(): Promise<void>;
|
15
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,16 +29,29 @@ 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);
|
44
|
+
}
|
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;
|
38
55
|
}
|
39
56
|
async beforeEach() { }
|
40
57
|
async afterEach() { }
|
package/build/esm/decorators.js
CHANGED
@@ -2,7 +2,7 @@ if (typeof it === 'undefined') {
|
|
2
2
|
//@ts-ignore
|
3
3
|
global.it = () => { };
|
4
4
|
}
|
5
|
-
class
|
5
|
+
class SpruceTestDecoratorResolver {
|
6
6
|
static resolveActiveTest(target) {
|
7
7
|
return this.ActiveTestClass ? new this.ActiveTestClass() : target;
|
8
8
|
}
|
@@ -19,7 +19,9 @@ function hookupTestClass(target, h) {
|
|
19
19
|
if (!target[hook]) {
|
20
20
|
return;
|
21
21
|
}
|
22
|
-
if (
|
22
|
+
if (SpruceTestDecoratorResolver.ActiveTestClass &&
|
23
|
+
!h &&
|
24
|
+
hook === 'beforeAll') {
|
23
25
|
throw new Error(`beforeAll() and afterAll() must be static`);
|
24
26
|
}
|
25
27
|
// @ts-ignore
|
@@ -38,7 +40,7 @@ export default function test(description, ...args) {
|
|
38
40
|
hookupTestClass(target);
|
39
41
|
// Make sure each test gets the spruce
|
40
42
|
it(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
41
|
-
const testClass =
|
43
|
+
const testClass = SpruceTestDecoratorResolver.resolveActiveTest(target);
|
42
44
|
const bound = descriptor.value.bind(testClass);
|
43
45
|
//@ts-ignore
|
44
46
|
global.activeTest = {
|
@@ -51,7 +53,7 @@ export default function test(description, ...args) {
|
|
51
53
|
}
|
52
54
|
export function suite() {
|
53
55
|
return function (Target) {
|
54
|
-
|
56
|
+
SpruceTestDecoratorResolver.ActiveTestClass = Target;
|
55
57
|
// Test.activeTest.__isTestingHookedUp = false
|
56
58
|
hookupTestClass(Target, ['beforeAll', 'afterAll']);
|
57
59
|
};
|
@@ -63,7 +65,7 @@ test.only = (description, ...args) => {
|
|
63
65
|
hookupTestClass(target);
|
64
66
|
// Make sure each test gets the spruce
|
65
67
|
it.only(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
66
|
-
const bound = descriptor.value.bind(
|
68
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
67
69
|
return bound(...args);
|
68
70
|
});
|
69
71
|
};
|
@@ -84,7 +86,7 @@ test.skip = (description, ...args) => {
|
|
84
86
|
hookupTestClass(target);
|
85
87
|
// Make sure each test gets the spruce
|
86
88
|
it.skip(description !== null && description !== void 0 ? description : propertyKey, async () => {
|
87
|
-
const bound = descriptor.value.bind(
|
89
|
+
const bound = descriptor.value.bind(SpruceTestDecoratorResolver.resolveActiveTest(target));
|
88
90
|
return bound(...args);
|
89
91
|
});
|
90
92
|
};
|