@testforgejs/vue-test-plugin-pinia 1.0.0-beta.2 → 1.0.0-beta.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.
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` is required.
27
+ > `@testforgejs/vue-test-core`, `pinia`, and `@pinia/testing` are required.
28
28
 
29
29
  ## Usage
30
30
 
31
- Register `piniaPlugin` in the TestForge plugin manifest.
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
- `defaults.pinia` is an options factory. A new Pinia options object is created for each pipeline context.
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 provides a Pinia instance for components mounted through TestForge.
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.x
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
- piniaPlugin: () => piniaPlugin
23
+ PLUGIN_NAME: () => PINIA_PLUGIN_NAME,
24
+ piniaPlugin: () => piniaPlugin,
25
+ plugin: () => piniaPlugin
24
26
  });
25
27
  module.exports = __toCommonJS(index_exports);
26
28
 
@@ -28,7 +30,10 @@ module.exports = __toCommonJS(index_exports);
28
30
  var import_vue_test_core = require("@testforgejs/vue-test-core");
29
31
  var import_testing = require("@pinia/testing");
30
32
  function createPiniaPlugin(options) {
31
- const pinia = (0, import_vue_test_core.createPluginInstance)(import_testing.createTestingPinia, options);
33
+ const pinia = (0, import_vue_test_core.createPluginInstance)(
34
+ import_testing.createTestingPinia,
35
+ options
36
+ );
32
37
  if (options.mockStores) {
33
38
  options.mockStores(pinia);
34
39
  }
@@ -37,8 +42,23 @@ function createPiniaPlugin(options) {
37
42
 
38
43
  // src/module/piniaPlugin.ts
39
44
  var import_pinia = require("pinia");
45
+
46
+ // src/defaults.ts
47
+ var defaultOptions = (runner) => () => {
48
+ if (!runner) {
49
+ return {};
50
+ }
51
+ return {
52
+ createSpy: runner.fn
53
+ };
54
+ };
55
+
56
+ // src/constants/constants.ts
57
+ var PINIA_PLUGIN_NAME = "pinia";
58
+
59
+ // src/module/piniaPlugin.ts
40
60
  var piniaPlugin = {
41
- getName: () => "pinia",
61
+ getName: () => PINIA_PLUGIN_NAME,
42
62
  getDefinition: () => ({
43
63
  // beforeCreate(ctx, options) {
44
64
  // return {
@@ -51,9 +71,12 @@ var piniaPlugin = {
51
71
  afterCreate(instance) {
52
72
  (0, import_pinia.setActivePinia)(instance);
53
73
  }
54
- })
74
+ }),
75
+ getDefaultOptions: defaultOptions
55
76
  };
56
77
  // Annotate the CommonJS export names for ESM import in node:
57
78
  0 && (module.exports = {
58
- piniaPlugin
79
+ PLUGIN_NAME,
80
+ piniaPlugin,
81
+ plugin
59
82
  });
package/dist/index.d.cts CHANGED
@@ -1,24 +1,33 @@
1
- import { Pinia } from 'pinia';
2
- import { TestingOptions } from '@pinia/testing';
3
- import { PluginControlOptions, PluginModule } from '@testforgejs/vue-test-core';
1
+ import { TestingOptions, TestingPinia } from '@pinia/testing';
2
+ import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
4
3
 
5
4
  /**
6
- * A callback function to mutate or configure Pinia stores immediately after they are created.
7
- * Used to set the initial state (mocking) in tests.
5
+ * Stable TestForge identifier for the managed Pinia plugin.
8
6
  *
9
- * @param pinia - Созданный инстанс Pinia для тестирования.
7
+ * Use this identifier when declaring Pinia configuration
8
+ * in presets and other plugin-aware TestForge APIs.
10
9
  */
11
- type MockStoresFn = (pinia: Pinia) => void;
10
+ declare const PINIA_PLUGIN_NAME: "pinia";
11
+
12
+ /**
13
+ * A callback for configuring Pinia stores after the testing Pinia instance
14
+ * is created and before the component is mounted.
15
+ *
16
+ * Use it to initialize or modify stores required by the test.
17
+ *
18
+ * @param pinia - The testing Pinia instance used by the mounted component.
19
+ */
20
+ type MockStoresFn = (pinia: TestingPinia) => void;
12
21
  /**
13
22
  * Configuration options for the Pinia test plugin.
14
23
  *
15
- * This interface integrates the standard Pinia testing initialization settings
16
- * (`TestingOptions` from `@pinia/testing`) with the TestForge core configuration options.
24
+ * Combines standard Pinia testing configuration (`TestingOptions` from `@pinia/testing`)
25
+ * with TestForge plugin control options.
17
26
  *
18
- * @see {@link TestingOptions} to configure action stubs and the initial state.
19
- * @see {@link PluginControlOptions} to use interception methods such as `expose`.
27
+ * @see {@link TestingOptions} for configuring action stubs, initial state, and Pinia plugins.
28
+ * @see {@link PluginControlOptions} for instance capturing and exposure mechanisms.
20
29
  */
21
- interface VueTestPiniaOptions extends TestingOptions, PluginControlOptions<Pinia> {
30
+ interface VueTestPiniaOptions extends TestingOptions, PluginControlOptions<TestingPinia> {
22
31
  /**
23
32
  * A callback function to modify the state of stores before a component is mounted.
24
33
  *
@@ -56,10 +65,16 @@ declare module "@testforgejs/vue-test-core" {
56
65
  * Configuration for the `pinia` plugin.
57
66
  * Accepts an object of type {@link VueTestPiniaOptions}, which controls the behavior of the stores in tests.
58
67
  */
59
- pinia: VueTestPiniaOptions;
68
+ [PINIA_PLUGIN_NAME]: VueTestPiniaOptions;
60
69
  }
61
70
  }
62
71
 
63
- declare const piniaPlugin: PluginModule<Pinia, VueTestPiniaOptions>;
72
+ /**
73
+ * Managed Pinia testing plugin module for TestForge.
74
+ *
75
+ * Provides the runtime definition for creating testing Pinia instances
76
+ * and exposes the default configuration used by TestForge-managed presets.
77
+ */
78
+ declare const piniaPlugin: PluginModuleWithDefaults<TestingPinia, VueTestPiniaOptions>;
64
79
 
65
- export { type MockStoresFn, type VueTestPiniaOptions, piniaPlugin };
80
+ export { type MockStoresFn, PINIA_PLUGIN_NAME as PLUGIN_NAME, type VueTestPiniaOptions, piniaPlugin, piniaPlugin as plugin };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,33 @@
1
- import { Pinia } from 'pinia';
2
- import { TestingOptions } from '@pinia/testing';
3
- import { PluginControlOptions, PluginModule } from '@testforgejs/vue-test-core';
1
+ import { TestingOptions, TestingPinia } from '@pinia/testing';
2
+ import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
4
3
 
5
4
  /**
6
- * A callback function to mutate or configure Pinia stores immediately after they are created.
7
- * Used to set the initial state (mocking) in tests.
5
+ * Stable TestForge identifier for the managed Pinia plugin.
8
6
  *
9
- * @param pinia - Созданный инстанс Pinia для тестирования.
7
+ * Use this identifier when declaring Pinia configuration
8
+ * in presets and other plugin-aware TestForge APIs.
10
9
  */
11
- type MockStoresFn = (pinia: Pinia) => void;
10
+ declare const PINIA_PLUGIN_NAME: "pinia";
11
+
12
+ /**
13
+ * A callback for configuring Pinia stores after the testing Pinia instance
14
+ * is created and before the component is mounted.
15
+ *
16
+ * Use it to initialize or modify stores required by the test.
17
+ *
18
+ * @param pinia - The testing Pinia instance used by the mounted component.
19
+ */
20
+ type MockStoresFn = (pinia: TestingPinia) => void;
12
21
  /**
13
22
  * Configuration options for the Pinia test plugin.
14
23
  *
15
- * This interface integrates the standard Pinia testing initialization settings
16
- * (`TestingOptions` from `@pinia/testing`) with the TestForge core configuration options.
24
+ * Combines standard Pinia testing configuration (`TestingOptions` from `@pinia/testing`)
25
+ * with TestForge plugin control options.
17
26
  *
18
- * @see {@link TestingOptions} to configure action stubs and the initial state.
19
- * @see {@link PluginControlOptions} to use interception methods such as `expose`.
27
+ * @see {@link TestingOptions} for configuring action stubs, initial state, and Pinia plugins.
28
+ * @see {@link PluginControlOptions} for instance capturing and exposure mechanisms.
20
29
  */
21
- interface VueTestPiniaOptions extends TestingOptions, PluginControlOptions<Pinia> {
30
+ interface VueTestPiniaOptions extends TestingOptions, PluginControlOptions<TestingPinia> {
22
31
  /**
23
32
  * A callback function to modify the state of stores before a component is mounted.
24
33
  *
@@ -56,10 +65,16 @@ declare module "@testforgejs/vue-test-core" {
56
65
  * Configuration for the `pinia` plugin.
57
66
  * Accepts an object of type {@link VueTestPiniaOptions}, which controls the behavior of the stores in tests.
58
67
  */
59
- pinia: VueTestPiniaOptions;
68
+ [PINIA_PLUGIN_NAME]: VueTestPiniaOptions;
60
69
  }
61
70
  }
62
71
 
63
- declare const piniaPlugin: PluginModule<Pinia, VueTestPiniaOptions>;
72
+ /**
73
+ * Managed Pinia testing plugin module for TestForge.
74
+ *
75
+ * Provides the runtime definition for creating testing Pinia instances
76
+ * and exposes the default configuration used by TestForge-managed presets.
77
+ */
78
+ declare const piniaPlugin: PluginModuleWithDefaults<TestingPinia, VueTestPiniaOptions>;
64
79
 
65
- export { type MockStoresFn, type VueTestPiniaOptions, piniaPlugin };
80
+ export { type MockStoresFn, PINIA_PLUGIN_NAME as PLUGIN_NAME, type VueTestPiniaOptions, piniaPlugin, piniaPlugin as plugin };
package/dist/index.js CHANGED
@@ -2,7 +2,10 @@
2
2
  import { createPluginInstance } from "@testforgejs/vue-test-core";
3
3
  import { createTestingPinia } from "@pinia/testing";
4
4
  function createPiniaPlugin(options) {
5
- const pinia = createPluginInstance(createTestingPinia, options);
5
+ const pinia = createPluginInstance(
6
+ createTestingPinia,
7
+ options
8
+ );
6
9
  if (options.mockStores) {
7
10
  options.mockStores(pinia);
8
11
  }
@@ -11,8 +14,23 @@ function createPiniaPlugin(options) {
11
14
 
12
15
  // src/module/piniaPlugin.ts
13
16
  import { setActivePinia } from "pinia";
17
+
18
+ // src/defaults.ts
19
+ var defaultOptions = (runner) => () => {
20
+ if (!runner) {
21
+ return {};
22
+ }
23
+ return {
24
+ createSpy: runner.fn
25
+ };
26
+ };
27
+
28
+ // src/constants/constants.ts
29
+ var PINIA_PLUGIN_NAME = "pinia";
30
+
31
+ // src/module/piniaPlugin.ts
14
32
  var piniaPlugin = {
15
- getName: () => "pinia",
33
+ getName: () => PINIA_PLUGIN_NAME,
16
34
  getDefinition: () => ({
17
35
  // beforeCreate(ctx, options) {
18
36
  // return {
@@ -25,8 +43,11 @@ var piniaPlugin = {
25
43
  afterCreate(instance) {
26
44
  setActivePinia(instance);
27
45
  }
28
- })
46
+ }),
47
+ getDefaultOptions: defaultOptions
29
48
  };
30
49
  export {
31
- piniaPlugin
50
+ PINIA_PLUGIN_NAME as PLUGIN_NAME,
51
+ piniaPlugin,
52
+ piniaPlugin as plugin
32
53
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testforgejs/vue-test-plugin-pinia",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.4",
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": ">=3.0.0 <5.0.0",
47
- "@pinia/testing": ">=1.0.0 <3.0.0",
48
- "@testforgejs/vue-test-core": "1.0.0-beta.2"
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.2"
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",