@webship-js/vue-steps 0.0.0-stage → 2.0.0
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/LICENSE +21 -0
- package/README.md +415 -2
- package/demo/app/app.vue +19 -0
- package/demo/app/pages/about.vue +10 -0
- package/demo/app/pages/client-only.vue +12 -0
- package/demo/app/pages/contact.vue +44 -0
- package/demo/app/pages/index.vue +15 -0
- package/demo/app/pages/posts/[id].vue +16 -0
- package/demo/app/pages/posts/index.vue +18 -0
- package/demo/app/pages/posts/latest.vue +11 -0
- package/demo/nuxt.config.ts +9 -0
- package/demo/server/api/contact.post.ts +19 -0
- package/demo/server/api/posts/[id].get.ts +8 -0
- package/demo/server/api/posts.get.ts +8 -0
- package/package.json +67 -4
- package/tests/features/errors.feature +14 -0
- package/tests/features/forms.feature +38 -0
- package/tests/features/page.feature +32 -0
- package/tests/features/views.feature +57 -0
- package/tests/step-definitions/vue-errors.steps.js +51 -0
- package/tests/step-definitions/vue-forms.steps.js +171 -0
- package/tests/step-definitions/vue-helpers.js +294 -0
- package/tests/step-definitions/vue-page.steps.js +109 -0
- package/tests/step-definitions/vue-probe.js +305 -0
- package/tests/step-definitions/vue-views.steps.js +211 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Webship.co
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,416 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/webship/vue-steps/2.0.x/assets/logo.svg" alt="Vue logo" width="96"></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# vue-steps
|
|
4
|
+
|
|
5
|
+
Cucumber step definitions for Vue apps, Nuxt first, for [webship-js](https://webship.co/docs/webship-js/2.0.x), a BDD
|
|
6
|
+
browser automation harness built on Playwright and Cucumber-js.
|
|
7
|
+
|
|
8
|
+
A Nuxt page arrives as the server's HTML; the app's scripts then wire it up in the browser (hydration). Until they
|
|
9
|
+
have, the page's links load whole pages and its buttons do nothing yet. After that, the app changes its views inside
|
|
10
|
+
the page, fetches each view's data during the navigation, sends a form in place, and shows its error page when a view
|
|
11
|
+
fails. The steps wait for each of those to end, on the app's own signals, never for a fixed time:
|
|
12
|
+
|
|
13
|
+
- the app's own state: Nuxt no longer hydrating (`useNuxtApp().isHydrating`), or a Vue app mounted;
|
|
14
|
+
- its router's navigations: Nuxt's `page:loading:start` and `page:loading:end`, or Vue Router's guards in an app
|
|
15
|
+
without Nuxt;
|
|
16
|
+
- the document: a change of view keeps it, a whole page load brings a new one (told apart without counting on a
|
|
17
|
+
request: the app fetches a view's code ahead for the links on the screen);
|
|
18
|
+
- the requests in flight (a view's data, a form sent in place), the frames asked for and the animations and
|
|
19
|
+
transitions running.
|
|
20
|
+
|
|
21
|
+
The same steps run in a browser with JavaScript and in one without: a form's step waits for the answer of the request
|
|
22
|
+
the app sends in place in the one, and for the page the posted form loads in the other.
|
|
23
|
+
|
|
24
|
+
No step phrase names the framework: a scenario reads `When I use the "Posts" link`, `When I send the form with the
|
|
25
|
+
"Send" button` and `Then the form should have been turned down with "…"`.
|
|
26
|
+
|
|
27
|
+
CI makes the demo (Nuxt's official starter with the pages of [`demo/`](demo/)), builds it, serves it with its own
|
|
28
|
+
server, and runs the whole suite against it twice in a browser with JavaScript and twice in one without, then the
|
|
29
|
+
assertions that must fail in each; see [`.github/workflows/test.yml`](.github/workflows/test.yml).
|
|
30
|
+
|
|
31
|
+
## Wiring the page up
|
|
32
|
+
|
|
33
|
+
A page with a Vue app is waited on until the app has wired it up: Nuxt's own flag (`isHydrating` turning false), or,
|
|
34
|
+
in an app without Nuxt, the mount of the app (Vue marks the element it mounts in the browser `data-v-app`; an app
|
|
35
|
+
rendered on the server and hydrated keeps only its element's own app, which the steps read too). Every step that acts (using a link,
|
|
36
|
+
sending a form) waits for it first, as a click before then loads a whole page; `Given the page is wired up` waits for
|
|
37
|
+
it on purpose. A page without an app, and every page in a browser without JavaScript, have nothing to wait for: the
|
|
38
|
+
steps go on, and say so in the run's log.
|
|
39
|
+
|
|
40
|
+
A view Nuxt draws in the browser only (`routeRules: { '/client-only': { ssr: false } }`) arrives as an empty element:
|
|
41
|
+
`Then the page should have been drawn in the browser only` says so, and without JavaScript such a page stays empty.
|
|
42
|
+
|
|
43
|
+
## From nothing to a green run
|
|
44
|
+
|
|
45
|
+
What the machine needs: git, Node.js 24 or later with npm, and Docker to make and serve the demo (or a Nuxt app that
|
|
46
|
+
is built and served already).
|
|
47
|
+
|
|
48
|
+
**1. An app.** Any Nuxt app works (step 5 points the suite at it). To start, make the demo with this repository's
|
|
49
|
+
script: it runs Nuxt's create tool (`nuxi init --template minimal`), puts the pages of `demo/` over the starter, and
|
|
50
|
+
builds it, in a Node.js container; then serve it with its own server:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
git clone https://github.com/webship/vue-steps.git
|
|
54
|
+
cd vue-steps
|
|
55
|
+
npm run demo:build
|
|
56
|
+
npm run demo:serve
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The demo answers at `http://127.0.0.1:3000`: a home page with a counter, an about page, posts loaded from the server,
|
|
60
|
+
a contact form, and a page drawn in the browser only. Leave the server running in its own terminal. It has no
|
|
61
|
+
accounts: the steps need none.
|
|
62
|
+
|
|
63
|
+
**2. A test project**, in another folder:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
mkdir vue-tests && cd vue-tests
|
|
67
|
+
npm init -y
|
|
68
|
+
npm install --save-dev webship-js @webship-js/vue-steps
|
|
69
|
+
npx init-webship-js
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`npx init-webship-js` writes `cucumber.js`, `playwright.config.ts`, the `tests/` folders with a first feature and the
|
|
73
|
+
`npm test` scripts, and installs Chromium.
|
|
74
|
+
|
|
75
|
+
**3. `cucumber.js`.** Replace the file with the wiring of the pack: the step files of webship-js and of the pack, the
|
|
76
|
+
tags that keep the lanes of this repository out of a normal run, and the address of the app.
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
module.exports = {
|
|
80
|
+
default: {
|
|
81
|
+
requireModule: ['tsx/cjs'],
|
|
82
|
+
require: [
|
|
83
|
+
'node_modules/webship-js/tests/step-definitions/**/*.js',
|
|
84
|
+
'node_modules/@webship-js/vue-steps/tests/step-definitions/*.js',
|
|
85
|
+
'tests/step-definitions/**/*.js',
|
|
86
|
+
],
|
|
87
|
+
paths: ['tests/features/**/*.feature'],
|
|
88
|
+
// Work in progress, the assertions that must fail and the scenarios of a browser without JavaScript stay out.
|
|
89
|
+
tags: 'not @wip and not @must-fail and not @no-javascript',
|
|
90
|
+
format: ['@cucumber/pretty-formatter', 'json:tests/reports/cucumber_report.json'],
|
|
91
|
+
worldParameters: {
|
|
92
|
+
launchUrl: process.env.LAUNCH_URL || 'http://127.0.0.1:3000',
|
|
93
|
+
// Browser errors are reported, not failed: a form turned down shows one ("Failed to load resource: 422").
|
|
94
|
+
javascript: { mode: 'warn', levels: ['error'] },
|
|
95
|
+
// The waits webship-js adds around each page, scenario and step (milliseconds).
|
|
96
|
+
minWaitTime: { page: 3000, before_scenario: 0, after_scenario: 0, before_step: 0, after_step: 0 },
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**4. A first feature**, `tests/features/first-run.feature`:
|
|
103
|
+
|
|
104
|
+
```gherkin
|
|
105
|
+
Feature: First run
|
|
106
|
+
Scenario: A link changes the view in place, and the new view is announced
|
|
107
|
+
Given I am on "/"
|
|
108
|
+
When I use the "Posts" link
|
|
109
|
+
Then the view should have changed in place
|
|
110
|
+
And the new view should be announced as "Posts"
|
|
111
|
+
|
|
112
|
+
Scenario: A message too short is turned down
|
|
113
|
+
Given I am on "/contact"
|
|
114
|
+
When I fill in "Your name" with "Ada"
|
|
115
|
+
And I fill in "Your message" with "Too short"
|
|
116
|
+
And I send the form with the "Send" button
|
|
117
|
+
Then the form should have been turned down with "Your message needs at least 10 characters."
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**5. Run it.** Set `LAUNCH_URL` to the address of the app:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
LAUNCH_URL=http://127.0.0.1:3000 npm test
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
A green first run prints every step, the browser error of the refused message (reported, not failed:
|
|
127
|
+
`mode: 'warn'`), then the summary (the starter feature of `npx init-webship-js` and the two scenarios above, passed)
|
|
128
|
+
and the HTML report it wrote:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
[webship-js] JavaScript errors during "A message too short is turned down" (mode=warn):
|
|
132
|
+
1. [console.error] Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)
|
|
133
|
+
|
|
134
|
+
3 scenarios (3 passed)
|
|
135
|
+
11 steps (11 passed)
|
|
136
|
+
0m03.272s (executing steps: 0m03.238s)
|
|
137
|
+
[webship-js] HTML report → …/vue-tests/tests/reports/cucumber_report.html
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
From there, copy the features of [`tests/features/`](tests/features/) (they also ship in the package, under
|
|
141
|
+
`node_modules/@webship-js/vue-steps/tests/features/`): together they use every step of the pack, against the demo.
|
|
142
|
+
|
|
143
|
+
### On an app of your own
|
|
144
|
+
|
|
145
|
+
Point `LAUNCH_URL` at the address the app is served at, and write the features from what its pages show: links and
|
|
146
|
+
buttons by the names a person reads, forms by their buttons, views by their titles and addresses.
|
|
147
|
+
|
|
148
|
+
- **A browser without JavaScript:** set `javaScriptEnabled: false` in `contextOptions` of `playwright.config.ts`
|
|
149
|
+
(this repository does it from `JAVASCRIPT=off`) and run the scenarios that hold without it. The same steps wait
|
|
150
|
+
for whole page loads there.
|
|
151
|
+
- **webship-js's own steps** (`I press "…"`, `I click "…"`) do not wait for the app. Tag a scenario
|
|
152
|
+
`@still-after-steps`, and after each of its steps the pack waits for the page to be still, on a page with an app;
|
|
153
|
+
or follow such a step with `When I wait for the page to be still`.
|
|
154
|
+
- **The route announcer** is Nuxt's `<NuxtRouteAnnouncer />`, which the starter's `app.vue` renders. An app without it
|
|
155
|
+
has no announcer, and `the new view should be announced as "…"` says so.
|
|
156
|
+
|
|
157
|
+
### What the suite tests
|
|
158
|
+
|
|
159
|
+
The features of this repository run every step of the pack against the demo, in CI on every change, in a browser with
|
|
160
|
+
JavaScript and in one without:
|
|
161
|
+
|
|
162
|
+
- the app wiring the page up, a page drawn in the browser only, and a count that changes in place;
|
|
163
|
+
- views: a link that changes the view in place, the announcement of the new view's title, the link of the current
|
|
164
|
+
view, the view's address, a view with data of its own and the browser's back, data loaded again, a link whose view
|
|
165
|
+
the app redirects, and the new pages a browser without JavaScript loads;
|
|
166
|
+
- the contact form: a message taken, one turned down with its message, sent in place with JavaScript and leading to a
|
|
167
|
+
new page without it;
|
|
168
|
+
- the error pages of a missing post and of an address the app does not know.
|
|
169
|
+
|
|
170
|
+
Not tested: layouts of the app's own, middleware other than a redirect, server components and islands, lazy
|
|
171
|
+
hydration, and the development server.
|
|
172
|
+
|
|
173
|
+
## Requirements
|
|
174
|
+
|
|
175
|
+
- Node.js 24 or later
|
|
176
|
+
- A webship-js 2.0 test project, webship-js 2.0.18 or later
|
|
177
|
+
- A Nuxt app, built and served (proven on Nuxt 4.7 with Vue 3.5 and Vue Router 5.5); or a Vue app mounted in the
|
|
178
|
+
browser, for the steps that do not need Nuxt's own signals
|
|
179
|
+
|
|
180
|
+
## Install
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
npm install --save-dev @webship-js/vue-steps
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Quick start
|
|
187
|
+
|
|
188
|
+
1. Add the step files to the `require` list of your webship-js `cucumber.js`, after webship-js's own:
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
require: [
|
|
192
|
+
'node_modules/webship-js/tests/step-definitions/**/*.js',
|
|
193
|
+
'node_modules/@webship-js/vue-steps/tests/step-definitions/*.js',
|
|
194
|
+
'tests/step-definitions/**/*.js',
|
|
195
|
+
],
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
2. Point `launchUrl` at the app:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
worldParameters: {
|
|
202
|
+
launchUrl: process.env.LAUNCH_URL || 'https://app.example.com',
|
|
203
|
+
},
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
3. Write a feature from what the app shows:
|
|
207
|
+
|
|
208
|
+
```gherkin
|
|
209
|
+
Feature: Signing in
|
|
210
|
+
Scenario: A wrong password is turned down
|
|
211
|
+
Given I am on "/login"
|
|
212
|
+
When I fill in "Email" with "ada@example.com"
|
|
213
|
+
And I fill in "Password" with "wrong"
|
|
214
|
+
And I send the form with the "Log in" button
|
|
215
|
+
Then the form should have been turned down with "Wrong email or password"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Run `npx cucumber-js --dry-run` once: it reports any undefined or ambiguous step before a browser opens.
|
|
219
|
+
|
|
220
|
+
## Test users
|
|
221
|
+
|
|
222
|
+
None. The demo has no sign-in, and the steps need no account (an app's own sign-in form is sent with the steps of the
|
|
223
|
+
pack, like any other form). `cucumber.js` lists no accounts and no scenario signs in:
|
|
224
|
+
|
|
225
|
+
```json
|
|
226
|
+
{}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## What is included
|
|
230
|
+
|
|
231
|
+
| File | Steps | Covers |
|
|
232
|
+
| --- | --- | --- |
|
|
233
|
+
| `vue-page.steps.js` | 4 | The app wiring the page up (waited for, or asserted), a page drawn in the browser only, and the wait for the page to be still; the opt-in `@still-after-steps`. |
|
|
234
|
+
| `vue-views.steps.js` | 7 | A link used and the browser's back, each to its end; how the last navigation ended (in place, or a new page); the announcement of the new view; the link of the current view; the view's address; the wait for a view's data. |
|
|
235
|
+
| `vue-forms.steps.js` | 4 | A form sent with a button, in either mode; whether it went through, or was turned down and why; how it was sent. |
|
|
236
|
+
| `vue-errors.steps.js` | 1 | An error page: its status, its first heading and its message. |
|
|
237
|
+
| `vue-helpers.js` | | Shared plumbing for the files above and for your own steps: the wait budgets, the poll on the page, the app wiring the page up, the page being still, following a navigation to its end, finding a link or a button by its name, the failure messages (which name the lane without JavaScript). It registers no step. |
|
|
238
|
+
| `vue-probe.js` | | The page side: put into every page before its own scripts, it keeps an id for each document, the frames the page asks for, its requests in flight, its inputs and changes, whether the server's HTML held the page, and, once the app has wired the page up, the navigations of its router. It registers no step. |
|
|
239
|
+
| `demo/` | | The pages of the demo app (MIT, this pack's own), put over Nuxt's starter by `.github/scripts/build-demo.sh`; the Webship Workspace's plugin builds the same demo from them. |
|
|
240
|
+
|
|
241
|
+
webship-js's own steps still go to an address (`Given I am on "/posts"`), read the page (`I should see "…"`), fill in
|
|
242
|
+
fields and press keys: this pack adds the app's own views, its forms and their waits.
|
|
243
|
+
|
|
244
|
+
## How the steps find things and wait
|
|
245
|
+
|
|
246
|
+
- **By the name a person reads.** A link or a button by its accessible name (its text, or its label), as Playwright
|
|
247
|
+
computes it: exactly, then without regard to case, then by its start (three characters or more); never a part in
|
|
248
|
+
the middle. A form's button among the buttons of the page's forms.
|
|
249
|
+
- **Wired up first.** Every step that acts waits for the app to wire the page up, when the page has an app and the
|
|
250
|
+
browser runs JavaScript.
|
|
251
|
+
- **A navigation to its end, never by a request.** In place: the app's router started and ended its navigation
|
|
252
|
+
(Nuxt's `page:loading:start` and `page:loading:end`), the announcer, when there is one, holds the new title, and
|
|
253
|
+
the page is still. A whole page: a new document has loaded and, when it can be, been wired up.
|
|
254
|
+
- **A form in either mode.** After the click, whichever comes first: the request the app sends in place (its answer,
|
|
255
|
+
then the page still), or a page load (through the server's redirects). A button the app handles in the page,
|
|
256
|
+
sending nothing, ends when the page is still. A form went through when its answer is not a refusal and the page
|
|
257
|
+
shows no alert; it was turned down when its answer is a 4xx or the page shows an alert (`role="alert"`).
|
|
258
|
+
- **Still:** no page load, no request in flight, no navigation of the app in progress, no frame asked for, no finite
|
|
259
|
+
animation or transition running, the page wired up when it can be, and 40 ms of quiet with a frame after the last
|
|
260
|
+
input (or 100 ms of nothing).
|
|
261
|
+
- **Then steps wait for what they expect,** up to the step's budget (`minWaitTime.page`, at least 10 seconds), looking
|
|
262
|
+
every 50 milliseconds from Node.js.
|
|
263
|
+
- **Failures say what was found,** and a failure in a browser without JavaScript says so: `Expected the page to be
|
|
264
|
+
wired up, but the browser has JavaScript off.`
|
|
265
|
+
|
|
266
|
+
### Notes on waits
|
|
267
|
+
|
|
268
|
+
What the app does that a test must wait past, found by recording it in a real browser:
|
|
269
|
+
|
|
270
|
+
- **Wired up in one frame.** Nuxt's flag turns false, the app's element gets its Vue app and the route announcer
|
|
271
|
+
appears together, a few tens of milliseconds after the page has loaded. The announcer is not in the server's HTML.
|
|
272
|
+
- **The announcer follows the page's title, not the navigation.** Nuxt's announcer says `document.title` each time the
|
|
273
|
+
page's head is rendered, on the first load too, and the title changes a few milliseconds after the router's
|
|
274
|
+
`page:loading:end`. The steps read it once the navigation has ended, never as its end.
|
|
275
|
+
- **A view's data is fetched during the navigation**, before the new view is shown and announced. A view's code is
|
|
276
|
+
fetched ahead for the links on the screen, so a click often sends no request at all.
|
|
277
|
+
- **The focus stays where it was.** After a change of view the focus stays on the link that was clicked, or goes to the
|
|
278
|
+
page when that link is gone: the app does not move it.
|
|
279
|
+
- **An error page has no announcer.** Nuxt's error page is drawn without the app's own layout (`app.vue`), so the
|
|
280
|
+
announcer is not there.
|
|
281
|
+
- **A redirect is one navigation of several addresses.** When a route middleware sends an address on to another, the
|
|
282
|
+
router runs its guards again for the new one, and Nuxt calls `page:loading:start` for each address but
|
|
283
|
+
`page:loading:end` once, when the last has loaded. The steps count the addresses the router marks as redirected
|
|
284
|
+
(`redirectedFrom`) as part of the navigation they belong to, and with Vue Router alone they count them once.
|
|
285
|
+
|
|
286
|
+
### Findings
|
|
287
|
+
|
|
288
|
+
Found while writing the steps; not reported upstream yet (the owner decides).
|
|
289
|
+
|
|
290
|
+
- **A stale announcement on an error page reached inside the app.** A missing post reached inside the app (a
|
|
291
|
+
navigation whose view throws a 404) shows Nuxt's error page in the same document, while the route announcer still
|
|
292
|
+
says the title of an earlier view ("Home"), not the error's. Loaded directly, the error page has no announcer at all.
|
|
293
|
+
|
|
294
|
+
## Steps
|
|
295
|
+
|
|
296
|
+
One example of each step; the JSDoc block above each definition holds five.
|
|
297
|
+
|
|
298
|
+
### `vue-page.steps.js` (4)
|
|
299
|
+
|
|
300
|
+
- `Given the page is wired up`
|
|
301
|
+
- `Then the page should be wired up`
|
|
302
|
+
- `Then the page should have been drawn in the browser only`
|
|
303
|
+
- `When I wait for the page to be still`
|
|
304
|
+
|
|
305
|
+
### `vue-views.steps.js` (7)
|
|
306
|
+
|
|
307
|
+
- `When I use the "Posts" link`
|
|
308
|
+
- `When I return to the previous view`
|
|
309
|
+
- `Then the view should have changed in place`
|
|
310
|
+
- `Then the new view should be announced as "Posts"`
|
|
311
|
+
- `Then the "Posts" link should be marked current`
|
|
312
|
+
- `Then the view's address should be "/posts"`
|
|
313
|
+
- `When I wait for the view's data to arrive`
|
|
314
|
+
|
|
315
|
+
### `vue-forms.steps.js` (4)
|
|
316
|
+
|
|
317
|
+
- `When I send the form with the "Send" button`
|
|
318
|
+
- `Then the form should have gone through`
|
|
319
|
+
- `Then the form should have been turned down with "Your message needs at least 10 characters."`
|
|
320
|
+
- `Then the form should have been sent in place`
|
|
321
|
+
|
|
322
|
+
### `vue-errors.steps.js` (1)
|
|
323
|
+
|
|
324
|
+
- `Then the view should be the 404 error page`
|
|
325
|
+
|
|
326
|
+
## Phrases shared with other packs
|
|
327
|
+
|
|
328
|
+
None of this pack's phrases matches one of webship-js (`npm run test:examples` checks it), nor one of the 57 step packs
|
|
329
|
+
published so far, and none of their examples matches one of this pack's steps. The Svelte and Next.js packs speak of
|
|
330
|
+
the same things in words of their own ("taken over the page", "follow the … link in the app", "without a full page
|
|
331
|
+
reload"), so the pack loads beside any of them.
|
|
332
|
+
|
|
333
|
+
## Nuxt's own tests and this pack
|
|
334
|
+
|
|
335
|
+
Nuxt's own suite (`test/basic.test.ts` and `test/e2e`, MIT) builds its test apps and drives them with Playwright,
|
|
336
|
+
waiting for a page with `useNuxtApp()._route` and `isHydrating`, as this pack does. Its groups, and the features that
|
|
337
|
+
cover the same ground on a real app:
|
|
338
|
+
|
|
339
|
+
| Nuxt's own suite | In this pack |
|
|
340
|
+
| --- | --- |
|
|
341
|
+
| `pages`: rendering a route, and moving between routes | `views.feature`: a link that changes the view in place, the view's address, the browser's back |
|
|
342
|
+
| `nuxt links`: `aria-current`, the active classes, prefetching | `views.feature`: the link of the current view; the steps never count on a prefetch request |
|
|
343
|
+
| `errors`: the error page, `createError`, a status mapped to the response | `errors.feature`: a missing post and an unknown address, their status and message |
|
|
344
|
+
| `composables`: `useFetch`, refreshing data | `views.feature`: a view with data of its own, and data loaded again |
|
|
345
|
+
| route rules: `ssr: false` | `page.feature`: a page drawn in the browser only |
|
|
346
|
+
|
|
347
|
+
Not in this pack: middleware and layouts, islands and server components, lazy hydration, and the development server.
|
|
348
|
+
|
|
349
|
+
## Testing this package
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
npm install
|
|
353
|
+
npm run demo:build # the demo: Nuxt's starter and the pages of demo/, made and built in a Node.js container, in demo-app/
|
|
354
|
+
npm run demo:serve & # served at http://127.0.0.1:3000
|
|
355
|
+
npm run test:examples # the examples and the features against the step patterns
|
|
356
|
+
npm run test:paths # a feature or a scenario named on the command line runs alone
|
|
357
|
+
npx cucumber-js --dry-run # no undefined and no ambiguous step
|
|
358
|
+
LAUNCH_URL=http://127.0.0.1:3000 npm test # the suite, with JavaScript
|
|
359
|
+
LAUNCH_URL=http://127.0.0.1:3000 npm run test:must-fail # assertions that must fail, each with its message
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
The lane without JavaScript:
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
JAVASCRIPT=off CUCUMBER_TAGS='not @wip and not @must-fail and not @needs-javascript' LAUNCH_URL=http://127.0.0.1:3000 npm test
|
|
366
|
+
JAVASCRIPT=off MUST_FAIL_TAGS='@must-fail and not @needs-javascript' LAUNCH_URL=http://127.0.0.1:3000 npm run test:must-fail
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
The tags: `@needs-javascript` runs only with JavaScript, `@no-javascript` only without (not `@javascript`, which
|
|
370
|
+
webship-js reads as "fail the scenario on any browser error"). In CI each lane names its reports
|
|
371
|
+
(`cucumber_report-javascript-off.json`, `must-fail-javascript-off.json`), so a failure of one is never read as the
|
|
372
|
+
other's.
|
|
373
|
+
|
|
374
|
+
`tests/must-fail/` holds scenarios that assert something that is not true of the demo. `npm run test:must-fail` runs
|
|
375
|
+
them and checks that each one fails at its last step, with the message it announces and a hint: a step that cannot
|
|
376
|
+
fail proves nothing. It runs them with a wait of 3 seconds (`COMPONENT_WAIT_MS`), since each of them waits its whole
|
|
377
|
+
budget.
|
|
378
|
+
|
|
379
|
+
`LAUNCH_URL` points the suite at another address; `npx cucumber-js tests/features/forms.feature` runs one feature;
|
|
380
|
+
`FEATURES` runs a subset too; `CUCUMBER_TAGS=@critical` runs the smoke lane; `HEADLESS=false` shows the browser.
|
|
381
|
+
|
|
382
|
+
The suite leaves the demo as it found it: the demo keeps nothing (the contact form only answers).
|
|
383
|
+
|
|
384
|
+
## The demo
|
|
385
|
+
|
|
386
|
+
The demo is made, not kept as a whole in this repository. [`.github/scripts/build-demo.sh`](.github/scripts/build-demo.sh)
|
|
387
|
+
runs Nuxt's create tool, `nuxi init --template minimal` (nuxi 4.1.0), puts the pages of [`demo/`](demo/) over the
|
|
388
|
+
starter, and runs `npm install` and `npm run build`, in a Node.js 24 container pinned by its digest, into `demo-app/`;
|
|
389
|
+
[`.github/scripts/serve-demo.sh`](.github/scripts/serve-demo.sh) serves the build with its own server
|
|
390
|
+
(`node .output/server/index.mjs`).
|
|
391
|
+
|
|
392
|
+
- The starter is Nuxt's own, released under the MIT licence by the Nuxt team (https://github.com/nuxt/starter): it is
|
|
393
|
+
made at each build, and nothing of it is in this repository.
|
|
394
|
+
- The pages of `demo/` are this pack's own (MIT): a home page with a counter, an about page, posts from a server route
|
|
395
|
+
(`useFetch`, `refresh()`, `createError` for a missing post, and a route middleware that sends `/posts/latest` on to
|
|
396
|
+
the latest post), a contact form that works without JavaScript and is sent in place with it, and a page drawn in
|
|
397
|
+
the browser only.
|
|
398
|
+
- Nuxt's own suite and its examples (MIT) were read, to learn what the framework does that a test must wait for;
|
|
399
|
+
nothing of them is in this repository.
|
|
400
|
+
|
|
401
|
+
## How the steps were written
|
|
402
|
+
|
|
403
|
+
Everything a step relies on was seen in a real browser first, on the built demo: when the app wires a page up and what
|
|
404
|
+
it renders then, what a change of view and a whole page load each change, the order of the router's hooks, the
|
|
405
|
+
requests of a view and of a form with JavaScript and without, the announcer's text and when it changes, where the
|
|
406
|
+
keyboard focus goes. The steps were written from that, and are proven on Nuxt 4.7 with Vue 3.5 and Vue Router 5.5, in
|
|
407
|
+
English, with Chromium, with JavaScript and without.
|
|
408
|
+
|
|
409
|
+
## License
|
|
410
|
+
|
|
411
|
+
MIT (see `LICENSE`).
|
|
412
|
+
|
|
413
|
+
## Logo
|
|
414
|
+
|
|
415
|
+
The Vue logo is the Vue team's, designed by Evan You, from github.com/vuejs/art, under CC BY-NC-SA 4.0
|
|
416
|
+
(https://creativecommons.org/licenses/by-nc-sa/4.0/). It is not covered by this package's MIT licence.
|
package/demo/app/app.vue
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<NuxtRouteAnnouncer />
|
|
4
|
+
<header>
|
|
5
|
+
<nav aria-label="Main">
|
|
6
|
+
<ul>
|
|
7
|
+
<li><NuxtLink to="/">Home</NuxtLink></li>
|
|
8
|
+
<li><NuxtLink to="/about">About</NuxtLink></li>
|
|
9
|
+
<li><NuxtLink to="/posts">Posts</NuxtLink></li>
|
|
10
|
+
<li><NuxtLink to="/contact">Contact</NuxtLink></li>
|
|
11
|
+
<li><NuxtLink to="/client-only">Client only</NuxtLink></li>
|
|
12
|
+
</ul>
|
|
13
|
+
</nav>
|
|
14
|
+
</header>
|
|
15
|
+
<main>
|
|
16
|
+
<NuxtPage />
|
|
17
|
+
</main>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
useHead({ title: 'About' })
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<template>
|
|
6
|
+
<section>
|
|
7
|
+
<h1>About this demo</h1>
|
|
8
|
+
<p>The pages of this app are written for the tests of a step pack; the app itself is the official starter.</p>
|
|
9
|
+
</section>
|
|
10
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
useHead({ title: 'Client only' })
|
|
3
|
+
const now = ref('')
|
|
4
|
+
onMounted(() => { now.value = 'rendered in the browser' })
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<template>
|
|
8
|
+
<section>
|
|
9
|
+
<h1>Client only</h1>
|
|
10
|
+
<p>This page is <span id="where">{{ now }}</span>.</p>
|
|
11
|
+
</section>
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The form works without JavaScript (posted to the server route, which sends the page back with the answer in its
|
|
3
|
+
// address) and, once the app has taken the page over, is sent inside the page.
|
|
4
|
+
useHead({ title: 'Contact' })
|
|
5
|
+
const route = useRoute()
|
|
6
|
+
const name = ref('')
|
|
7
|
+
const message = ref('')
|
|
8
|
+
const sent = ref(typeof route.query.sent === 'string' ? route.query.sent : '')
|
|
9
|
+
const error = ref(typeof route.query.error === 'string' ? route.query.error : '')
|
|
10
|
+
const sending = ref(false)
|
|
11
|
+
|
|
12
|
+
async function send() {
|
|
13
|
+
sending.value = true
|
|
14
|
+
error.value = ''
|
|
15
|
+
sent.value = ''
|
|
16
|
+
try {
|
|
17
|
+
const answer = await $fetch<{ ok: boolean, name: string }>('/api/contact', { method: 'POST', body: { name: name.value, message: message.value } })
|
|
18
|
+
sent.value = answer.name
|
|
19
|
+
} catch (e: any) {
|
|
20
|
+
error.value = (e && e.data && e.data.error) || 'The message could not be sent.'
|
|
21
|
+
} finally {
|
|
22
|
+
sending.value = false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<section>
|
|
29
|
+
<h1>Contact</h1>
|
|
30
|
+
<form method="post" action="/api/contact" @submit.prevent="send">
|
|
31
|
+
<p>
|
|
32
|
+
<label for="name">Your name</label>
|
|
33
|
+
<input id="name" v-model="name" name="name" type="text">
|
|
34
|
+
</p>
|
|
35
|
+
<p>
|
|
36
|
+
<label for="message">Your message</label>
|
|
37
|
+
<textarea id="message" v-model="message" name="message" />
|
|
38
|
+
</p>
|
|
39
|
+
<button type="submit" :disabled="sending">Send</button>
|
|
40
|
+
</form>
|
|
41
|
+
<p v-if="sent" role="status">Thanks, {{ sent }}: your message was sent.</p>
|
|
42
|
+
<p v-if="error" role="alert">{{ error }}</p>
|
|
43
|
+
</section>
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
useHead({ title: 'Home' })
|
|
3
|
+
const count = ref(0)
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<section>
|
|
8
|
+
<h1>Welcome to the demo</h1>
|
|
9
|
+
<p>A Nuxt app with pages of its own: posts loaded from the server, a contact form, and a page rendered in the browser only.</p>
|
|
10
|
+
<p>
|
|
11
|
+
<button type="button" aria-label="Add one to the count" @click="count++">+1</button>
|
|
12
|
+
<span>Count: <strong id="count">{{ count }}</strong></span>
|
|
13
|
+
</p>
|
|
14
|
+
</section>
|
|
15
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
const route = useRoute()
|
|
3
|
+
const { data: post, error } = await useFetch(`/api/posts/${route.params.id}`)
|
|
4
|
+
if (error.value) {
|
|
5
|
+
throw createError({ statusCode: error.value.statusCode || 404, statusMessage: 'Post not found', fatal: true })
|
|
6
|
+
}
|
|
7
|
+
useHead({ title: () => post.value?.title || 'Post' })
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<article v-if="post">
|
|
12
|
+
<h1>{{ post.title }}</h1>
|
|
13
|
+
<p>{{ post.body }}</p>
|
|
14
|
+
<p><NuxtLink to="/posts">All posts</NuxtLink></p>
|
|
15
|
+
</article>
|
|
16
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
useHead({ title: 'Posts' })
|
|
3
|
+
const { data: posts, refresh, status } = await useFetch('/api/posts')
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<section>
|
|
8
|
+
<h1>Posts</h1>
|
|
9
|
+
<ul>
|
|
10
|
+
<li v-for="post in posts" :key="post.id">
|
|
11
|
+
<NuxtLink :to="`/posts/${post.id}`">{{ post.title }}</NuxtLink>
|
|
12
|
+
</li>
|
|
13
|
+
</ul>
|
|
14
|
+
<p><NuxtLink to="/posts/latest">The latest post</NuxtLink></p>
|
|
15
|
+
<button type="button" @click="refresh()">Load the posts again</button>
|
|
16
|
+
<p>Status: <span id="status">{{ status }}</span></p>
|
|
17
|
+
</section>
|
|
18
|
+
</template>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The latest post has no address of its own: a route middleware sends /posts/latest on to it. Inside the app the
|
|
3
|
+
// router follows the redirect; without JavaScript the server answers it with a redirect.
|
|
4
|
+
definePageMeta({
|
|
5
|
+
middleware: () => navigateTo('/posts/3'),
|
|
6
|
+
})
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<p>Taking you to the latest post.</p>
|
|
11
|
+
</template>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// https://nuxt.com/docs/api/configuration/nuxt-config
|
|
2
|
+
export default defineNuxtConfig({
|
|
3
|
+
compatibilityDate: '2025-07-15',
|
|
4
|
+
devtools: { enabled: false },
|
|
5
|
+
// One page rendered in the browser only: the server sends the app's shell, and nothing of the page.
|
|
6
|
+
routeRules: {
|
|
7
|
+
'/client-only': { ssr: false },
|
|
8
|
+
},
|
|
9
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The contact form: JSON from the page's own fetch, or a form posted without JavaScript, which is sent back to the
|
|
2
|
+
// page with the answer in its address.
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const type = getRequestHeader(event, 'content-type') || ''
|
|
5
|
+
const fromForm = type.includes('application/x-www-form-urlencoded')
|
|
6
|
+
const body = fromForm ? await readFormData(event).then((f) => Object.fromEntries(f)) : await readBody(event)
|
|
7
|
+
const name = String((body && body.name) || '').trim()
|
|
8
|
+
const message = String((body && body.message) || '').trim()
|
|
9
|
+
const error = !name ? 'Your name is required.' : (message.length < 10 ? 'Your message needs at least 10 characters.' : '')
|
|
10
|
+
if (fromForm) {
|
|
11
|
+
const query = error ? `error=${encodeURIComponent(error)}` : `sent=${encodeURIComponent(name)}`
|
|
12
|
+
return sendRedirect(event, `/contact?${query}`, 303)
|
|
13
|
+
}
|
|
14
|
+
if (error) {
|
|
15
|
+
setResponseStatus(event, 422)
|
|
16
|
+
return { error }
|
|
17
|
+
}
|
|
18
|
+
return { ok: true, name }
|
|
19
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { POSTS } from '../posts.get'
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler((event) => {
|
|
4
|
+
const id = Number(getRouterParam(event, 'id'))
|
|
5
|
+
const post = POSTS.find((p) => p.id === id)
|
|
6
|
+
if (!post) throw createError({ statusCode: 404, statusMessage: 'Post not found' })
|
|
7
|
+
return post
|
|
8
|
+
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The posts of the demo, kept in the server's code: a list for /posts and one post for /posts/<id>.
|
|
2
|
+
export const POSTS = [
|
|
3
|
+
{ id: 1, title: 'First steps', body: 'A page loaded from the server, then taken over in the browser.' },
|
|
4
|
+
{ id: 2, title: 'Moving between pages', body: 'A link inside the app loads the next page without a whole page load.' },
|
|
5
|
+
{ id: 3, title: 'Forms', body: 'A form sent inside the page with JavaScript, and posted without it.' },
|
|
6
|
+
]
|
|
7
|
+
|
|
8
|
+
export default defineEventHandler(() => POSTS.map(({ id, title }) => ({ id, title })))
|