@testforgejs/vue-test-plugin-pinia 1.0.0-beta.2 → 1.0.0-beta.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.
- package/README.md +224 -7
- package/dist/index.cjs +24 -4
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +21 -3
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -24,13 +24,78 @@ npm install -D @testforgejs/vue-test-plugin-pinia@beta
|
|
|
24
24
|
yarn add -D @testforgejs/vue-test-plugin-pinia@beta
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
> `@testforgejs/vue-test-core`
|
|
27
|
+
> `@testforgejs/vue-test-core`, `pinia`, and `@pinia/testing` are required.
|
|
28
28
|
|
|
29
29
|
## Usage
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
### Using plugin defaults
|
|
32
|
+
|
|
33
|
+
The plugin provides a project-independent default configuration through `getDefaultOptions()`.
|
|
34
|
+
|
|
35
|
+
When using Vitest, you can pass `vi` as the runner:
|
|
32
36
|
|
|
33
37
|
```typescript
|
|
38
|
+
import { vi } from "vitest";
|
|
39
|
+
|
|
40
|
+
import { createTestFramework } from "@testforgejs/vue-test-core";
|
|
41
|
+
import { piniaPlugin } from "@testforgejs/vue-test-plugin-pinia";
|
|
42
|
+
|
|
43
|
+
const framework = createTestFramework({
|
|
44
|
+
presets: {
|
|
45
|
+
default: {
|
|
46
|
+
manifest: [
|
|
47
|
+
{
|
|
48
|
+
module: piniaPlugin,
|
|
49
|
+
enabled: true,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
defaults: {
|
|
53
|
+
pinia: piniaPlugin.getDefaultOptions(vi),
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
For Jest, pass `jest` instead:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
pinia: piniaPlugin.getDefaultOptions(jest),
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Passing a runner is optional:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
pinia: piniaPlugin.getDefaultOptions(),
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`getDefaultOptions()` returns an options factory suitable for use in a preset.
|
|
73
|
+
|
|
74
|
+
The plugin-provided defaults are equivalent to:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
{
|
|
78
|
+
createSpy: runner?.fn,
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
When a runner is provided, its `fn` implementation is passed to `@pinia/testing` as `createSpy`.
|
|
83
|
+
|
|
84
|
+
When the runner is omitted, `createSpy` is left undefined and `@pinia/testing` handles spy resolution according to its own behavior. This can be useful in environments where the test runner exposes supported globals.
|
|
85
|
+
|
|
86
|
+
The plugin intentionally does not override other `createTestingPinia()` options. As a result, behavior such as action stubbing, initial state, `$patch()` handling, and `$reset()` handling follows the defaults provided by `@pinia/testing`.
|
|
87
|
+
|
|
88
|
+
In particular, store actions are stubbed by default and therefore do not execute their implementations unless `stubActions: false` is configured explicitly.
|
|
89
|
+
|
|
90
|
+
Plugin defaults are **not applied automatically**. Adding the plugin to a preset manifest declares that the plugin is available and whether it is enabled; the preset explicitly decides whether to use the plugin-provided defaults or provide its own configuration.
|
|
91
|
+
|
|
92
|
+
### Providing custom options
|
|
93
|
+
|
|
94
|
+
You can define the Pinia testing configuration directly in the preset instead:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { vi } from "vitest";
|
|
98
|
+
|
|
34
99
|
import { createTestFramework } from "@testforgejs/vue-test-core";
|
|
35
100
|
import { piniaPlugin } from "@testforgejs/vue-test-plugin-pinia";
|
|
36
101
|
|
|
@@ -45,7 +110,13 @@ const framework = createTestFramework({
|
|
|
45
110
|
],
|
|
46
111
|
defaults: {
|
|
47
112
|
pinia: () => ({
|
|
48
|
-
initialState: {
|
|
113
|
+
initialState: {
|
|
114
|
+
user: {
|
|
115
|
+
name: "Test User",
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
stubActions: false,
|
|
119
|
+
createSpy: vi.fn,
|
|
49
120
|
}),
|
|
50
121
|
},
|
|
51
122
|
},
|
|
@@ -53,14 +124,160 @@ const framework = createTestFramework({
|
|
|
53
124
|
});
|
|
54
125
|
```
|
|
55
126
|
|
|
56
|
-
`
|
|
127
|
+
Using `getDefaultOptions()` is optional. Define custom defaults when tests require application-specific initial state, real action execution, Pinia plugins, or other testing behavior.
|
|
128
|
+
|
|
129
|
+
## Configuration
|
|
130
|
+
|
|
131
|
+
### Pinia testing options
|
|
132
|
+
|
|
133
|
+
The plugin integrates TestForge with Pinia using `@pinia/testing` and `createTestingPinia()`.
|
|
134
|
+
|
|
135
|
+
Configuration fields such as `initialState`, `stubActions`, `createSpy`, `plugins`, `fakeApp`, `stubPatch`, and `stubReset` are provided by `@pinia/testing`.
|
|
136
|
+
|
|
137
|
+
For example:
|
|
138
|
+
|
|
139
|
+
- `initialState` provides initial state for stores created by the testing Pinia.
|
|
140
|
+
- `stubActions` controls whether store actions execute or are replaced by spies.
|
|
141
|
+
- `createSpy` specifies the spy implementation used for actions and other mocked operations.
|
|
142
|
+
- `plugins` installs application Pinia plugins into the testing Pinia.
|
|
143
|
+
- `fakeApp` creates an application and installs the testing Pinia into it.
|
|
144
|
+
- `stubPatch` controls whether `$patch()` modifies store state.
|
|
145
|
+
- `stubReset` controls whether `$reset()` modifies store state.
|
|
146
|
+
|
|
147
|
+
TestForge does not redefine these Pinia testing options. The integration passes them to `createTestingPinia()` when creating the Pinia instance.
|
|
148
|
+
|
|
149
|
+
Refer to the Pinia documentation for the complete set of `TestingOptions` and their behavior.
|
|
150
|
+
|
|
151
|
+
### TestForge plugin defaults
|
|
152
|
+
|
|
153
|
+
The defaults provided by this package intentionally contain only the runner integration:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
{
|
|
157
|
+
createSpy: runner?.fn,
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
When a runner is provided, TestForge supplies its mock-function implementation to `@pinia/testing`.
|
|
162
|
+
|
|
163
|
+
The plugin does not explicitly configure:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
initialState;
|
|
167
|
+
stubActions;
|
|
168
|
+
plugins;
|
|
169
|
+
fakeApp;
|
|
170
|
+
stubPatch;
|
|
171
|
+
stubReset;
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
These options therefore retain the behavior defined by `createTestingPinia()`.
|
|
175
|
+
|
|
176
|
+
This keeps the plugin defaults project-independent and avoids overriding Pinia testing behavior when TestForge does not need to do so.
|
|
177
|
+
|
|
178
|
+
For example, `createTestingPinia()` stubs store actions by default. To execute action implementations while keeping them observable as spies, configure:
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
defaults: {
|
|
182
|
+
pinia: () => ({
|
|
183
|
+
stubActions: false,
|
|
184
|
+
createSpy: vi.fn,
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Runner integration
|
|
190
|
+
|
|
191
|
+
`getDefaultOptions()` optionally accepts a TestForge-compatible runner.
|
|
192
|
+
|
|
193
|
+
With Vitest:
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
piniaPlugin.getDefaultOptions(vi);
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
With Jest:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
piniaPlugin.getDefaultOptions(jest);
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
The runner's `fn` implementation is used as the `createSpy` option for `@pinia/testing`.
|
|
206
|
+
|
|
207
|
+
Passing the runner explicitly makes the spy implementation part of the preset configuration and avoids depending on test-runner globals.
|
|
208
|
+
|
|
209
|
+
The runner can also be omitted:
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
piniaPlugin.getDefaultOptions();
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
In that case, the plugin does not provide a spy implementation and `@pinia/testing` is responsible for resolving one from the test environment.
|
|
216
|
+
|
|
217
|
+
For example, `@pinia/testing` can use Jest globals automatically and can use Vitest globals when Vitest is configured with `globals: true`.
|
|
218
|
+
|
|
219
|
+
### Options factories
|
|
220
|
+
|
|
221
|
+
Preset defaults are defined as factories:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
defaults: {
|
|
225
|
+
pinia: () => ({
|
|
226
|
+
initialState: {
|
|
227
|
+
user: {
|
|
228
|
+
name: "Test User",
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
stubActions: false,
|
|
232
|
+
createSpy: vi.fn,
|
|
233
|
+
}),
|
|
234
|
+
},
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
Each invocation of the factory produces a fresh options object for the current TestForge pipeline execution.
|
|
238
|
+
|
|
239
|
+
`piniaPlugin.getDefaultOptions(runner)` follows the same contract: it returns an options factory rather than a shared options object.
|
|
240
|
+
|
|
241
|
+
This allows presets to choose explicitly between:
|
|
242
|
+
|
|
243
|
+
- the project-independent defaults provided by the plugin; and
|
|
244
|
+
- a custom Pinia testing configuration defined by the preset.
|
|
245
|
+
|
|
246
|
+
## Package exports
|
|
247
|
+
|
|
248
|
+
The package provides both descriptive and standardized plugin exports:
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
import { piniaPlugin, plugin, PLUGIN_NAME } from "@testforgejs/vue-test-plugin-pinia";
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### `piniaPlugin`
|
|
255
|
+
|
|
256
|
+
The descriptive Pinia plugin module export.
|
|
257
|
+
|
|
258
|
+
### `plugin`
|
|
259
|
+
|
|
260
|
+
The standardized plugin module export.
|
|
261
|
+
|
|
262
|
+
It references the same plugin module as `piniaPlugin` and provides a consistent package-level API across TestForge plugin packages.
|
|
263
|
+
|
|
264
|
+
### `PLUGIN_NAME`
|
|
265
|
+
|
|
266
|
+
The standardized plugin identifier export.
|
|
267
|
+
|
|
268
|
+
For this package:
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
PLUGIN_NAME === "pinia";
|
|
272
|
+
```
|
|
57
273
|
|
|
58
|
-
The plugin
|
|
274
|
+
The standardized `plugin` and `PLUGIN_NAME` exports are useful for tooling and other code that works with TestForge plugin packages generically.
|
|
59
275
|
|
|
60
276
|
## Supported versions
|
|
61
277
|
|
|
62
|
-
- Vue: 3.
|
|
63
|
-
- Pinia: 3.x
|
|
278
|
+
- Vue: 3.3.0 or higher
|
|
279
|
+
- Pinia: 3.x and 4.x
|
|
280
|
+
- `@pinia/testing`: 1.x and 2.x
|
|
64
281
|
|
|
65
282
|
## Documentation
|
|
66
283
|
|
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
23
|
+
PLUGIN_NAME: () => PINIA_PLUGIN_NAME,
|
|
24
|
+
piniaPlugin: () => piniaPlugin,
|
|
25
|
+
plugin: () => piniaPlugin
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(index_exports);
|
|
26
28
|
|
|
@@ -37,8 +39,23 @@ function createPiniaPlugin(options) {
|
|
|
37
39
|
|
|
38
40
|
// src/module/piniaPlugin.ts
|
|
39
41
|
var import_pinia = require("pinia");
|
|
42
|
+
|
|
43
|
+
// src/defaults.ts
|
|
44
|
+
var defaultOptions = (runner) => () => {
|
|
45
|
+
if (!runner) {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
createSpy: runner.fn
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/constants/constants.ts
|
|
54
|
+
var PINIA_PLUGIN_NAME = "pinia";
|
|
55
|
+
|
|
56
|
+
// src/module/piniaPlugin.ts
|
|
40
57
|
var piniaPlugin = {
|
|
41
|
-
getName: () =>
|
|
58
|
+
getName: () => PINIA_PLUGIN_NAME,
|
|
42
59
|
getDefinition: () => ({
|
|
43
60
|
// beforeCreate(ctx, options) {
|
|
44
61
|
// return {
|
|
@@ -51,9 +68,12 @@ var piniaPlugin = {
|
|
|
51
68
|
afterCreate(instance) {
|
|
52
69
|
(0, import_pinia.setActivePinia)(instance);
|
|
53
70
|
}
|
|
54
|
-
})
|
|
71
|
+
}),
|
|
72
|
+
getDefaultOptions: defaultOptions
|
|
55
73
|
};
|
|
56
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
57
75
|
0 && (module.exports = {
|
|
58
|
-
|
|
76
|
+
PLUGIN_NAME,
|
|
77
|
+
piniaPlugin,
|
|
78
|
+
plugin
|
|
59
79
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Pinia } from 'pinia';
|
|
2
2
|
import { TestingOptions } from '@pinia/testing';
|
|
3
|
-
import { PluginControlOptions,
|
|
3
|
+
import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
|
|
4
|
+
|
|
5
|
+
declare const PINIA_PLUGIN_NAME: "pinia";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* A callback function to mutate or configure Pinia stores immediately after they are created.
|
|
@@ -56,10 +58,10 @@ declare module "@testforgejs/vue-test-core" {
|
|
|
56
58
|
* Configuration for the `pinia` plugin.
|
|
57
59
|
* Accepts an object of type {@link VueTestPiniaOptions}, which controls the behavior of the stores in tests.
|
|
58
60
|
*/
|
|
59
|
-
|
|
61
|
+
[PINIA_PLUGIN_NAME]: VueTestPiniaOptions;
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
declare const piniaPlugin:
|
|
65
|
+
declare const piniaPlugin: PluginModuleWithDefaults<Pinia, VueTestPiniaOptions>;
|
|
64
66
|
|
|
65
|
-
export { type MockStoresFn, type VueTestPiniaOptions, piniaPlugin };
|
|
67
|
+
export { type MockStoresFn, PINIA_PLUGIN_NAME as PLUGIN_NAME, type VueTestPiniaOptions, piniaPlugin, piniaPlugin as plugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Pinia } from 'pinia';
|
|
2
2
|
import { TestingOptions } from '@pinia/testing';
|
|
3
|
-
import { PluginControlOptions,
|
|
3
|
+
import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
|
|
4
|
+
|
|
5
|
+
declare const PINIA_PLUGIN_NAME: "pinia";
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* A callback function to mutate or configure Pinia stores immediately after they are created.
|
|
@@ -56,10 +58,10 @@ declare module "@testforgejs/vue-test-core" {
|
|
|
56
58
|
* Configuration for the `pinia` plugin.
|
|
57
59
|
* Accepts an object of type {@link VueTestPiniaOptions}, which controls the behavior of the stores in tests.
|
|
58
60
|
*/
|
|
59
|
-
|
|
61
|
+
[PINIA_PLUGIN_NAME]: VueTestPiniaOptions;
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
declare const piniaPlugin:
|
|
65
|
+
declare const piniaPlugin: PluginModuleWithDefaults<Pinia, VueTestPiniaOptions>;
|
|
64
66
|
|
|
65
|
-
export { type MockStoresFn, type VueTestPiniaOptions, piniaPlugin };
|
|
67
|
+
export { type MockStoresFn, PINIA_PLUGIN_NAME as PLUGIN_NAME, type VueTestPiniaOptions, piniaPlugin, piniaPlugin as plugin };
|
package/dist/index.js
CHANGED
|
@@ -11,8 +11,23 @@ function createPiniaPlugin(options) {
|
|
|
11
11
|
|
|
12
12
|
// src/module/piniaPlugin.ts
|
|
13
13
|
import { setActivePinia } from "pinia";
|
|
14
|
+
|
|
15
|
+
// src/defaults.ts
|
|
16
|
+
var defaultOptions = (runner) => () => {
|
|
17
|
+
if (!runner) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
createSpy: runner.fn
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/constants/constants.ts
|
|
26
|
+
var PINIA_PLUGIN_NAME = "pinia";
|
|
27
|
+
|
|
28
|
+
// src/module/piniaPlugin.ts
|
|
14
29
|
var piniaPlugin = {
|
|
15
|
-
getName: () =>
|
|
30
|
+
getName: () => PINIA_PLUGIN_NAME,
|
|
16
31
|
getDefinition: () => ({
|
|
17
32
|
// beforeCreate(ctx, options) {
|
|
18
33
|
// return {
|
|
@@ -25,8 +40,11 @@ var piniaPlugin = {
|
|
|
25
40
|
afterCreate(instance) {
|
|
26
41
|
setActivePinia(instance);
|
|
27
42
|
}
|
|
28
|
-
})
|
|
43
|
+
}),
|
|
44
|
+
getDefaultOptions: defaultOptions
|
|
29
45
|
};
|
|
30
46
|
export {
|
|
31
|
-
|
|
47
|
+
PINIA_PLUGIN_NAME as PLUGIN_NAME,
|
|
48
|
+
piniaPlugin,
|
|
49
|
+
piniaPlugin as plugin
|
|
32
50
|
};
|
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.3",
|
|
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",
|
|
@@ -43,14 +43,20 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"author": "Roman Levchenko",
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"pinia": "
|
|
47
|
-
"@pinia/testing": "
|
|
48
|
-
"@testforgejs/vue-test-core": "1.0.0-beta.
|
|
46
|
+
"pinia": "^3.0.0 || ^4.0.0",
|
|
47
|
+
"@pinia/testing": "^1.0.0 || ^2.0.0",
|
|
48
|
+
"@testforgejs/vue-test-core": "1.0.0-beta.3"
|
|
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.3"
|
|
54
|
+
},
|
|
55
|
+
"testforge": {
|
|
56
|
+
"plugin": {
|
|
57
|
+
"schemaVersion": 1,
|
|
58
|
+
"displayName": "Pinia"
|
|
59
|
+
}
|
|
54
60
|
},
|
|
55
61
|
"scripts": {
|
|
56
62
|
"build": "tsup",
|