@testforgejs/vue-test-plugin-router 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
@@ -1,6 +1,6 @@
1
1
  # @testforgejs/vue-test-plugin-router
2
2
 
3
- Official TestForge plugin for Vue Router integration in component tests.
3
+ Vue Router integration for TestForge component tests.
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,13 +24,63 @@ npm install -D @testforgejs/vue-test-plugin-router@beta
24
24
  yarn add -D @testforgejs/vue-test-plugin-router@beta
25
25
  ```
26
26
 
27
- > `@testforgejs/vue-test-core` is required.
27
+ > `@testforgejs/vue-test-core` and `vue-router` are required.
28
28
 
29
29
  ## Usage
30
30
 
31
- Register `routerPlugin` in the TestForge plugin manifest.
31
+ ### Using plugin defaults
32
+
33
+ The plugin provides a project-independent default configuration through `getDefaultOptions()`:
34
+
35
+ ```typescript
36
+ import { createTestFramework } from "@testforgejs/vue-test-core";
37
+ import { routerPlugin } from "@testforgejs/vue-test-plugin-router";
38
+
39
+ const framework = createTestFramework({
40
+ presets: {
41
+ default: {
42
+ manifest: [
43
+ {
44
+ module: routerPlugin,
45
+ enabled: true,
46
+ },
47
+ ],
48
+ defaults: {
49
+ router: routerPlugin.getDefaultOptions(),
50
+ },
51
+ },
52
+ },
53
+ });
54
+
55
+ const factory = framework.testComponentFactory(MyComponent);
56
+
57
+ const wrapper = factory();
58
+ ```
59
+
60
+ `getDefaultOptions()` returns an options factory suitable for use in a preset.
61
+
62
+ The plugin-provided defaults are equivalent to:
32
63
 
33
64
  ```typescript
65
+ {
66
+ history: createMemoryHistory(),
67
+ routes: [],
68
+ }
69
+ ```
70
+
71
+ The in-memory history keeps router state isolated from the browser environment, while the empty route table avoids introducing application-specific routes.
72
+
73
+ These defaults provide the minimum Vue Router configuration required to create a router instance. They do not define routes or other routing behavior on behalf of the application.
74
+
75
+ 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.
76
+
77
+ ### Providing custom options
78
+
79
+ You can define the Vue Router configuration directly in the preset instead:
80
+
81
+ ```typescript
82
+ import { createMemoryHistory } from "vue-router";
83
+
34
84
  import { createTestFramework } from "@testforgejs/vue-test-core";
35
85
  import { routerPlugin } from "@testforgejs/vue-test-plugin-router";
36
86
 
@@ -45,34 +95,130 @@ const framework = createTestFramework({
45
95
  ],
46
96
  defaults: {
47
97
  router: () => ({
98
+ history: createMemoryHistory(),
48
99
  routes: [
49
100
  {
50
101
  path: "/",
51
102
  component: { render: () => null },
52
103
  },
104
+ {
105
+ path: "/users/:id",
106
+ component: UserDetails,
107
+ },
53
108
  ],
54
109
  }),
55
110
  },
56
111
  },
57
112
  },
58
113
  });
114
+ ```
59
115
 
60
- const factory = framework.testComponentFactory(MyComponent);
116
+ Using `getDefaultOptions()` is optional. Define custom defaults when tests require application-specific routes, a different history implementation, navigation behavior, or other Vue Router configuration.
61
117
 
62
- const wrapper = factory();
118
+ For tests that depend on application routes, [create a project-specific preset](https://github.com/testforgejs/testforge/blob/main/docs/preset-authoring-guide.md) that provides the router configuration required by the application.
119
+
120
+ ## Configuration
121
+
122
+ ### Vue Router options
123
+
124
+ The plugin integrates TestForge with Vue Router by creating a router from the provided Vue Router options.
125
+
126
+ Configuration fields such as `history`, `routes`, `scrollBehavior`, `linkActiveClass`, and other router options belong to Vue Router.
127
+
128
+ TestForge does not define an alternative router configuration format. The integration passes these options to Vue Router when creating the router instance.
129
+
130
+ Refer to the Vue Router documentation for the complete set of supported router options and their behavior.
131
+
132
+ ### TestForge plugin defaults
133
+
134
+ The defaults provided by this package intentionally contain only the configuration required to create an isolated, project-independent router:
135
+
136
+ ```typescript
137
+ {
138
+ history: createMemoryHistory(),
139
+ routes: [],
140
+ }
63
141
  ```
64
142
 
65
- `defaults.router` is an options factory. Each invocation produces a fresh Vue Router options object for the current pipeline context.
143
+ `createMemoryHistory()` is used regardless of whether the test environment exposes browser globals. This keeps the default router isolated from `window.location` and browser history state and makes the configuration consistent across test environments.
66
144
 
67
- The default configuration provides a minimal `/` route so that Vue Router is ready to use without requiring application-specific routes.
145
+ The route table is empty because TestForge does not know the routes defined by the application. Application routes should be supplied by a project-specific preset or other explicit test configuration.
68
146
 
69
- For tests that depend on application routes, [create a project-specific preset](https://github.com/testforgejs/testforge/blob/main/docs/preset-authoring-guide.md) that provides the router configuration required by the application.
147
+ The plugin does not add a synthetic `/` route or otherwise define application routing behavior.
148
+
149
+ If tests require actual routes, provide them explicitly:
150
+
151
+ ```typescript
152
+ defaults: {
153
+ router: () => ({
154
+ history: createMemoryHistory(),
155
+ routes: [
156
+ {
157
+ path: "/users/:id",
158
+ component: UserDetails,
159
+ },
160
+ ],
161
+ }),
162
+ },
163
+ ```
164
+
165
+ Likewise, if tests specifically depend on browser history behavior, provide the appropriate Vue Router history implementation explicitly.
166
+
167
+ ### Options factories
168
+
169
+ Preset defaults are defined as factories:
170
+
171
+ ```typescript
172
+ defaults: {
173
+ router: () => ({
174
+ history: createMemoryHistory(),
175
+ routes: [],
176
+ }),
177
+ },
178
+ ```
179
+
180
+ Each invocation of the factory produces a fresh options object for the current TestForge pipeline execution, including a fresh in-memory history instance.
181
+
182
+ `routerPlugin.getDefaultOptions()` follows the same contract: it returns an options factory rather than a shared options object.
183
+
184
+ This allows presets to choose explicitly between:
185
+
186
+ - the minimal project-independent defaults provided by the plugin; and
187
+ - a custom Vue Router configuration defined by the preset.
188
+
189
+ ## Package exports
190
+
191
+ The package provides both descriptive and standardized plugin exports:
192
+
193
+ ```typescript
194
+ import { routerPlugin, plugin, PLUGIN_NAME } from "@testforgejs/vue-test-plugin-router";
195
+ ```
196
+
197
+ ### `routerPlugin`
198
+
199
+ The descriptive Vue Router plugin module export.
200
+
201
+ ### `plugin`
202
+
203
+ The standardized plugin module export.
204
+
205
+ It references the same plugin module as `routerPlugin` and provides a consistent package-level API across TestForge plugin packages.
206
+
207
+ ### `PLUGIN_NAME`
208
+
209
+ The standardized plugin identifier export.
210
+
211
+ For this package:
212
+
213
+ ```typescript
214
+ PLUGIN_NAME === "router";
215
+ ```
70
216
 
71
- The plugin provides Vue Router integration for components mounted through TestForge.
217
+ The standardized `plugin` and `PLUGIN_NAME` exports are useful for tooling and other code that works with TestForge plugin packages generically.
72
218
 
73
219
  ## Supported versions
74
220
 
75
- - Vue: 3.x
221
+ - Vue: 3.3.0 or higher
76
222
  - Vue Router: 4.x and 5.x
77
223
 
78
224
  ## Documentation
package/dist/index.cjs CHANGED
@@ -20,6 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ PLUGIN_NAME: () => ROUTER_PLUGIN_NAME,
24
+ plugin: () => routerPlugin,
23
25
  routerPlugin: () => routerPlugin
24
26
  });
25
27
  module.exports = __toCommonJS(index_exports);
@@ -31,14 +33,27 @@ function createRouterPlugin(options) {
31
33
  return (0, import_vue_test_core.createPluginInstance)(import_vue_router.createRouter, options);
32
34
  }
33
35
 
36
+ // src/defaults.ts
37
+ var import_vue_router2 = require("vue-router");
38
+ var defaultOptions = () => () => ({
39
+ history: (0, import_vue_router2.createMemoryHistory)(),
40
+ routes: []
41
+ });
42
+
43
+ // src/constants/constants.ts
44
+ var ROUTER_PLUGIN_NAME = "router";
45
+
34
46
  // src/module/routerPlugin.ts
35
47
  var routerPlugin = {
36
- getName: () => "router",
48
+ getName: () => ROUTER_PLUGIN_NAME,
37
49
  getDefinition: () => ({
38
50
  create: createRouterPlugin
39
- })
51
+ }),
52
+ getDefaultOptions: defaultOptions
40
53
  };
41
54
  // Annotate the CommonJS export names for ESM import in node:
42
55
  0 && (module.exports = {
56
+ PLUGIN_NAME,
57
+ plugin,
43
58
  routerPlugin
44
59
  });
package/dist/index.d.cts CHANGED
@@ -1,17 +1,38 @@
1
1
  import { RouterOptions, Router } from 'vue-router';
2
- import { PluginControlOptions, PluginModule } from '@testforgejs/vue-test-core';
2
+ import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
3
+
4
+ /**
5
+ * Stable TestForge identifier for the managed Vue Router plugin.
6
+ *
7
+ * Use this identifier when declaring Router configuration
8
+ * in presets and other plugin-aware TestForge APIs.
9
+ */
10
+ declare const ROUTER_PLUGIN_NAME: "router";
3
11
 
4
12
  /**
5
13
  * Configuration options for the Vue Router test plugin.
6
14
  *
7
- * This interface integrates standard router initialization settings
8
- * and TestForge test kernel control options (such as `expose`).
15
+ * Combines standard Vue Router configuration (`RouterOptions` from `vue-router`)
16
+ * with TestForge plugin control options.
9
17
  *
10
- * @see {@link RouterOptions} from the `vue-router` package for configuring routes and history.
11
- * @see {@link PluginControlOptions} from the `@testforgejs/vue-test-core` package for instance interception.
18
+ * @example
19
+ * Configure the managed Vue Router plugin for a component test:
20
+ *
21
+ * ```ts
22
+ * factory({}, {
23
+ * plugins: {
24
+ * router: {
25
+ * history: createMemoryHistory(),
26
+ * routes: [],
27
+ * },
28
+ * },
29
+ * });
30
+ * ```
31
+ *
32
+ * @see `RouterOptions` from `vue-router` for configuring routes and history.
33
+ * @see `PluginControlOptions` from `@testforgejs/vue-test-core` for instance capturing and exposure mechanisms.
12
34
  */
13
- interface VueTestRouterOptions extends RouterOptions, PluginControlOptions<Router> {
14
- }
35
+ type VueTestRouterOptions = RouterOptions & PluginControlOptions<Router>;
15
36
 
16
37
  /**
17
38
  * Extending TestForge kernel types for Vue Router integration.
@@ -42,13 +63,16 @@ declare module "@testforgejs/vue-test-core" {
42
63
  * });
43
64
  * ```
44
65
  */
45
- router: VueTestRouterOptions;
66
+ [ROUTER_PLUGIN_NAME]: VueTestRouterOptions;
46
67
  }
47
68
  }
48
69
 
49
70
  /**
50
- * A Vue Router plugin module for the TestForge testing framework.
71
+ * Managed Vue Router plugin module for TestForge.
72
+ *
73
+ * Provides the runtime definition for creating Vue Router instances
74
+ * and exposes the default configuration used by TestForge-managed presets.
51
75
  */
52
- declare const routerPlugin: PluginModule<Router, VueTestRouterOptions>;
76
+ declare const routerPlugin: PluginModuleWithDefaults<Router, VueTestRouterOptions>;
53
77
 
54
- export { type VueTestRouterOptions, routerPlugin };
78
+ export { ROUTER_PLUGIN_NAME as PLUGIN_NAME, type VueTestRouterOptions, routerPlugin as plugin, routerPlugin };
package/dist/index.d.ts CHANGED
@@ -1,17 +1,38 @@
1
1
  import { RouterOptions, Router } from 'vue-router';
2
- import { PluginControlOptions, PluginModule } from '@testforgejs/vue-test-core';
2
+ import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
3
+
4
+ /**
5
+ * Stable TestForge identifier for the managed Vue Router plugin.
6
+ *
7
+ * Use this identifier when declaring Router configuration
8
+ * in presets and other plugin-aware TestForge APIs.
9
+ */
10
+ declare const ROUTER_PLUGIN_NAME: "router";
3
11
 
4
12
  /**
5
13
  * Configuration options for the Vue Router test plugin.
6
14
  *
7
- * This interface integrates standard router initialization settings
8
- * and TestForge test kernel control options (such as `expose`).
15
+ * Combines standard Vue Router configuration (`RouterOptions` from `vue-router`)
16
+ * with TestForge plugin control options.
9
17
  *
10
- * @see {@link RouterOptions} from the `vue-router` package for configuring routes and history.
11
- * @see {@link PluginControlOptions} from the `@testforgejs/vue-test-core` package for instance interception.
18
+ * @example
19
+ * Configure the managed Vue Router plugin for a component test:
20
+ *
21
+ * ```ts
22
+ * factory({}, {
23
+ * plugins: {
24
+ * router: {
25
+ * history: createMemoryHistory(),
26
+ * routes: [],
27
+ * },
28
+ * },
29
+ * });
30
+ * ```
31
+ *
32
+ * @see `RouterOptions` from `vue-router` for configuring routes and history.
33
+ * @see `PluginControlOptions` from `@testforgejs/vue-test-core` for instance capturing and exposure mechanisms.
12
34
  */
13
- interface VueTestRouterOptions extends RouterOptions, PluginControlOptions<Router> {
14
- }
35
+ type VueTestRouterOptions = RouterOptions & PluginControlOptions<Router>;
15
36
 
16
37
  /**
17
38
  * Extending TestForge kernel types for Vue Router integration.
@@ -42,13 +63,16 @@ declare module "@testforgejs/vue-test-core" {
42
63
  * });
43
64
  * ```
44
65
  */
45
- router: VueTestRouterOptions;
66
+ [ROUTER_PLUGIN_NAME]: VueTestRouterOptions;
46
67
  }
47
68
  }
48
69
 
49
70
  /**
50
- * A Vue Router plugin module for the TestForge testing framework.
71
+ * Managed Vue Router plugin module for TestForge.
72
+ *
73
+ * Provides the runtime definition for creating Vue Router instances
74
+ * and exposes the default configuration used by TestForge-managed presets.
51
75
  */
52
- declare const routerPlugin: PluginModule<Router, VueTestRouterOptions>;
76
+ declare const routerPlugin: PluginModuleWithDefaults<Router, VueTestRouterOptions>;
53
77
 
54
- export { type VueTestRouterOptions, routerPlugin };
78
+ export { ROUTER_PLUGIN_NAME as PLUGIN_NAME, type VueTestRouterOptions, routerPlugin as plugin, routerPlugin };
package/dist/index.js CHANGED
@@ -5,13 +5,26 @@ function createRouterPlugin(options) {
5
5
  return createPluginInstance(createRouter, options);
6
6
  }
7
7
 
8
+ // src/defaults.ts
9
+ import { createMemoryHistory } from "vue-router";
10
+ var defaultOptions = () => () => ({
11
+ history: createMemoryHistory(),
12
+ routes: []
13
+ });
14
+
15
+ // src/constants/constants.ts
16
+ var ROUTER_PLUGIN_NAME = "router";
17
+
8
18
  // src/module/routerPlugin.ts
9
19
  var routerPlugin = {
10
- getName: () => "router",
20
+ getName: () => ROUTER_PLUGIN_NAME,
11
21
  getDefinition: () => ({
12
22
  create: createRouterPlugin
13
- })
23
+ }),
24
+ getDefaultOptions: defaultOptions
14
25
  };
15
26
  export {
27
+ ROUTER_PLUGIN_NAME as PLUGIN_NAME,
28
+ routerPlugin as plugin,
16
29
  routerPlugin
17
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testforgejs/vue-test-plugin-router",
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 Vue Router integration in component tests",
6
6
  "homepage": "https://github.com/testforgejs/testforge#readme",
@@ -44,12 +44,18 @@
44
44
  "license": "MIT",
45
45
  "author": "Roman Levchenko",
46
46
  "peerDependencies": {
47
- "vue-router": ">=4.0.0 <6.0.0",
48
- "@testforgejs/vue-test-core": "1.0.0-beta.2"
47
+ "vue-router": "^4.0.0 || ^5.0.0",
48
+ "@testforgejs/vue-test-core": "1.0.0-beta.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "vue-router": "^5.0.0",
52
- "@testforgejs/vue-test-core": "1.0.0-beta.2"
52
+ "@testforgejs/vue-test-core": "1.0.0-beta.3"
53
+ },
54
+ "testforge": {
55
+ "plugin": {
56
+ "schemaVersion": 1,
57
+ "displayName": "Vue Router"
58
+ }
53
59
  },
54
60
  "scripts": {
55
61
  "build": "tsup",