@testforgejs/vue-test-plugin-pinia 1.0.0-beta.6 → 1.0.0-beta.7
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.
- package/README.md +94 -3
- package/dist/index.cjs +21 -8
- package/dist/index.d.cts +97 -30
- package/dist/index.d.ts +97 -30
- package/dist/index.js +19 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -36,7 +36,6 @@ When using Vitest, you can pass `vi` as the runner:
|
|
|
36
36
|
|
|
37
37
|
```typescript
|
|
38
38
|
import { vi } from "vitest";
|
|
39
|
-
|
|
40
39
|
import { createTestFramework } from "@testforgejs/vue-test-core";
|
|
41
40
|
import { piniaPlugin } from "@testforgejs/vue-test-plugin-pinia";
|
|
42
41
|
|
|
@@ -95,7 +94,6 @@ You can define the Pinia testing configuration directly in the preset instead:
|
|
|
95
94
|
|
|
96
95
|
```typescript
|
|
97
96
|
import { vi } from "vitest";
|
|
98
|
-
|
|
99
97
|
import { createTestFramework } from "@testforgejs/vue-test-core";
|
|
100
98
|
import { piniaPlugin } from "@testforgejs/vue-test-plugin-pinia";
|
|
101
99
|
|
|
@@ -148,6 +146,90 @@ TestForge does not redefine these Pinia testing options. The integration passes
|
|
|
148
146
|
|
|
149
147
|
Refer to the Pinia documentation for the complete set of `TestingOptions` and their behavior.
|
|
150
148
|
|
|
149
|
+
For additional store initialization and modification before mounting, see [Configuring stores with `withMockStores()`](#configuring-stores-with-withmockstores).
|
|
150
|
+
|
|
151
|
+
### Configuring stores with `withMockStores()`
|
|
152
|
+
|
|
153
|
+
The TestForge Pinia plugin provides the `withMockStores()` helper for configuring stores before a component is mounted. It accepts a callback that receives the testing Pinia instance used by the mounted component.
|
|
154
|
+
|
|
155
|
+
Unlike the native `initialState` option, which initializes store state, `withMockStores()` lets you access stores directly and perform additional setup, including calling store actions.
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import { withMockStores } from "@testforgejs/vue-test-plugin-pinia";
|
|
159
|
+
|
|
160
|
+
factory(
|
|
161
|
+
{},
|
|
162
|
+
{
|
|
163
|
+
plugins: {
|
|
164
|
+
pinia: {
|
|
165
|
+
stubActions: false,
|
|
166
|
+
...withMockStores((pinia) => {
|
|
167
|
+
const store = useCounterStore(pinia);
|
|
168
|
+
store.setCount(42);
|
|
169
|
+
}),
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
);
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The callback runs after the Pinia instance has been resolved and before the component is mounted. This applies to newly created instances and explicitly reused instances alike.
|
|
177
|
+
|
|
178
|
+
When calling store actions inside `withMockStores()`, configure `stubActions: false` if their implementations need to execute. By default, `createTestingPinia()` stubs store actions.
|
|
179
|
+
|
|
180
|
+
The configuration returned by `withMockStores()` can be used in per-mount plugin options or factory-level defaults. The callback is invoked for each mount that uses the configuration and receives that mount's resolved Pinia instance.
|
|
181
|
+
|
|
182
|
+
#### Configuring an existing Pinia instance
|
|
183
|
+
|
|
184
|
+
The `withMockStores()` callback also runs when an existing Pinia instance is supplied using `withPluginInstance()`. This allows you to configure stores on an explicitly reused instance without creating a new Pinia instance.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { createTestingPinia } from "@pinia/testing";
|
|
188
|
+
import { vi } from "vitest";
|
|
189
|
+
import { withPluginInstance } from "@testforgejs/vue-test-core";
|
|
190
|
+
import { withMockStores } from "@testforgejs/vue-test-plugin-pinia";
|
|
191
|
+
|
|
192
|
+
const pinia = createTestingPinia({
|
|
193
|
+
createSpy: vi.fn,
|
|
194
|
+
stubActions: false,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
factory(
|
|
198
|
+
{},
|
|
199
|
+
{},
|
|
200
|
+
{},
|
|
201
|
+
{
|
|
202
|
+
plugins: {
|
|
203
|
+
pinia: {
|
|
204
|
+
...withPluginInstance(pinia),
|
|
205
|
+
...withMockStores((pinia) => {
|
|
206
|
+
const store = useCounterStore(pinia);
|
|
207
|
+
store.count = 42;
|
|
208
|
+
}),
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
In this example:
|
|
216
|
+
|
|
217
|
+
- TestForge reuses the supplied Pinia instance instead of creating a new one.
|
|
218
|
+
- The `withMockStores()` callback receives that same instance.
|
|
219
|
+
- The callback modifies the store before the component is mounted.
|
|
220
|
+
|
|
221
|
+
Native `createTestingPinia()` options should be configured when creating the instance. Using `withPluginInstance()` reuses that instance rather than recreating it with new testing options.
|
|
222
|
+
|
|
223
|
+
#### Shared instance isolation
|
|
224
|
+
|
|
225
|
+
**Using `withPluginInstance()` explicitly enables instance reuse.** When the same instance is reused across multiple mounts, the mounted components share its stores and reactive state. State changes made during one mount may affect other components using that instance.
|
|
226
|
+
|
|
227
|
+
The `withMockStores()` callback runs for **each mount** that configures it and operates on the resolved instance. When that instance is shared, the callback can modify stores that were initialized during an earlier mount. TestForge does not automatically reset or clone explicitly reused plugin instances.
|
|
228
|
+
|
|
229
|
+
For independent tests, let TestForge create a fresh Pinia instance for each mount. If a test requires `withPluginInstance()`, create the supplied Pinia instance separately for each test unless shared state is an intentional part of the scenario.
|
|
230
|
+
|
|
231
|
+
Reusing the same `withMockStores()` configuration **does not itself share Pinia state**: it is the explicit reuse of an instance via `withPluginInstance()` that causes the mounts to share state, assuming the callback does not depend on other shared mutable data.
|
|
232
|
+
|
|
151
233
|
### TestForge plugin defaults
|
|
152
234
|
|
|
153
235
|
The defaults provided by this package intentionally contain only the runner integration:
|
|
@@ -248,13 +330,22 @@ This allows presets to choose explicitly between:
|
|
|
248
330
|
The package provides both descriptive and standardized plugin exports:
|
|
249
331
|
|
|
250
332
|
```typescript
|
|
251
|
-
import {
|
|
333
|
+
import {
|
|
334
|
+
piniaPlugin,
|
|
335
|
+
withMockStores,
|
|
336
|
+
plugin,
|
|
337
|
+
PLUGIN_NAME,
|
|
338
|
+
} from "@testforgejs/vue-test-plugin-pinia";
|
|
252
339
|
```
|
|
253
340
|
|
|
254
341
|
### `piniaPlugin`
|
|
255
342
|
|
|
256
343
|
The descriptive Pinia plugin module export.
|
|
257
344
|
|
|
345
|
+
### `withMockStores()`
|
|
346
|
+
|
|
347
|
+
A helper that adds a symbol-keyed store setup callback to managed Pinia plugin options. See [Configuring stores with `withMockStores()`](#configuring-stores-with-withmockstores) for examples.
|
|
348
|
+
|
|
258
349
|
### `plugin`
|
|
259
350
|
|
|
260
351
|
The standardized plugin module export.
|
package/dist/index.cjs
CHANGED
|
@@ -22,20 +22,28 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
PLUGIN_NAME: () => PINIA_PLUGIN_NAME,
|
|
24
24
|
piniaPlugin: () => piniaPlugin,
|
|
25
|
-
plugin: () => piniaPlugin
|
|
25
|
+
plugin: () => piniaPlugin,
|
|
26
|
+
withMockStores: () => withMockStores
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(index_exports);
|
|
28
29
|
|
|
29
30
|
// src/module/createPiniaPlugin.ts
|
|
30
31
|
var import_vue_test_core = require("@testforgejs/vue-test-core");
|
|
31
32
|
var import_testing = require("@pinia/testing");
|
|
33
|
+
|
|
34
|
+
// src/constants/constants.ts
|
|
35
|
+
var PINIA_PLUGIN_NAME = "pinia";
|
|
36
|
+
var MOCK_STORES = /* @__PURE__ */ Symbol("TestForge.pinia.mockStores");
|
|
37
|
+
|
|
38
|
+
// src/module/createPiniaPlugin.ts
|
|
32
39
|
function createPiniaPlugin(options) {
|
|
40
|
+
const { [MOCK_STORES]: mockStores, ...pluginOptions } = options;
|
|
33
41
|
const pinia = (0, import_vue_test_core.createPluginInstance)(
|
|
34
42
|
import_testing.createTestingPinia,
|
|
35
|
-
|
|
43
|
+
pluginOptions
|
|
36
44
|
);
|
|
37
|
-
if (
|
|
38
|
-
|
|
45
|
+
if (mockStores) {
|
|
46
|
+
mockStores(pinia);
|
|
39
47
|
}
|
|
40
48
|
return pinia;
|
|
41
49
|
}
|
|
@@ -53,9 +61,6 @@ var defaultOptions = (runner) => () => {
|
|
|
53
61
|
};
|
|
54
62
|
};
|
|
55
63
|
|
|
56
|
-
// src/constants/constants.ts
|
|
57
|
-
var PINIA_PLUGIN_NAME = "pinia";
|
|
58
|
-
|
|
59
64
|
// src/module/piniaPlugin.ts
|
|
60
65
|
var piniaPlugin = {
|
|
61
66
|
getName: () => PINIA_PLUGIN_NAME,
|
|
@@ -75,9 +80,17 @@ var piniaPlugin = {
|
|
|
75
80
|
}),
|
|
76
81
|
getDefaultOptions: defaultOptions
|
|
77
82
|
};
|
|
83
|
+
|
|
84
|
+
// src/helpers/withMockStores.ts
|
|
85
|
+
function withMockStores(mockStores) {
|
|
86
|
+
return {
|
|
87
|
+
[MOCK_STORES]: mockStores
|
|
88
|
+
};
|
|
89
|
+
}
|
|
78
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
91
|
0 && (module.exports = {
|
|
80
92
|
PLUGIN_NAME,
|
|
81
93
|
piniaPlugin,
|
|
82
|
-
plugin
|
|
94
|
+
plugin,
|
|
95
|
+
withMockStores
|
|
83
96
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestingOptions, TestingPinia } from '@pinia/testing';
|
|
2
|
-
import {
|
|
2
|
+
import { RuntimePluginOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Stable TestForge identifier for the managed Pinia plugin.
|
|
@@ -8,12 +8,13 @@ import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue
|
|
|
8
8
|
* in presets and other plugin-aware TestForge APIs.
|
|
9
9
|
*/
|
|
10
10
|
declare const PINIA_PLUGIN_NAME: "pinia";
|
|
11
|
+
declare const MOCK_STORES: unique symbol;
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* A callback for configuring Pinia stores after the testing Pinia
|
|
14
|
-
*
|
|
14
|
+
* A callback for configuring Pinia stores after the testing Pinia
|
|
15
|
+
* instance has been resolved and before the component is mounted.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
+
* The instance may be newly created or reused through `withPluginInstance()`.
|
|
17
18
|
*
|
|
18
19
|
* @param pinia - The testing Pinia instance used by the mounted component.
|
|
19
20
|
*/
|
|
@@ -21,36 +22,68 @@ type MockStoresFn = (pinia: TestingPinia) => void;
|
|
|
21
22
|
/**
|
|
22
23
|
* Configuration options for the Pinia test plugin.
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* Extends native Pinia testing options with TestForge-specific
|
|
26
|
+
* store initialization support.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* Managed instance controls are provided separately by TestForge
|
|
29
|
+
* through its plugin configuration types.
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* Use `withMockStores()` to initialize or modify Pinia stores before
|
|
32
|
+
* the component is mounted.
|
|
33
|
+
*
|
|
34
|
+
* The store setup callback runs for both newly created Pinia instances
|
|
35
|
+
* and pre-created instances reused through `withPluginInstance()`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { withMockStores } from "@testforgejs/vue-test-plugin-pinia";
|
|
40
|
+
*
|
|
41
|
+
* factory({}, {
|
|
42
|
+
* plugins: {
|
|
43
|
+
* pinia: {
|
|
44
|
+
* stubActions: false,
|
|
45
|
+
* ...withMockStores((pinia) => {
|
|
46
|
+
* const store = useCounterStore(pinia);
|
|
47
|
+
* store.count = 42;
|
|
48
|
+
* }),
|
|
49
|
+
* },
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @see `TestingOptions` from `@pinia/testing` for native Pinia configuration.
|
|
32
55
|
*/
|
|
33
|
-
type VueTestPiniaOptions = TestingOptions &
|
|
56
|
+
type VueTestPiniaOptions = TestingOptions & {
|
|
34
57
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
58
|
+
* Internal callback for configuring Pinia stores before mounting.
|
|
59
|
+
*
|
|
60
|
+
* Use the public `withMockStores()` helper instead of accessing
|
|
61
|
+
* this property directly.
|
|
62
|
+
*
|
|
63
|
+
* The callback runs for both newly created and reused Pinia instances.
|
|
37
64
|
*
|
|
38
|
-
* @
|
|
39
|
-
* ```ts
|
|
40
|
-
* factory({}, {
|
|
41
|
-
* plugins: {
|
|
42
|
-
* pinia: {
|
|
43
|
-
* mockStores: (pinia) => {
|
|
44
|
-
* const store = useCounterStore(pinia);
|
|
45
|
-
* store.count = 42;
|
|
46
|
-
* },
|
|
47
|
-
* },
|
|
48
|
-
* },
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
65
|
+
* @internal
|
|
51
66
|
*/
|
|
52
|
-
|
|
67
|
+
[MOCK_STORES]?: MockStoresFn;
|
|
53
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Resolved runtime options for the managed Pinia test plugin.
|
|
71
|
+
*
|
|
72
|
+
* Combines {@link VueTestPiniaOptions} with the internal TestForge
|
|
73
|
+
* controls used to create, reuse, and expose a {@link TestingPinia} instance.
|
|
74
|
+
*
|
|
75
|
+
* These options are passed to `createPiniaPlugin()` after the Mount Pipeline
|
|
76
|
+
* has resolved the plugin configuration.
|
|
77
|
+
*
|
|
78
|
+
* Input metadata provided through `withPluginInstance()` is processed
|
|
79
|
+
* before this stage and is not part of the resolved runtime options.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*
|
|
83
|
+
* @see {@link VueTestPiniaOptions}
|
|
84
|
+
* @see `RuntimePluginOptions` from `@testforgejs/vue-test-core`.
|
|
85
|
+
*/
|
|
86
|
+
type PiniaRuntimeOptions = RuntimePluginOptions<TestingPinia, VueTestPiniaOptions>;
|
|
54
87
|
|
|
55
88
|
/**
|
|
56
89
|
* TestForge core type augmentation for Pinia integration.
|
|
@@ -83,9 +116,43 @@ declare module "@testforgejs/vue-test-core" {
|
|
|
83
116
|
/**
|
|
84
117
|
* Managed Pinia testing plugin module for TestForge.
|
|
85
118
|
*
|
|
86
|
-
* Provides the runtime definition for creating testing Pinia
|
|
87
|
-
* and exposes
|
|
119
|
+
* Provides the runtime definition for creating or reusing testing Pinia
|
|
120
|
+
* instances and exposes a default configuration factory
|
|
121
|
+
* that presets can explicitly opt into.
|
|
88
122
|
*/
|
|
89
123
|
declare const piniaPlugin: PluginModuleWithDefaults<TestingPinia, VueTestPiniaOptions>;
|
|
90
124
|
|
|
91
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Creates Pinia plugin options for initializing or modifying stores
|
|
127
|
+
* before the component is mounted.
|
|
128
|
+
*
|
|
129
|
+
* The callback receives the resolved testing Pinia instance, whether
|
|
130
|
+
* it was newly created or reused through `withPluginInstance()`.
|
|
131
|
+
*
|
|
132
|
+
* Spread the returned options into the Pinia configuration provided
|
|
133
|
+
* to a TestForge component factory.
|
|
134
|
+
*
|
|
135
|
+
* @param mockStores - Callback invoked with the resolved testing Pinia instance.
|
|
136
|
+
* @returns Plugin options containing the store initialization callback.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { withMockStores } from "@testforgejs/vue-test-plugin-pinia";
|
|
141
|
+
*
|
|
142
|
+
* factory({}, {
|
|
143
|
+
* plugins: {
|
|
144
|
+
* pinia: {
|
|
145
|
+
* ...withMockStores((pinia) => {
|
|
146
|
+
* const store = useCounterStore(pinia);
|
|
147
|
+
* store.count = 42;
|
|
148
|
+
* }),
|
|
149
|
+
* },
|
|
150
|
+
* },
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare function withMockStores(mockStores: MockStoresFn): {
|
|
155
|
+
[MOCK_STORES]: MockStoresFn;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export { type MockStoresFn, PINIA_PLUGIN_NAME as PLUGIN_NAME, type PiniaRuntimeOptions, type VueTestPiniaOptions as PluginOptions, type VueTestPiniaOptions, piniaPlugin, piniaPlugin as plugin, withMockStores };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TestingOptions, TestingPinia } from '@pinia/testing';
|
|
2
|
-
import {
|
|
2
|
+
import { RuntimePluginOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Stable TestForge identifier for the managed Pinia plugin.
|
|
@@ -8,12 +8,13 @@ import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue
|
|
|
8
8
|
* in presets and other plugin-aware TestForge APIs.
|
|
9
9
|
*/
|
|
10
10
|
declare const PINIA_PLUGIN_NAME: "pinia";
|
|
11
|
+
declare const MOCK_STORES: unique symbol;
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
|
-
* A callback for configuring Pinia stores after the testing Pinia
|
|
14
|
-
*
|
|
14
|
+
* A callback for configuring Pinia stores after the testing Pinia
|
|
15
|
+
* instance has been resolved and before the component is mounted.
|
|
15
16
|
*
|
|
16
|
-
*
|
|
17
|
+
* The instance may be newly created or reused through `withPluginInstance()`.
|
|
17
18
|
*
|
|
18
19
|
* @param pinia - The testing Pinia instance used by the mounted component.
|
|
19
20
|
*/
|
|
@@ -21,36 +22,68 @@ type MockStoresFn = (pinia: TestingPinia) => void;
|
|
|
21
22
|
/**
|
|
22
23
|
* Configuration options for the Pinia test plugin.
|
|
23
24
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
25
|
+
* Extends native Pinia testing options with TestForge-specific
|
|
26
|
+
* store initialization support.
|
|
26
27
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
28
|
+
* Managed instance controls are provided separately by TestForge
|
|
29
|
+
* through its plugin configuration types.
|
|
29
30
|
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* Use `withMockStores()` to initialize or modify Pinia stores before
|
|
32
|
+
* the component is mounted.
|
|
33
|
+
*
|
|
34
|
+
* The store setup callback runs for both newly created Pinia instances
|
|
35
|
+
* and pre-created instances reused through `withPluginInstance()`.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { withMockStores } from "@testforgejs/vue-test-plugin-pinia";
|
|
40
|
+
*
|
|
41
|
+
* factory({}, {
|
|
42
|
+
* plugins: {
|
|
43
|
+
* pinia: {
|
|
44
|
+
* stubActions: false,
|
|
45
|
+
* ...withMockStores((pinia) => {
|
|
46
|
+
* const store = useCounterStore(pinia);
|
|
47
|
+
* store.count = 42;
|
|
48
|
+
* }),
|
|
49
|
+
* },
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @see `TestingOptions` from `@pinia/testing` for native Pinia configuration.
|
|
32
55
|
*/
|
|
33
|
-
type VueTestPiniaOptions = TestingOptions &
|
|
56
|
+
type VueTestPiniaOptions = TestingOptions & {
|
|
34
57
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
58
|
+
* Internal callback for configuring Pinia stores before mounting.
|
|
59
|
+
*
|
|
60
|
+
* Use the public `withMockStores()` helper instead of accessing
|
|
61
|
+
* this property directly.
|
|
62
|
+
*
|
|
63
|
+
* The callback runs for both newly created and reused Pinia instances.
|
|
37
64
|
*
|
|
38
|
-
* @
|
|
39
|
-
* ```ts
|
|
40
|
-
* factory({}, {
|
|
41
|
-
* plugins: {
|
|
42
|
-
* pinia: {
|
|
43
|
-
* mockStores: (pinia) => {
|
|
44
|
-
* const store = useCounterStore(pinia);
|
|
45
|
-
* store.count = 42;
|
|
46
|
-
* },
|
|
47
|
-
* },
|
|
48
|
-
* },
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
65
|
+
* @internal
|
|
51
66
|
*/
|
|
52
|
-
|
|
67
|
+
[MOCK_STORES]?: MockStoresFn;
|
|
53
68
|
};
|
|
69
|
+
/**
|
|
70
|
+
* Resolved runtime options for the managed Pinia test plugin.
|
|
71
|
+
*
|
|
72
|
+
* Combines {@link VueTestPiniaOptions} with the internal TestForge
|
|
73
|
+
* controls used to create, reuse, and expose a {@link TestingPinia} instance.
|
|
74
|
+
*
|
|
75
|
+
* These options are passed to `createPiniaPlugin()` after the Mount Pipeline
|
|
76
|
+
* has resolved the plugin configuration.
|
|
77
|
+
*
|
|
78
|
+
* Input metadata provided through `withPluginInstance()` is processed
|
|
79
|
+
* before this stage and is not part of the resolved runtime options.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
*
|
|
83
|
+
* @see {@link VueTestPiniaOptions}
|
|
84
|
+
* @see `RuntimePluginOptions` from `@testforgejs/vue-test-core`.
|
|
85
|
+
*/
|
|
86
|
+
type PiniaRuntimeOptions = RuntimePluginOptions<TestingPinia, VueTestPiniaOptions>;
|
|
54
87
|
|
|
55
88
|
/**
|
|
56
89
|
* TestForge core type augmentation for Pinia integration.
|
|
@@ -83,9 +116,43 @@ declare module "@testforgejs/vue-test-core" {
|
|
|
83
116
|
/**
|
|
84
117
|
* Managed Pinia testing plugin module for TestForge.
|
|
85
118
|
*
|
|
86
|
-
* Provides the runtime definition for creating testing Pinia
|
|
87
|
-
* and exposes
|
|
119
|
+
* Provides the runtime definition for creating or reusing testing Pinia
|
|
120
|
+
* instances and exposes a default configuration factory
|
|
121
|
+
* that presets can explicitly opt into.
|
|
88
122
|
*/
|
|
89
123
|
declare const piniaPlugin: PluginModuleWithDefaults<TestingPinia, VueTestPiniaOptions>;
|
|
90
124
|
|
|
91
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Creates Pinia plugin options for initializing or modifying stores
|
|
127
|
+
* before the component is mounted.
|
|
128
|
+
*
|
|
129
|
+
* The callback receives the resolved testing Pinia instance, whether
|
|
130
|
+
* it was newly created or reused through `withPluginInstance()`.
|
|
131
|
+
*
|
|
132
|
+
* Spread the returned options into the Pinia configuration provided
|
|
133
|
+
* to a TestForge component factory.
|
|
134
|
+
*
|
|
135
|
+
* @param mockStores - Callback invoked with the resolved testing Pinia instance.
|
|
136
|
+
* @returns Plugin options containing the store initialization callback.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { withMockStores } from "@testforgejs/vue-test-plugin-pinia";
|
|
141
|
+
*
|
|
142
|
+
* factory({}, {
|
|
143
|
+
* plugins: {
|
|
144
|
+
* pinia: {
|
|
145
|
+
* ...withMockStores((pinia) => {
|
|
146
|
+
* const store = useCounterStore(pinia);
|
|
147
|
+
* store.count = 42;
|
|
148
|
+
* }),
|
|
149
|
+
* },
|
|
150
|
+
* },
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
declare function withMockStores(mockStores: MockStoresFn): {
|
|
155
|
+
[MOCK_STORES]: MockStoresFn;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export { type MockStoresFn, PINIA_PLUGIN_NAME as PLUGIN_NAME, type PiniaRuntimeOptions, type VueTestPiniaOptions as PluginOptions, type VueTestPiniaOptions, piniaPlugin, piniaPlugin as plugin, withMockStores };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
// src/module/createPiniaPlugin.ts
|
|
2
2
|
import { createPluginInstance } from "@testforgejs/vue-test-core";
|
|
3
3
|
import { createTestingPinia } from "@pinia/testing";
|
|
4
|
+
|
|
5
|
+
// src/constants/constants.ts
|
|
6
|
+
var PINIA_PLUGIN_NAME = "pinia";
|
|
7
|
+
var MOCK_STORES = /* @__PURE__ */ Symbol("TestForge.pinia.mockStores");
|
|
8
|
+
|
|
9
|
+
// src/module/createPiniaPlugin.ts
|
|
4
10
|
function createPiniaPlugin(options) {
|
|
11
|
+
const { [MOCK_STORES]: mockStores, ...pluginOptions } = options;
|
|
5
12
|
const pinia = createPluginInstance(
|
|
6
13
|
createTestingPinia,
|
|
7
|
-
|
|
14
|
+
pluginOptions
|
|
8
15
|
);
|
|
9
|
-
if (
|
|
10
|
-
|
|
16
|
+
if (mockStores) {
|
|
17
|
+
mockStores(pinia);
|
|
11
18
|
}
|
|
12
19
|
return pinia;
|
|
13
20
|
}
|
|
@@ -25,9 +32,6 @@ var defaultOptions = (runner) => () => {
|
|
|
25
32
|
};
|
|
26
33
|
};
|
|
27
34
|
|
|
28
|
-
// src/constants/constants.ts
|
|
29
|
-
var PINIA_PLUGIN_NAME = "pinia";
|
|
30
|
-
|
|
31
35
|
// src/module/piniaPlugin.ts
|
|
32
36
|
var piniaPlugin = {
|
|
33
37
|
getName: () => PINIA_PLUGIN_NAME,
|
|
@@ -47,8 +51,16 @@ var piniaPlugin = {
|
|
|
47
51
|
}),
|
|
48
52
|
getDefaultOptions: defaultOptions
|
|
49
53
|
};
|
|
54
|
+
|
|
55
|
+
// src/helpers/withMockStores.ts
|
|
56
|
+
function withMockStores(mockStores) {
|
|
57
|
+
return {
|
|
58
|
+
[MOCK_STORES]: mockStores
|
|
59
|
+
};
|
|
60
|
+
}
|
|
50
61
|
export {
|
|
51
62
|
PINIA_PLUGIN_NAME as PLUGIN_NAME,
|
|
52
63
|
piniaPlugin,
|
|
53
|
-
piniaPlugin as plugin
|
|
64
|
+
piniaPlugin as plugin,
|
|
65
|
+
withMockStores
|
|
54
66
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@testforgejs/vue-test-plugin-pinia",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Official TestForge plugin for Pinia integration in component tests",
|
|
6
6
|
"homepage": "https://github.com/testforgejs/testforge#readme",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"pinia": "^3.0.0 || ^4.0.0",
|
|
47
47
|
"@pinia/testing": "^1.0.0 || ^2.0.0",
|
|
48
|
-
"@testforgejs/vue-test-core": "1.0.0-beta.
|
|
48
|
+
"@testforgejs/vue-test-core": "1.0.0-beta.6"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"pinia": "^4.0.0",
|
|
52
52
|
"@pinia/testing": "^2.0.0",
|
|
53
|
-
"@testforgejs/vue-test-core": "1.0.0-beta.
|
|
53
|
+
"@testforgejs/vue-test-core": "1.0.0-beta.6"
|
|
54
54
|
},
|
|
55
55
|
"testforge": {
|
|
56
56
|
"plugin": {
|