@webship-js/nextjs-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 +575 -2
- package/package.json +64 -4
- package/tests/features/README.md +28 -0
- package/tests/features/build.feature +24 -0
- package/tests/features/default-app.feature +33 -0
- package/tests/features/development.feature +24 -0
- package/tests/features/errors.feature +38 -0
- package/tests/features/forms.feature +56 -0
- package/tests/features/images.feature +38 -0
- package/tests/features/loading.feature +43 -0
- package/tests/features/navigation.feature +46 -0
- package/tests/features/pages-router.feature +35 -0
- package/tests/features/search-and-pagination.feature +37 -0
- package/tests/features/session.feature +59 -0
- package/tests/step-definitions/README.md +30 -0
- package/tests/step-definitions/nextjs-errors.steps.js +250 -0
- package/tests/step-definitions/nextjs-forms.steps.js +266 -0
- package/tests/step-definitions/nextjs-helpers.js +1036 -0
- package/tests/step-definitions/nextjs-images.steps.js +200 -0
- package/tests/step-definitions/nextjs-loading.steps.js +170 -0
- package/tests/step-definitions/nextjs-navigation.steps.js +194 -0
- package/tests/step-definitions/nextjs-pages.steps.js +204 -0
- package/tests/step-definitions/nextjs-session.steps.js +254 -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,576 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/webship/nextjs-steps/2.0.x/assets/logo.svg" alt="Next.js logo" width="96"></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# nextjs-steps
|
|
4
|
+
|
|
5
|
+
Cucumber step definitions for testing apps built with Next.js, with
|
|
6
|
+
[webship-js](https://webship.co/docs/webship-js/2.0.x), a BDD browser automation
|
|
7
|
+
harness built on Playwright and Cucumber-js.
|
|
8
|
+
|
|
9
|
+
A Next.js app has no user interface of its own, so `@webship-js/nextjs-steps`
|
|
10
|
+
targets what the framework does in every app, which is also what makes tests
|
|
11
|
+
flaky when a step does not wait for it: hydration; client-side navigation, the
|
|
12
|
+
browser's back and forward buttons and the route announcer; the pages the
|
|
13
|
+
router fetches ahead of a click; streaming and the loading states of the parts
|
|
14
|
+
of a page; form actions, their pending state and the errors they send back next
|
|
15
|
+
to each field; the not-found pages and the error pages of an error boundary,
|
|
16
|
+
with the details of an error kept from the visitor; the image component's lazy,
|
|
17
|
+
preloaded and optimized images; pages prerendered or rendered for each request;
|
|
18
|
+
the production build, and the error overlay and tools of the development server;
|
|
19
|
+
and a login form with its session. The steps are proven on the App Router and
|
|
20
|
+
the Pages Router, on 16.4.6 (the current release, the Active LTS line) and on
|
|
21
|
+
15.5.29 (the Maintenance LTS line).
|
|
22
|
+
|
|
23
|
+
No step phrase names the framework or its libraries: a scenario reads `When I
|
|
24
|
+
click the link "Invoices" without a full page reload` and `Then a part of the
|
|
25
|
+
page should show its loading state`.
|
|
26
|
+
|
|
27
|
+
Every step waits on the app's own signals, never on a clock: React's own marks
|
|
28
|
+
of a hydrated element and of a Suspense boundary showing its fallback, the
|
|
29
|
+
markers of the parts the server streams, the router's own requests and commits,
|
|
30
|
+
the Pages Router's events, and the requests the page sends. [How the steps find
|
|
31
|
+
things and wait](#how-the-steps-find-things-and-wait) says what each wait
|
|
32
|
+
relies on.
|
|
33
|
+
|
|
34
|
+
CI builds the apps with [DDEV](https://ddev.com) on the runner (the finished
|
|
35
|
+
app of the official Learn course on PostgreSQL, on both release lines and on the
|
|
36
|
+
development server; the app `create-next-app` makes with its defaults; the
|
|
37
|
+
official Pages Router example), runs the suite of each twice on every push and
|
|
38
|
+
pull request, then the assertions that must fail; see
|
|
39
|
+
[`.github/workflows/test.yml`](.github/workflows/test.yml).
|
|
40
|
+
|
|
41
|
+
## From nothing to a green run
|
|
42
|
+
|
|
43
|
+
What the machine needs: Docker, [DDEV](https://ddev.com), git, python3, and Node.js 20 or later with npm. The app, its Node.js 24 and its PostgreSQL run in DDEV's containers.
|
|
44
|
+
|
|
45
|
+
**1. The app.** The pack's own build script (the one CI runs) makes the app in a DDEV project of type `generic`: the finished app of the official Learn course (a dashboard of invoices and customers with a login), made with `create-next-app` from the course's example, moved to 16.4.6, its database (PostgreSQL 17, in a container of the project) seeded by the course's own seed, then the suite's own test data and the two accounts of [Test users](#test-users), then built for production and served by the web container. It takes about two minutes.
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
git clone https://github.com/webship/nextjs-steps.git
|
|
49
|
+
SITE_DIR="$PWD/learn-app" nextjs-steps/.github/scripts/build-ddev-site.sh
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The app answers at `https://nextjssteps.ddev.site`. Its accounts are `administrator@example.com` and `editor@example.com`, each with the password `dD.123123ddd` (step 3 names them).
|
|
53
|
+
|
|
54
|
+
In the [Webship Workspace](https://github.com/webship/workspace), its Next.js plugin builds the same app instead, in a sites folder of the workspace (`dev/` here, the one `--with-needs` adds to a new workspace; `test/`, `sandboxes/` and `demos/` work the same):
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
bash core/scripts/plugins.sh --require nextjs --with-needs
|
|
58
|
+
bash core/scripts/plugins.sh --activate nextjs --with-needs
|
|
59
|
+
bash core/scripts/plugins.sh --install nextjs
|
|
60
|
+
bash dev/cmd-nextjs-project.sh nxlearn --install --add-users --example learn --test-data
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
That app answers at `https://nxlearn.ddev.site`. `--test-data` adds the same test data (the customers "Ivy Example" and "Oak Example" and their invoices). Its accounts are the plugin's, the same two with the workspace's shared password `dD.123123ddd`: `administrator@example.com` and `editor@example.com` (step 3 names them).
|
|
64
|
+
|
|
65
|
+
**2. A test project.**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
mkdir nextjs-tests && cd nextjs-tests
|
|
69
|
+
npm init -y
|
|
70
|
+
npm install --save-dev webship-js @webship-js/nextjs-steps
|
|
71
|
+
npx init-webship-js
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`npx init-webship-js` writes `cucumber.js`, `playwright.config.ts`, the `tests/` folders with a first feature and the `npm test` scripts, and installs Chromium. npm usually runs it already when it installs webship-js; a second run changes nothing.
|
|
75
|
+
|
|
76
|
+
**3. `cucumber.js`.** Replace the file with the wiring of the pack: the step files of webship-js and of the pack, the paths (a feature named on the command line runs alone, as in the file `npx init-webship-js` writes), the tags that keep the assertions that must fail out of a normal run, the address of the app, its login page and its session address, and the accounts (the JSON of [Test users](#test-users)).
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
// A feature or a scenario named on the command line runs alone (cucumber-js 12 would add it to the
|
|
80
|
+
// paths below): `npx cucumber-js tests/features/first-run.feature`.
|
|
81
|
+
const OPTIONS_WITH_A_VALUE = new Set([
|
|
82
|
+
'-c', '--config', '-f', '--format', '--format-options', '--i18n-keywords',
|
|
83
|
+
'-i', '--import', '-l', '--loader', '--language', '--name', '--order',
|
|
84
|
+
'-p', '--profile', '--parallel', '--plugin', '--plugin-options',
|
|
85
|
+
'-r', '--require', '--require-module', '--retry', '--retry-tag-filter',
|
|
86
|
+
'--shard', '-t', '--tags', '--world-parameters',
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
function commandLinePaths() {
|
|
90
|
+
if (!/cucumber(-js|\.js)?$/.test(String(process.argv[1] || ''))) return [];
|
|
91
|
+
const args = process.argv.slice(2);
|
|
92
|
+
const paths = [];
|
|
93
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
94
|
+
if (args[i].startsWith('-')) {
|
|
95
|
+
if (OPTIONS_WITH_A_VALUE.has(args[i])) i += 1;
|
|
96
|
+
} else {
|
|
97
|
+
paths.push(args[i]);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return paths;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
default: {
|
|
105
|
+
requireModule: ['tsx/cjs'],
|
|
106
|
+
require: [
|
|
107
|
+
'node_modules/webship-js/tests/step-definitions/**/*.js',
|
|
108
|
+
'node_modules/@webship-js/nextjs-steps/tests/step-definitions/*.js',
|
|
109
|
+
'tests/step-definitions/**/*.js',
|
|
110
|
+
],
|
|
111
|
+
paths: commandLinePaths().length ? [] : ['tests/features/**/*.feature'],
|
|
112
|
+
// Work in progress and the assertions that must fail stay out of a normal run.
|
|
113
|
+
tags: 'not @wip and not @must-fail',
|
|
114
|
+
format: ['@cucumber/pretty-formatter', 'json:tests/reports/cucumber_report.json'],
|
|
115
|
+
worldParameters: {
|
|
116
|
+
launchUrl: process.env.LAUNCH_URL || 'https://nextjssteps.ddev.site',
|
|
117
|
+
// The app's login page, and the address that answers with the session of the browser.
|
|
118
|
+
loginPath: '/login',
|
|
119
|
+
sessionPath: '/api/auth/session',
|
|
120
|
+
// An account that logged in once keeps its session for the rest of the run.
|
|
121
|
+
reuseSessions: true,
|
|
122
|
+
// The browser logs "Failed to load resource: the server responded with a status of 404" (or 500)
|
|
123
|
+
// for an error page: not a fault of the app. The scenarios that open one carry @js-off.
|
|
124
|
+
javascript: { mode: 'warn', levels: ['error'] },
|
|
125
|
+
// The waits webship-js adds around each page, scenario and step (milliseconds).
|
|
126
|
+
minWaitTime: { page: 3000, before_scenario: 0, after_scenario: 0, before_step: 0, after_step: 0 },
|
|
127
|
+
users: {
|
|
128
|
+
administrator: { email: 'administrator@example.com', password: 'dD.123123ddd', name: 'Administrator' },
|
|
129
|
+
editor: { email: 'editor@example.com', password: 'dD.123123ddd', name: 'Editor' },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
On an app from the Webship Workspace (step 1) the accounts are the same; its address goes in `LAUNCH_URL` (step 5).
|
|
137
|
+
|
|
138
|
+
**4. A first feature**, `tests/features/first-run.feature`:
|
|
139
|
+
|
|
140
|
+
```gherkin
|
|
141
|
+
Feature: First run
|
|
142
|
+
Scenario: The dashboard opens its pages in the same document
|
|
143
|
+
Given I am a logged in user with the "administrator" user
|
|
144
|
+
When I click the link "Invoices" without a full page reload
|
|
145
|
+
Then the route announcer should announce "Invoices"
|
|
146
|
+
And the site should be served as a production build
|
|
147
|
+
And there should be no hydration errors
|
|
148
|
+
|
|
149
|
+
Scenario: A wrong password is refused
|
|
150
|
+
When I log in with the email "administrator@example.com" and the password "wrong-password"
|
|
151
|
+
Then the form should show the message "Invalid credentials."
|
|
152
|
+
And I should not be logged in
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**5. Run it.** Set `LAUNCH_URL` to the address of the app: `https://nextjssteps.ddev.site` for the build script's app, `https://nxlearn.ddev.site` for the Workspace's.
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
LAUNCH_URL=https://nextjssteps.ddev.site npm test
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
A green first run prints every step, then the summary (the starter feature of `npx init-webship-js` and the two scenarios above, passed) and the HTML report it wrote:
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
3 scenarios (3 passed)
|
|
165
|
+
10 steps (10 passed)
|
|
166
|
+
[webship-js] HTML report → …/nextjs-tests/tests/reports/cucumber_report.html
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
`npx cucumber-js tests/features/first-run.feature` runs that feature alone.
|
|
170
|
+
|
|
171
|
+
From there, copy the features of [`tests/features/`](tests/features/) (they also ship in the package, under `node_modules/@webship-js/nextjs-steps/tests/features/`): together they use every step of the pack. Each carries the tag of the app it runs on: `@learn` (the Learn app, on the app of either way of step 1), `@default-app` (an app `create-next-app` made with its defaults), `@pages-router` (the Pages Router example); `@development` runs on the development server. Run the ones of your app with `--tags`, for example `npx cucumber-js --tags "@learn and not @development"`. They read no file of their own.
|
|
172
|
+
|
|
173
|
+
### What the suite tests
|
|
174
|
+
|
|
175
|
+
The features of this repository run every step of the pack, twice in a row in CI on every change, then the assertions that must fail:
|
|
176
|
+
|
|
177
|
+
- **The session** (`@learn`): a visitor sent to the login form, which keeps the page asked for; each account logging in through the form; a wrong password and an unknown address refused with the form's message; the login button busy while its answer is held back; a session taken over; logging out.
|
|
178
|
+
- **Client-side navigation** (`@learn`, `@pages-router`): the links of the side navigation opening their pages without a full page reload, the route announcer saying each new title, back and forward, the pages fetched ahead of a click, a page opened from its address.
|
|
179
|
+
- **Search and pagination in the address** (`@learn`): a search put in the address and the list it gives, a search in the address filling in the search box, the pages of the list.
|
|
180
|
+
- **Forms and their actions** (`@learn`): the errors of the server next to each field and for the whole form, an error gone once its field is right, an invoice created, listed and deleted, an invoice changed and put back, each without a full page reload.
|
|
181
|
+
- **Loading states and streaming** (`@learn`): on a slow network, the list showing its loading state while a search streams in, a page whose parts stream in one after the other; the router keeping its page while the answer of a navigation is held back.
|
|
182
|
+
- **Not-found and error pages** (`@learn`, `@default-app`, `@pages-router`): the app's own not-found page for an invoice that does not exist, the default one for an address with no route, the error page of a part that fails without the details of the error, a page that exists being neither.
|
|
183
|
+
- **The production build** (`@learn`, `@default-app`, `@pages-router`): the router that serves the pages, a hydrated page with no hydration errors, no development tools, prerendered pages and pages rendered for each request.
|
|
184
|
+
- **Images** (`@learn`, `@default-app`): lazy and preloaded images, the image optimizer and the format it sends, the size of an image ahead of loading, the picture made for a small screen loading on one and the wide one not.
|
|
185
|
+
- **The development server** (`@learn @development`): its tools on the page, and its error overlay with the details of a part that fails.
|
|
186
|
+
|
|
187
|
+
Not tested: the framework's own tests (it has its own); the app's own business logic (an invoice's total); a hosted database or any account at a vendor; middleware other than the app's; internationalised routing; the Edge runtime; static exports; a site behind a CDN; Firefox and WebKit beyond what the steps need (the slow network is Chromium's own).
|
|
188
|
+
|
|
189
|
+
## Requirements
|
|
190
|
+
|
|
191
|
+
- Node.js 20 or later
|
|
192
|
+
- A webship-js 2.0 test project (webship-js 2.0.16 or later)
|
|
193
|
+
- An app of the 15.x or 16.x line (proven on 15.5.29 and 16.4.6), served as a production build (the development server for the `@development` steps); for the session steps, a login form and an address that answers with the session (see [Accounts](#accounts))
|
|
194
|
+
|
|
195
|
+
## Install
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
npm install --save-dev @webship-js/nextjs-steps
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Quick start
|
|
202
|
+
|
|
203
|
+
1. Add the step files to the `require` list of your webship-js `cucumber.js`:
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
require: [
|
|
207
|
+
'node_modules/webship-js/tests/step-definitions/**/*.js',
|
|
208
|
+
'node_modules/@webship-js/nextjs-steps/tests/step-definitions/*.js',
|
|
209
|
+
'tests/step-definitions/**/*.js',
|
|
210
|
+
],
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
2. Point `launchUrl` at the app and, if your scenarios log in, name the login
|
|
214
|
+
page, the session address and the accounts (see [Accounts](#accounts)):
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
worldParameters: {
|
|
218
|
+
launchUrl: process.env.LAUNCH_URL || 'https://your-app.ddev.site',
|
|
219
|
+
loginPath: '/login', // the login page
|
|
220
|
+
sessionPath: '/api/auth/session', // the session of the browser as JSON
|
|
221
|
+
users: {
|
|
222
|
+
editor: { email: 'editor@example.com', password: process.env.EDITOR_PASSWORD, name: 'Editor' },
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
3. Copy a feature file from [`tests/features/`](tests/features/) into your
|
|
228
|
+
project and replace the addresses, links, labels and texts with those of
|
|
229
|
+
your app.
|
|
230
|
+
|
|
231
|
+
```gherkin
|
|
232
|
+
Feature: The list streams in
|
|
233
|
+
|
|
234
|
+
Scenario: On a slow network the list shows its loading state, then its rows
|
|
235
|
+
Given I am a logged in user with the "editor" user
|
|
236
|
+
And I am on "/dashboard/invoices"
|
|
237
|
+
And the network is slow
|
|
238
|
+
When I fill in "Search invoices..." with "Oak"
|
|
239
|
+
Then a part of the page should show its loading state
|
|
240
|
+
When I wait for the page to finish loading
|
|
241
|
+
Then no part of the page should show its loading state
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## What is included
|
|
245
|
+
|
|
246
|
+
| File | Steps | Covers |
|
|
247
|
+
| --- | --- | --- |
|
|
248
|
+
| `nextjs-pages.steps.js` | 7 | The wait for the page to be ready; a hydrated page and hydration errors; a production build; the router that serves the page; the release it runs on; prerendered pages. It also puts the recorders on every page of the run (the identity of each document, the requests of the app by kind, the errors of the console). |
|
|
249
|
+
| `nextjs-navigation.steps.js` | 5 | A link followed and back and forward, each without a full page reload; the route announcer and what it says; the pages fetched ahead of a click. |
|
|
250
|
+
| `nextjs-loading.steps.js` | 7 | A slow network; a page load that does not wait for its end; a part of the page showing its loading state; the server's answers held back and let through; the page waiting for the server; the wait for the page to finish loading. |
|
|
251
|
+
| `nextjs-forms.steps.js` | 5 | A form sent with its button (in a table row too), sent without a full page reload; the error of a field; the message of a form; a busy button. |
|
|
252
|
+
| `nextjs-errors.steps.js` | 8 | A 404 page and the default one; the error page of an error boundary; the details of an error; the development error overlay, its words and how many errors it lists; the development tools. |
|
|
253
|
+
| `nextjs-images.steps.js` | 7 | Lazy and preloaded images; the image optimizer and the format it sends; the width and the height; an image loaded or not; an image brought into view. |
|
|
254
|
+
| `nextjs-session.steps.js` | 9 | Login by a handle of the users registry (a session taken over when the account already has one), through the form, with an address and a password; the login form filled in without sending it; logout; who is signed in; the login form, and where it sends a person back to. |
|
|
255
|
+
| `nextjs-helpers.js` | | Shared plumbing for the files above and for your own steps: the wait on the app's own signals, the requests of the app by kind, the console of the page, friendly errors (a request the browser cut says so), the users registry, the session cache and the login, the route announcer, the images, the development error overlay. It registers no step. |
|
|
256
|
+
|
|
257
|
+
Text, links, buttons, fields, the address and its parameters, the status code
|
|
258
|
+
of a page, network mocks and the accessibility audit are webship-js's own steps
|
|
259
|
+
(`I should see "..."`, `I press "..."`, `I fill in "..." with "..."`, `the path
|
|
260
|
+
should be "..."`, `current url should have the "..." parameter with the "..."
|
|
261
|
+
value`, `the response status code should be 404`): this pack adds only what the
|
|
262
|
+
framework decides.
|
|
263
|
+
|
|
264
|
+
## Beside other packs
|
|
265
|
+
|
|
266
|
+
The pack loads beside webship-js and the Diffy pack with no phrase in common.
|
|
267
|
+
Some of its phrases are those of other platform packs on purpose, so that a
|
|
268
|
+
tester reads one vocabulary everywhere:
|
|
269
|
+
|
|
270
|
+
- the session (`I am a logged in user with the "…" user`, `I log in as "…"
|
|
271
|
+
with the login form`, `I log in with the email "…" and the password "…"`,
|
|
272
|
+
`I log out`, `I should be logged in`, `I should be logged in as "…"`, `I
|
|
273
|
+
should see the login form`) with the packs of server-side platforms (the
|
|
274
|
+
Laravel, CodeIgniter, Symfony, Moodle, MediaWiki, Odoo, TYPO3, WordPress,
|
|
275
|
+
Drupal core, django CMS, Joomla and Backdrop CMS packs share some or all of
|
|
276
|
+
them);
|
|
277
|
+
- the behaviour of a site that hydrates (`I click the link "…" without a full
|
|
278
|
+
page reload`, `I go back without a full page reload`, the route announcer, a
|
|
279
|
+
prefetched page, `I should see a hydrated page`, `there should be no
|
|
280
|
+
hydration errors`, a production build, the 404 pages) with the Gatsby and
|
|
281
|
+
Astro packs;
|
|
282
|
+
- `I wait for the page to be ready` with the Moodle pack.
|
|
283
|
+
|
|
284
|
+
Load two such packs in two profiles of one project, one per site.
|
|
285
|
+
|
|
286
|
+
## How the steps find things and wait
|
|
287
|
+
|
|
288
|
+
- **By what a person reads.** A link and a button by their name, a field by its
|
|
289
|
+
label (a group of radio buttons by its legend), an image by its alternative
|
|
290
|
+
text, a row by its text, a message by the live region it is announced in. The
|
|
291
|
+
framework's stable hooks are the fallback: `data-nimg` of the image
|
|
292
|
+
component, `#__next-route-announcer__` in `next-route-announcer`,
|
|
293
|
+
`.next-error-h1` of the default not-found page, the `data-nextjs-*`
|
|
294
|
+
attributes of the development tools.
|
|
295
|
+
- **Hydrated.** An element is in the hands of the app when it carries React's
|
|
296
|
+
properties (`__reactProps$…`); the page is hydrated when its root carries
|
|
297
|
+
React's fiber (`<html>` for the App Router, the child of `#__next` or the
|
|
298
|
+
`Next.js-hydration` measure for the Pages Router) and no Suspense boundary is
|
|
299
|
+
still dehydrated. A click waits for its element to be hydrated: on the Learn
|
|
300
|
+
app's create page, the button is visible a moment before its form is.
|
|
301
|
+
- **A page ready.** After every action, a step waits until the document is
|
|
302
|
+
loaded, the app has hydrated, no part of the page shows its loading state, the
|
|
303
|
+
Pages Router is ready with no route change going on (its `routeChangeStart` and
|
|
304
|
+
`routeChangeComplete` events), and no request of the app is running: the
|
|
305
|
+
App Router's payload of a navigation (the header `rsc: 1`), a form action (the
|
|
306
|
+
header `next-action`), the Pages Router's data (`/_next/data/…`), the app's
|
|
307
|
+
own requests. Prefetches (the header `next-router-prefetch`) are left aside.
|
|
308
|
+
All of that has to hold for 150 ms. `When I wait for the page to be ready` is
|
|
309
|
+
that wait, for a project's own steps.
|
|
310
|
+
- **A part showing its loading state.** While the server streams a page, a part
|
|
311
|
+
whose content is still on the way is marked in the HTML (`<!--$?-->`, and
|
|
312
|
+
`<!--$~-->` while React holds its reveal back a moment); in the browser, a
|
|
313
|
+
Suspense boundary of the current tree shows its fallback (a skeleton, a
|
|
314
|
+
spinner, a `loading.js` page). Both count; a part the router keeps hidden for
|
|
315
|
+
going back does not.
|
|
316
|
+
- **Navigation finished.** The router commits a new page to the address bar
|
|
317
|
+
(`pushState`, with its own state) when the page is ready to show; a
|
|
318
|
+
client-side navigation keeps the document, which a step checks by an
|
|
319
|
+
identity it gives each document. While the answer of a navigation is on its
|
|
320
|
+
way, the App Router keeps the old page and marks nothing as busy: the request
|
|
321
|
+
is the only signal, which `the page should be waiting for the server` reads.
|
|
322
|
+
- **A form on its way.** A form action is the request with the header
|
|
323
|
+
`next-action`; the step waits for its answer and for the page it sends the
|
|
324
|
+
browser to (`x-action-redirect`). A button is busy when the app marks it from
|
|
325
|
+
the form's pending state: disabled, `aria-disabled="true"` or
|
|
326
|
+
`aria-busy="true"`.
|
|
327
|
+
- **The errors of a field.** The texts that the field's `aria-describedby` (or
|
|
328
|
+
`aria-errormessage`) names, as a screen reader reads them with the field; the
|
|
329
|
+
message of a form, its live regions (`aria-live`, `role="alert"`,
|
|
330
|
+
`role="status"`).
|
|
331
|
+
- **Answers held back and a slow network.** `the server's answers are held
|
|
332
|
+
back` holds the requests of a navigation, a form action and a page's data
|
|
333
|
+
(Playwright routes) until `the server's answers come through`; `the network is
|
|
334
|
+
slow` is Chromium's own network emulation (200 ms, 6 KB/s), so the parts of a
|
|
335
|
+
page stream in one after the other.
|
|
336
|
+
- **Not-found and error pages.** A 404 page is a document (or a navigation's
|
|
337
|
+
payload) that answered 404, or the "noindex" and the "404" heading the
|
|
338
|
+
framework gives a page it cannot find; the error page of an error boundary
|
|
339
|
+
counts only when an error did happen (a 500, the production error #441 of a
|
|
340
|
+
server render, a request that failed on the server, an error the page raised).
|
|
341
|
+
- **The development server.** Its tools live in the `nextjs-portal` element
|
|
342
|
+
(their indicator; the error overlay, a dialog with its title, its message and
|
|
343
|
+
how many errors it lists). A production build has none of it.
|
|
344
|
+
- **The sticky parts of a page.** An element is brought to the middle of the
|
|
345
|
+
window before a click, so a fixed header never covers it.
|
|
346
|
+
- **Failures say what was found.** `Expected the field "Choose customer" to
|
|
347
|
+
show the error "Please choose somebody.", but it shows "Please select a
|
|
348
|
+
customer.".` with a hint on where to look; a request the browser cut (the
|
|
349
|
+
network of the machine changed) says so instead of blaming the scenario.
|
|
350
|
+
|
|
351
|
+
## Accounts
|
|
352
|
+
|
|
353
|
+
The suite never creates or deletes a user. Accounts are configuration: list
|
|
354
|
+
the ones the app has in `worldParameters.users`, by a handle the scenarios
|
|
355
|
+
use, each with the `email` (or `username`) it logs in with and its `password`,
|
|
356
|
+
and its `name`.
|
|
357
|
+
|
|
358
|
+
```javascript
|
|
359
|
+
users: {
|
|
360
|
+
editor: { email: 'editor@example.com', password: process.env.EDITOR_PASSWORD, name: 'Editor' },
|
|
361
|
+
},
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
The login steps fill in the visible form with a password field at
|
|
365
|
+
`worldParameters.loginPath` (`/login`). Who is signed in is read from
|
|
366
|
+
`worldParameters.sessionPath` (`/api/auth/session`): the address an app's
|
|
367
|
+
authentication library answers with the session of the browser as JSON (`null`
|
|
368
|
+
when nobody is signed in), as it does when the app mounts its handlers.
|
|
369
|
+
|
|
370
|
+
An account that logged in once keeps its session for the rest of the run: a
|
|
371
|
+
later scenario that logs in as the same handle takes the session over instead
|
|
372
|
+
of filling in the login form again. `reuseSessions: false` in
|
|
373
|
+
`worldParameters` turns that off.
|
|
374
|
+
|
|
375
|
+
## Test users
|
|
376
|
+
|
|
377
|
+
The accounts this repository's suite logs in as, exactly as `cucumber.js`
|
|
378
|
+
lists them in `worldParameters.users` (the default values; the
|
|
379
|
+
`<HANDLE>_EMAIL`, `<HANDLE>_PASSWORD` and `<HANDLE>_NAME` variables replace
|
|
380
|
+
them, and `ACCOUNT_PASSWORD` every password at once).
|
|
381
|
+
[`.github/scripts/build-ddev-site.sh`](.github/scripts/build-ddev-site.sh)
|
|
382
|
+
creates them in the Learn app, and CI does the same on the runner. They are
|
|
383
|
+
placeholder credentials of that throwaway app, not of any real one.
|
|
384
|
+
|
|
385
|
+
```json
|
|
386
|
+
{
|
|
387
|
+
"administrator": { "email": "administrator@example.com", "password": "dD.123123ddd", "name": "Administrator" },
|
|
388
|
+
"editor": { "email": "editor@example.com", "password": "dD.123123ddd", "name": "Editor" }
|
|
389
|
+
}
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
The Learn app has no roles: both accounts can do everything. The course's own
|
|
393
|
+
account stays as its seed makes it; no feature logs in with it.
|
|
394
|
+
|
|
395
|
+
## A test app
|
|
396
|
+
|
|
397
|
+
[`.github/scripts/build-ddev-site.sh`](.github/scripts/build-ddev-site.sh)
|
|
398
|
+
builds the app the suite of this repository runs against, in a DDEV project of
|
|
399
|
+
type `generic` (`PROJECT_NAME`, `nextjssteps`): the app in `site/`, Node.js 24
|
|
400
|
+
and pnpm baked in the web image, the app served on port 3000 by a daemon of the
|
|
401
|
+
web container (`next start` of the production build, or `next dev` with
|
|
402
|
+
`SERVER_MODE=development`), the router sending ports 80 and 443 of the project's
|
|
403
|
+
address to it. `APP` chooses the app:
|
|
404
|
+
|
|
405
|
+
- `learn` (the default): the finished app of the official Learn course
|
|
406
|
+
(`dashboard/final-example` of
|
|
407
|
+
[github.com/vercel/next-learn](https://github.com/vercel/next-learn), MIT, at
|
|
408
|
+
a pinned commit, `LEARN_REF`), made with `create-next-app --example` and
|
|
409
|
+
pnpm, moved to `NEXT_VERSION` (16.4.6; the course's lockfile pins an older
|
|
410
|
+
release). Its database is PostgreSQL 17 in a container of the project, with
|
|
411
|
+
TLS on (the app connects with `ssl: 'require'`; the certificate is the
|
|
412
|
+
self-signed one of the PostgreSQL image). The course's own `/seed` route
|
|
413
|
+
seeds it, on the development server, before the production build (the
|
|
414
|
+
dashboard's start page is prerendered with its data). Then
|
|
415
|
+
[`site/test-app.cjs`](site/test-app.cjs) adds the suite's own customers
|
|
416
|
+
("Ivy Example" and "Oak Example", at example.com, each with a copy of a
|
|
417
|
+
picture of the course) and their three invoices, with fixed ids, and the two
|
|
418
|
+
accounts of [Test users](#test-users). The app gets one route of the pack's
|
|
419
|
+
own, [`site/session-route.ts`](site/session-route.ts) at
|
|
420
|
+
`/api/auth/session`: the session of the browser as JSON, which the app's
|
|
421
|
+
authentication library answers itself in an app that mounts its handlers.
|
|
422
|
+
- `default`: the app `create-next-app` makes with its defaults (App Router).
|
|
423
|
+
- `pages`: the official `with-typescript` example (Pages Router), at the tag of
|
|
424
|
+
the release.
|
|
425
|
+
|
|
426
|
+
The build adds the project's address to `allowedDevOrigins` in the app's
|
|
427
|
+
`next.config`, so the development server answers it (the release refuses its
|
|
428
|
+
development resources to another origin), and turns telemetry off
|
|
429
|
+
(`NEXT_TELEMETRY_DISABLED`). Nothing else of the apps is changed: the app runs
|
|
430
|
+
in production mode, as the course's own example ships it.
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
SITE_DIR="$PWD/../learn-app" .github/scripts/build-ddev-site.sh
|
|
434
|
+
npm test
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
`APP=default` or `APP=pages` builds the other apps (the default tags of
|
|
438
|
+
`cucumber.js` follow `APP`); `NEXT_VERSION=15.5.29` the Maintenance LTS line;
|
|
439
|
+
`SERVER_MODE=development` the development server (`SERVE_ONLY=1` switches an
|
|
440
|
+
app already built between the two).
|
|
441
|
+
|
|
442
|
+
## Steps
|
|
443
|
+
|
|
444
|
+
One example of each step; the JSDoc block above each definition holds five.
|
|
445
|
+
|
|
446
|
+
### `nextjs-errors.steps.js` (8)
|
|
447
|
+
|
|
448
|
+
- `I should be on a 404 page`
|
|
449
|
+
- `I should be on the default 404 page`
|
|
450
|
+
- `the error page should show "Something went wrong!"`
|
|
451
|
+
- `the page should not show the details of the error`
|
|
452
|
+
- `the development error overlay should be shown`
|
|
453
|
+
- `the development error overlay should show "invalid input syntax for type uuid"`
|
|
454
|
+
- `the development error overlay should list 2 errors`
|
|
455
|
+
- `the development tools should be on the page`
|
|
456
|
+
|
|
457
|
+
### `nextjs-forms.steps.js` (5)
|
|
458
|
+
|
|
459
|
+
- `I send the form with "Create Invoice"`
|
|
460
|
+
- `the form should have been sent without a full page reload`
|
|
461
|
+
- `the field "Choose customer" should show the error "Please select a customer."`
|
|
462
|
+
- `the form should show the message "Missing Fields. Failed to Create Invoice."`
|
|
463
|
+
- `the "Log in" button should be busy`
|
|
464
|
+
|
|
465
|
+
### `nextjs-images.steps.js` (7)
|
|
466
|
+
|
|
467
|
+
- `the image "Ivy Example's profile picture" should load lazily`
|
|
468
|
+
- `the image "logo" should be preloaded`
|
|
469
|
+
- `the image "Ivy Example's profile picture" should be optimized`
|
|
470
|
+
- `the image "Ivy Example's profile picture" should be served as "image/webp"`
|
|
471
|
+
- `the image "Ivy Example's profile picture" should have a width and a height`
|
|
472
|
+
- `the image "Ivy Example's profile picture" should have loaded`
|
|
473
|
+
- `I scroll the image "Oak Example's profile picture" into view`
|
|
474
|
+
|
|
475
|
+
### `nextjs-loading.steps.js` (7)
|
|
476
|
+
|
|
477
|
+
- `the network is slow`
|
|
478
|
+
- `I start to go to "/dashboard/invoices"`
|
|
479
|
+
- `a part of the page should show its loading state`
|
|
480
|
+
- `the server's answers are held back`
|
|
481
|
+
- `the server's answers come through`
|
|
482
|
+
- `the page should be waiting for the server`
|
|
483
|
+
- `I wait for the page to finish loading`
|
|
484
|
+
|
|
485
|
+
### `nextjs-navigation.steps.js` (5)
|
|
486
|
+
|
|
487
|
+
- `I click the link "Invoices" without a full page reload`
|
|
488
|
+
- `I go back without a full page reload`
|
|
489
|
+
- `the page should have a route announcer`
|
|
490
|
+
- `the route announcer should announce "Invoices | Acme Dashboard"`
|
|
491
|
+
- `the page "/dashboard/invoices" should be prefetched`
|
|
492
|
+
|
|
493
|
+
### `nextjs-pages.steps.js` (7)
|
|
494
|
+
|
|
495
|
+
- `I wait for the page to be ready`
|
|
496
|
+
- `I should see a hydrated page`
|
|
497
|
+
- `there should be no hydration errors`
|
|
498
|
+
- `the site should be served as a production build`
|
|
499
|
+
- `the page should be served by the app router`
|
|
500
|
+
- `the page should run on the release "16"`
|
|
501
|
+
- `the page should be prerendered`
|
|
502
|
+
|
|
503
|
+
### `nextjs-session.steps.js` (9)
|
|
504
|
+
|
|
505
|
+
- `I am a logged in user with the "administrator" user`
|
|
506
|
+
- `I log in as "administrator" with the login form`
|
|
507
|
+
- `I log in with the email "administrator@example.com" and the password "wrong-password"`
|
|
508
|
+
- `I fill in the login form as "administrator"`
|
|
509
|
+
- `I log out`
|
|
510
|
+
- `I should be logged in`
|
|
511
|
+
- `I should be logged in as "administrator"`
|
|
512
|
+
- `I should see the login form`
|
|
513
|
+
- `the login form should send me back to "/dashboard"`
|
|
514
|
+
|
|
515
|
+
## Testing this package
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
npm install
|
|
519
|
+
SITE_DIR="$PWD/../learn-app" .github/scripts/build-ddev-site.sh
|
|
520
|
+
npm run test:examples # the examples and the features against the step patterns
|
|
521
|
+
npm run test:paths # a feature or a scenario named on the command line runs alone
|
|
522
|
+
npx cucumber-js --dry-run # no undefined and no ambiguous step
|
|
523
|
+
npm test # the suite, against the app
|
|
524
|
+
npm run test:must-fail # assertions that must fail, each with its message
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
`LAUNCH_URL` points the suite at another app; `npx cucumber-js
|
|
528
|
+
tests/features/session.feature` runs one feature and `npx cucumber-js
|
|
529
|
+
tests/features/session.feature:<line>` one scenario (the line of its
|
|
530
|
+
`Scenario:`; the paths of `cucumber.js` are left out when the command line
|
|
531
|
+
names any); `FEATURES` runs a subset too
|
|
532
|
+
(`FEATURES=tests/features/session.feature npm test`); `CUCUMBER_TAGS=@critical`
|
|
533
|
+
runs the smoke lane; `HEADLESS=false` shows the browser.
|
|
534
|
+
|
|
535
|
+
`tests/must-fail/` holds scenarios that assert something that is not true on
|
|
536
|
+
the test app. `npm run test:must-fail` runs them and checks that each one
|
|
537
|
+
fails at its last step, with the message it announces and a hint: a step that
|
|
538
|
+
cannot fail proves nothing.
|
|
539
|
+
|
|
540
|
+
The suite leaves the app as it found it: an invoice a scenario creates, it
|
|
541
|
+
deletes; an amount it changes, it puts back. A run stopped half way can leave
|
|
542
|
+
something behind; the build script makes the suite's own customers and their
|
|
543
|
+
invoices again, and gives the accounts back their name and password, without
|
|
544
|
+
building anything else:
|
|
545
|
+
|
|
546
|
+
```bash
|
|
547
|
+
TEST_DATA_ONLY=1 SITE_DIR="$PWD/../learn-app" .github/scripts/build-ddev-site.sh
|
|
548
|
+
ACCOUNTS_ONLY=1 SITE_DIR="$PWD/../learn-app" .github/scripts/build-ddev-site.sh
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
On a machine where other containers start and stop, Chromium can lose a
|
|
552
|
+
request in flight (`net::ERR_NETWORK_CHANGED`): the failure then says the
|
|
553
|
+
request was cut. Run the suite again, or run it inside the project's container
|
|
554
|
+
(the Webship Workspace's `cmd-tools-testing.sh <project> --run` does).
|
|
555
|
+
|
|
556
|
+
## How the steps were written
|
|
557
|
+
|
|
558
|
+
Every page a step touches was opened in a real browser first, and the step was
|
|
559
|
+
written from what is there: the roles and names of the accessibility tree, the
|
|
560
|
+
stable attributes, what the page does while it loads, streams, navigates or
|
|
561
|
+
sends a form, the exact messages. The steps are proven on 16.4.6 and 15.5.29,
|
|
562
|
+
on the App Router and the Pages Router, in English, with Chromium.
|
|
563
|
+
|
|
564
|
+
Not covered: the parallel and intercepting routes, the `<Form>` component's
|
|
565
|
+
search forms, middleware rewrites, internationalised routing, the Edge runtime,
|
|
566
|
+
static exports, the `<Script>` component, the metadata files beyond the title,
|
|
567
|
+
React Server Components' caching options, the experimental features of the
|
|
568
|
+
framework.
|
|
569
|
+
|
|
570
|
+
## License
|
|
571
|
+
|
|
572
|
+
MIT
|
|
573
|
+
|
|
574
|
+
## Logo
|
|
575
|
+
|
|
576
|
+
The Next.js logo in this README comes from Simple Icons 16.37.0 (CC0-1.0), filled with the colour the set lists for the brand. The Next.js name and logo are trademarks of their owner; this pack is not affiliated with or endorsed by them.
|