@testforgejs/vue-test-plugin-router 1.0.0-beta.1 → 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 +156 -10
- package/dist/index.cjs +17 -2
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +15 -2
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @testforgejs/vue-test-plugin-router
|
|
2
2
|
|
|
3
|
-
|
|
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`
|
|
27
|
+
> `@testforgejs/vue-test-core` and `vue-router` 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
|
+
```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
|
-
|
|
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
|
-
|
|
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
|
-
`
|
|
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
|
|
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
|
-
|
|
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
|
|
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.
|
|
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: () =>
|
|
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,5 +1,7 @@
|
|
|
1
1
|
import { RouterOptions, Router } from 'vue-router';
|
|
2
|
-
import { PluginControlOptions,
|
|
2
|
+
import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
|
|
3
|
+
|
|
4
|
+
declare const ROUTER_PLUGIN_NAME: "router";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Configuration options for the Vue Router test plugin.
|
|
@@ -42,13 +44,13 @@ declare module "@testforgejs/vue-test-core" {
|
|
|
42
44
|
* });
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
|
|
47
|
+
[ROUTER_PLUGIN_NAME]: VueTestRouterOptions;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* A Vue Router plugin module for the TestForge testing framework.
|
|
51
53
|
*/
|
|
52
|
-
declare const routerPlugin:
|
|
54
|
+
declare const routerPlugin: PluginModuleWithDefaults<Router, VueTestRouterOptions>;
|
|
53
55
|
|
|
54
|
-
export { type VueTestRouterOptions, routerPlugin };
|
|
56
|
+
export { ROUTER_PLUGIN_NAME as PLUGIN_NAME, type VueTestRouterOptions, routerPlugin as plugin, routerPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { RouterOptions, Router } from 'vue-router';
|
|
2
|
-
import { PluginControlOptions,
|
|
2
|
+
import { PluginControlOptions, PluginModuleWithDefaults } from '@testforgejs/vue-test-core';
|
|
3
|
+
|
|
4
|
+
declare const ROUTER_PLUGIN_NAME: "router";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* Configuration options for the Vue Router test plugin.
|
|
@@ -42,13 +44,13 @@ declare module "@testforgejs/vue-test-core" {
|
|
|
42
44
|
* });
|
|
43
45
|
* ```
|
|
44
46
|
*/
|
|
45
|
-
|
|
47
|
+
[ROUTER_PLUGIN_NAME]: VueTestRouterOptions;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* A Vue Router plugin module for the TestForge testing framework.
|
|
51
53
|
*/
|
|
52
|
-
declare const routerPlugin:
|
|
54
|
+
declare const routerPlugin: PluginModuleWithDefaults<Router, VueTestRouterOptions>;
|
|
53
55
|
|
|
54
|
-
export { type VueTestRouterOptions, routerPlugin };
|
|
56
|
+
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: () =>
|
|
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.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
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": "
|
|
48
|
-
"@testforgejs/vue-test-core": "1.0.0-beta.
|
|
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.
|
|
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",
|