@sprucelabs/spruce-test-fixtures 66.0.38 → 66.0.40
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.
|
@@ -4,7 +4,7 @@ type EMPLOYED = typeof EMPLOYED_BASE_ROLES;
|
|
|
4
4
|
type GUEST = typeof GUEST_BASE_ROLES;
|
|
5
5
|
export type CoreSeedTarget = 'organizations' | 'locations' | `${EMPLOYED[number]['slug']}s` | `${GUEST[number]['slug']}s`;
|
|
6
6
|
type SeedTarget = CoreSeedTarget | StoreName;
|
|
7
|
-
declare function seed(storeName: SeedTarget, totalToSeed?: number, ...params: any[]): (
|
|
7
|
+
declare function seed(storeName: SeedTarget, totalToSeed?: number, ...params: any[]): (_Class: any, key: string, descriptor: any) => void;
|
|
8
8
|
declare namespace seed {
|
|
9
9
|
var disableResettingTestClient: () => void;
|
|
10
10
|
}
|
|
@@ -13,25 +13,30 @@ import FakerTracker from '../../FakerTracker.js';
|
|
|
13
13
|
import MercuryFixture from '../fixtures/MercuryFixture.js';
|
|
14
14
|
import StoreFixture from '../fixtures/StoreFixture.js';
|
|
15
15
|
import login from './login.js';
|
|
16
|
+
const SeedTracker = {
|
|
17
|
+
isSeedingPatched: false,
|
|
18
|
+
shouldResetAccount: false,
|
|
19
|
+
attachedStoreAfterEach: false,
|
|
20
|
+
};
|
|
16
21
|
export default function seed(storeName, totalToSeed, ...params) {
|
|
17
|
-
return function (
|
|
22
|
+
return function (_Class, key, descriptor) {
|
|
18
23
|
if ((storeName === 'organizations' || storeName === 'locations') &&
|
|
19
|
-
!
|
|
20
|
-
|
|
21
|
-
SpruceTestResolver.onDidCallBeforeAll((
|
|
24
|
+
!SeedTracker.isSeedingPatched) {
|
|
25
|
+
SeedTracker.shouldResetAccount = false;
|
|
26
|
+
SpruceTestResolver.onDidCallBeforeAll(() => __awaiter(this, void 0, void 0, function* () {
|
|
22
27
|
yield login.on('did-login', () => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
yield forceResetAccount(
|
|
28
|
+
yield forceResetAccount();
|
|
24
29
|
}));
|
|
25
30
|
}));
|
|
26
|
-
|
|
31
|
+
SeedTracker.isSeedingPatched = true;
|
|
27
32
|
}
|
|
28
33
|
StoreFixture.setShouldAutomaticallyResetDatabase(false);
|
|
29
34
|
StoreFixture.resetDbConnectionSettings();
|
|
30
|
-
const seed = attachSeeder(storeName,
|
|
35
|
+
const seed = attachSeeder(storeName, totalToSeed, params);
|
|
31
36
|
const unbound = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
|
|
32
|
-
attachCleanup(
|
|
37
|
+
attachCleanup();
|
|
33
38
|
descriptor.value = (...args) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
yield optionallyReset(
|
|
39
|
+
yield optionallyReset(key);
|
|
35
40
|
yield seed();
|
|
36
41
|
const Test = SpruceTestResolver.getActiveTest();
|
|
37
42
|
const allArgs = [Test, args];
|
|
@@ -39,26 +44,26 @@ export default function seed(storeName, totalToSeed, ...params) {
|
|
|
39
44
|
});
|
|
40
45
|
};
|
|
41
46
|
}
|
|
42
|
-
function forceResetAccount(
|
|
47
|
+
function forceResetAccount() {
|
|
43
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
|
|
45
|
-
yield reset(
|
|
49
|
+
SeedTracker.shouldResetAccount = true;
|
|
50
|
+
yield reset();
|
|
46
51
|
});
|
|
47
52
|
}
|
|
48
|
-
function optionallyReset(
|
|
53
|
+
function optionallyReset(key) {
|
|
49
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
if (
|
|
51
|
-
if (
|
|
52
|
-
yield reset(
|
|
55
|
+
if (SeedTracker.lastReset !== key) {
|
|
56
|
+
if (SeedTracker.lastReset !== 'beforeEach') {
|
|
57
|
+
yield reset();
|
|
53
58
|
}
|
|
54
|
-
|
|
59
|
+
SeedTracker.lastReset = key;
|
|
55
60
|
}
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
|
-
function reset(
|
|
63
|
+
function reset() {
|
|
59
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
if (
|
|
61
|
-
|
|
65
|
+
if (SeedTracker.shouldResetAccount) {
|
|
66
|
+
SeedTracker.shouldResetAccount = false;
|
|
62
67
|
const cwd = SpruceTestResolver.getActiveTest().cwd;
|
|
63
68
|
yield FakerTracker.getFixtures(cwd).seeder.resetAccount();
|
|
64
69
|
}
|
|
@@ -69,20 +74,20 @@ let shouldResetTestClient = true;
|
|
|
69
74
|
seed.disableResettingTestClient = () => {
|
|
70
75
|
shouldResetTestClient = false;
|
|
71
76
|
};
|
|
72
|
-
function attachCleanup(
|
|
73
|
-
if (!
|
|
74
|
-
|
|
77
|
+
function attachCleanup() {
|
|
78
|
+
if (!SeedTracker.attachedStoreAfterEach) {
|
|
79
|
+
SeedTracker.attachedStoreAfterEach = true;
|
|
75
80
|
SpruceTestResolver.onWillCallBeforeEach((Class) => __awaiter(this, void 0, void 0, function* () {
|
|
76
81
|
MercuryFixture.setDefaultContractToLocalEventsIfExist(Class.cwd);
|
|
77
|
-
yield optionallyReset(
|
|
82
|
+
yield optionallyReset('beforeEach');
|
|
78
83
|
}));
|
|
79
84
|
SpruceTestResolver.onDidCallAfterEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
80
85
|
shouldResetTestClient && MercuryTestClient.reset();
|
|
81
|
-
delete
|
|
86
|
+
delete SeedTracker.lastReset;
|
|
82
87
|
}));
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
|
-
function attachSeeder(storeName,
|
|
90
|
+
function attachSeeder(storeName, totalToSeed, params) {
|
|
86
91
|
var _a, _b, _c;
|
|
87
92
|
const fixtureMap = {
|
|
88
93
|
locations: 'seeder',
|
|
@@ -127,7 +132,7 @@ function attachSeeder(storeName, TestClass, totalToSeed, params) {
|
|
|
127
132
|
options.TestClass = ActiveTest;
|
|
128
133
|
}
|
|
129
134
|
else {
|
|
130
|
-
|
|
135
|
+
SeedTracker.shouldResetAccount = true;
|
|
131
136
|
}
|
|
132
137
|
assert.isFunction(fixture[method], `The '${storeName}' store you created needs a method called 'seed(options: StoreSeedOptions)' in order for seeding. You must implement it yourself... for now.`);
|
|
133
138
|
const args = [options, ...(params !== null && params !== void 0 ? params : [])];
|
|
@@ -4,7 +4,7 @@ type EMPLOYED = typeof EMPLOYED_BASE_ROLES;
|
|
|
4
4
|
type GUEST = typeof GUEST_BASE_ROLES;
|
|
5
5
|
export type CoreSeedTarget = 'organizations' | 'locations' | `${EMPLOYED[number]['slug']}s` | `${GUEST[number]['slug']}s`;
|
|
6
6
|
type SeedTarget = CoreSeedTarget | StoreName;
|
|
7
|
-
declare function seed(storeName: SeedTarget, totalToSeed?: number, ...params: any[]): (
|
|
7
|
+
declare function seed(storeName: SeedTarget, totalToSeed?: number, ...params: any[]): (_Class: any, key: string, descriptor: any) => void;
|
|
8
8
|
declare namespace seed {
|
|
9
9
|
var disableResettingTestClient: () => void;
|
|
10
10
|
}
|
|
@@ -10,25 +10,30 @@ const FakerTracker_1 = __importDefault(require("../../FakerTracker"));
|
|
|
10
10
|
const MercuryFixture_1 = __importDefault(require("../fixtures/MercuryFixture"));
|
|
11
11
|
const StoreFixture_1 = __importDefault(require("../fixtures/StoreFixture"));
|
|
12
12
|
const login_1 = __importDefault(require("./login"));
|
|
13
|
+
const SeedTracker = {
|
|
14
|
+
isSeedingPatched: false,
|
|
15
|
+
shouldResetAccount: false,
|
|
16
|
+
attachedStoreAfterEach: false,
|
|
17
|
+
};
|
|
13
18
|
function seed(storeName, totalToSeed, ...params) {
|
|
14
|
-
return function (
|
|
19
|
+
return function (_Class, key, descriptor) {
|
|
15
20
|
if ((storeName === 'organizations' || storeName === 'locations') &&
|
|
16
|
-
!
|
|
17
|
-
|
|
18
|
-
test_utils_1.SpruceTestResolver.onDidCallBeforeAll(async (
|
|
21
|
+
!SeedTracker.isSeedingPatched) {
|
|
22
|
+
SeedTracker.shouldResetAccount = false;
|
|
23
|
+
test_utils_1.SpruceTestResolver.onDidCallBeforeAll(async () => {
|
|
19
24
|
await login_1.default.on('did-login', async () => {
|
|
20
|
-
await forceResetAccount(
|
|
25
|
+
await forceResetAccount();
|
|
21
26
|
});
|
|
22
27
|
});
|
|
23
|
-
|
|
28
|
+
SeedTracker.isSeedingPatched = true;
|
|
24
29
|
}
|
|
25
30
|
StoreFixture_1.default.setShouldAutomaticallyResetDatabase(false);
|
|
26
31
|
StoreFixture_1.default.resetDbConnectionSettings();
|
|
27
|
-
const seed = attachSeeder(storeName,
|
|
32
|
+
const seed = attachSeeder(storeName, totalToSeed, params);
|
|
28
33
|
const unbound = descriptor?.value;
|
|
29
|
-
attachCleanup(
|
|
34
|
+
attachCleanup();
|
|
30
35
|
descriptor.value = async (...args) => {
|
|
31
|
-
await optionallyReset(
|
|
36
|
+
await optionallyReset(key);
|
|
32
37
|
await seed();
|
|
33
38
|
const Test = test_utils_1.SpruceTestResolver.getActiveTest();
|
|
34
39
|
const allArgs = [Test, args];
|
|
@@ -36,21 +41,21 @@ function seed(storeName, totalToSeed, ...params) {
|
|
|
36
41
|
};
|
|
37
42
|
};
|
|
38
43
|
}
|
|
39
|
-
async function forceResetAccount(
|
|
40
|
-
|
|
41
|
-
await reset(
|
|
44
|
+
async function forceResetAccount() {
|
|
45
|
+
SeedTracker.shouldResetAccount = true;
|
|
46
|
+
await reset();
|
|
42
47
|
}
|
|
43
|
-
async function optionallyReset(
|
|
44
|
-
if (
|
|
45
|
-
if (
|
|
46
|
-
await reset(
|
|
48
|
+
async function optionallyReset(key) {
|
|
49
|
+
if (SeedTracker.lastReset !== key) {
|
|
50
|
+
if (SeedTracker.lastReset !== 'beforeEach') {
|
|
51
|
+
await reset();
|
|
47
52
|
}
|
|
48
|
-
|
|
53
|
+
SeedTracker.lastReset = key;
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
|
-
async function reset(
|
|
52
|
-
if (
|
|
53
|
-
|
|
56
|
+
async function reset() {
|
|
57
|
+
if (SeedTracker.shouldResetAccount) {
|
|
58
|
+
SeedTracker.shouldResetAccount = false;
|
|
54
59
|
const cwd = test_utils_1.SpruceTestResolver.getActiveTest().cwd;
|
|
55
60
|
await FakerTracker_1.default.getFixtures(cwd).seeder.resetAccount();
|
|
56
61
|
}
|
|
@@ -60,20 +65,20 @@ let shouldResetTestClient = true;
|
|
|
60
65
|
seed.disableResettingTestClient = () => {
|
|
61
66
|
shouldResetTestClient = false;
|
|
62
67
|
};
|
|
63
|
-
function attachCleanup(
|
|
64
|
-
if (!
|
|
65
|
-
|
|
68
|
+
function attachCleanup() {
|
|
69
|
+
if (!SeedTracker.attachedStoreAfterEach) {
|
|
70
|
+
SeedTracker.attachedStoreAfterEach = true;
|
|
66
71
|
test_utils_1.SpruceTestResolver.onWillCallBeforeEach(async (Class) => {
|
|
67
72
|
MercuryFixture_1.default.setDefaultContractToLocalEventsIfExist(Class.cwd);
|
|
68
|
-
await optionallyReset(
|
|
73
|
+
await optionallyReset('beforeEach');
|
|
69
74
|
});
|
|
70
75
|
test_utils_1.SpruceTestResolver.onDidCallAfterEach(async () => {
|
|
71
76
|
shouldResetTestClient && mercury_client_1.MercuryTestClient.reset();
|
|
72
|
-
delete
|
|
77
|
+
delete SeedTracker.lastReset;
|
|
73
78
|
});
|
|
74
79
|
}
|
|
75
80
|
}
|
|
76
|
-
function attachSeeder(storeName,
|
|
81
|
+
function attachSeeder(storeName, totalToSeed, params) {
|
|
77
82
|
const fixtureMap = {
|
|
78
83
|
locations: 'seeder',
|
|
79
84
|
organizations: 'seeder',
|
|
@@ -117,7 +122,7 @@ function attachSeeder(storeName, TestClass, totalToSeed, params) {
|
|
|
117
122
|
options.TestClass = ActiveTest;
|
|
118
123
|
}
|
|
119
124
|
else {
|
|
120
|
-
|
|
125
|
+
SeedTracker.shouldResetAccount = true;
|
|
121
126
|
}
|
|
122
127
|
test_utils_1.assert.isFunction(fixture[method], `The '${storeName}' store you created needs a method called 'seed(options: StoreSeedOptions)' in order for seeding. You must implement it yourself... for now.`);
|
|
123
128
|
const args = [options, ...(params ?? [])];
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@sprucelabs/spruce-test-fixtures"
|
|
14
14
|
]
|
|
15
15
|
},
|
|
16
|
-
"version": "66.0.
|
|
16
|
+
"version": "66.0.40",
|
|
17
17
|
"files": [
|
|
18
18
|
"build/**/*",
|
|
19
19
|
"!build/__tests__",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
"lint.tsc": "tsc -p . --noEmit"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@sprucelabs/data-stores": "^28.5.
|
|
64
|
+
"@sprucelabs/data-stores": "^28.5.80",
|
|
65
65
|
"@sprucelabs/error": "^6.0.586",
|
|
66
|
-
"@sprucelabs/heartwood-view-controllers": "^117.2.
|
|
67
|
-
"@sprucelabs/mercury-client": "^42.0.
|
|
68
|
-
"@sprucelabs/mercury-core-events": "^26.0.
|
|
69
|
-
"@sprucelabs/mercury-event-emitter": "^42.0.
|
|
66
|
+
"@sprucelabs/heartwood-view-controllers": "^117.2.29",
|
|
67
|
+
"@sprucelabs/mercury-client": "^42.0.750",
|
|
68
|
+
"@sprucelabs/mercury-core-events": "^26.0.33",
|
|
69
|
+
"@sprucelabs/mercury-event-emitter": "^42.0.750",
|
|
70
70
|
"@sprucelabs/schema": "^31.0.63",
|
|
71
71
|
"@sprucelabs/spruce-core-schemas": "^40.1.653",
|
|
72
72
|
"@sprucelabs/spruce-event-utils": "^40.2.54",
|
|
73
|
-
"@sprucelabs/spruce-permission-utils": "^12.0.
|
|
74
|
-
"@sprucelabs/spruce-skill-booter": "^66.0.
|
|
73
|
+
"@sprucelabs/spruce-permission-utils": "^12.0.54",
|
|
74
|
+
"@sprucelabs/spruce-skill-booter": "^66.0.40",
|
|
75
75
|
"@sprucelabs/spruce-skill-utils": "^31.2.68",
|
|
76
76
|
"@sprucelabs/test-utils": "^5.5.22",
|
|
77
77
|
"dotenv": "^16.4.7",
|
|
@@ -114,5 +114,5 @@
|
|
|
114
114
|
"^#spruce/(.*)$": "<rootDir>/build/.spruce/$1"
|
|
115
115
|
}
|
|
116
116
|
},
|
|
117
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "2ef8b1ace570afe286d4c071eeb6a344eda5a454"
|
|
118
118
|
}
|