nuxt-spec 0.1.16 → 0.1.17
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 -21
- package/README.md +296 -296
- package/app/app.vue +9 -9
- package/app/components/NuxtSpecTestComponent.vue +9 -9
- package/app/utils/vitest-utils.ts +5 -5
- package/bin/cli.js +53 -53
- package/bin/setup.js +231 -231
- package/config/.npmrc.template +2 -2
- package/config/index.d.ts +17 -17
- package/config/index.mjs +44 -44
- package/config/vitest.config.ts.template +5 -5
- package/nuxt.config.ts +14 -14
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Alois Sečkár
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Alois Sečkár
|
|
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,296 +1,296 @@
|
|
|
1
|
-
# Nuxt Spec
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
|
|
5
|
-
**Nuxt Spec** (aka `nuxt-spec`) is a base layer for [Nuxt](https://nuxt.com/) applications incorporating together a couple of testing libraries and packages and providing some utility functions. I created this project in early 2025 because I was unable to find a convenient "one-dependency" way to start testing my Nuxt apps and I didn't want to repeat the same steps and maintain the same set of dependencies over and over.
|
|
6
|
-
|
|
7
|
-
While Nuxt itself does have a [dedicated module for testing](https://nuxt.com/docs/getting-started/testing), to remain as versatile as possible, it has to be combined with other packages (which can be different based on your choice). I am trying to overcome this by defining "the way". This is both the strength and the weakness of this project. You were warned.
|
|
8
|
-
|
|
9
|
-
The most important client of `nuxt-spec` is my [Nuxt Ignis](https://github.com/AloisSeckar/nuxt-ignis) template starter that adds up even more ready-to-use cool stuff for your future awesome Nuxt websites.
|
|
10
|
-
|
|
11
|
-
## How to use
|
|
12
|
-
|
|
13
|
-
Aside from being "forked" and used as you seem fit, `nuxt-spec` is also available as an [NPM package](https://www.npmjs.com/package/nuxt-spec) that can be referenced as a single-import with all the features incoming.
|
|
14
|
-
|
|
15
|
-
The `nuxt-spec` package comes with a built-in CLI tool that can help you:
|
|
16
|
-
- setup the dependency in your project
|
|
17
|
-
- scaffold the default `vitest.config.ts` (see [configuration](#configuration) section)
|
|
18
|
-
- add a few test-related script shorthands into your `package.json` (see [running tests](#running-tests) section)
|
|
19
|
-
|
|
20
|
-
To use it, just run the CLI script in your terminal:
|
|
21
|
-
|
|
22
|
-
| Manager | Command |
|
|
23
|
-
|-----------------|---------|
|
|
24
|
-
| npm | `npx nuxt-spec setup` |
|
|
25
|
-
| yarn | `yarn dlx nuxt-spec setup` |
|
|
26
|
-
| pnpm | `pnpx nuxt-spec setup` |
|
|
27
|
-
| Bun | `bunx nuxt-spec setup` |
|
|
28
|
-
| Deno | `deno run --allow-run npm:npx nuxt-spec setup` |
|
|
29
|
-
|
|
30
|
-
First, the CLI tool will ask you whether you want to do the setup automatically. If you choose `y`es, it will perform all the steps for you. If you choose `n`o, it will guide you through the manual setup step-by-step (see [manual setup](#manual-setup) section).
|
|
31
|
-
|
|
32
|
-
### Manual setup
|
|
33
|
-
|
|
34
|
-
If you don't want to use the CLI tool, or you want to understand its flow better, here are the detailed steps:
|
|
35
|
-
|
|
36
|
-
1) Add following dependency into your `package.json`:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
"nuxt-spec": "0.1.
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
2) Add following section into your `nuxt.config.ts`:
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
extends: [
|
|
46
|
-
'nuxt-spec'
|
|
47
|
-
]
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
3) Add `.npmrc` file with following content (if you don't have it yet):
|
|
51
|
-
|
|
52
|
-
```
|
|
53
|
-
shamefully-hoist=true
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
4) Add `vitest.config.ts` file with following content (if you don't have it yet):
|
|
57
|
-
|
|
58
|
-
```ts
|
|
59
|
-
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
60
|
-
|
|
61
|
-
export default loadVitestConfig({
|
|
62
|
-
// your custom config here
|
|
63
|
-
})
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
5) (Optional) Add following scripts into your `package.json`:
|
|
67
|
-
|
|
68
|
-
```
|
|
69
|
-
"scripts": {
|
|
70
|
-
"test": "vitest run",
|
|
71
|
-
"test-u": "vitest run -u",
|
|
72
|
-
"test-i": "vitest"
|
|
73
|
-
}
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
6) (Optional) Setup file structures for tests as follows:
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
test/
|
|
80
|
-
├── e2e/
|
|
81
|
-
│ └── nuxt-e2e.test.ts
|
|
82
|
-
├── nuxt/
|
|
83
|
-
│ └── nuxt-unit.test.ts
|
|
84
|
-
└── unit/
|
|
85
|
-
└── vitest.test.ts
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.1.
|
|
89
|
-
|
|
90
|
-
### Install and execute
|
|
91
|
-
|
|
92
|
-
Whether you used the CLI tool or did the manual setup, you are ready to install and run the tests.
|
|
93
|
-
|
|
94
|
-
1) Install the dependencies:
|
|
95
|
-
|
|
96
|
-
<!-- tabs:start -->
|
|
97
|
-
|
|
98
|
-
#### **npm**
|
|
99
|
-
|
|
100
|
-
```bash
|
|
101
|
-
npm install
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
#### **yarn**
|
|
105
|
-
|
|
106
|
-
```bash
|
|
107
|
-
yarn install
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
#### **pnpm**
|
|
111
|
-
|
|
112
|
-
```bash
|
|
113
|
-
pnpm install
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
#### **bun**
|
|
117
|
-
|
|
118
|
-
```bash
|
|
119
|
-
bun install
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
<!-- tabs:end -->
|
|
123
|
-
|
|
124
|
-
2) If you're prompted (for the first time when installing to a new machine), install headless browser runtimes:
|
|
125
|
-
|
|
126
|
-
<!-- tabs:start -->
|
|
127
|
-
|
|
128
|
-
#### **npm**
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
npx playwright-core install
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
#### **yarn**
|
|
135
|
-
|
|
136
|
-
```bash
|
|
137
|
-
yarn dlx playwright-core install
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
#### **pnpm**
|
|
141
|
-
|
|
142
|
-
```bash
|
|
143
|
-
pnpm exec playwright-core install
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
#### **bun**
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
bunx playwright-core install
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
<!-- tabs:end -->
|
|
153
|
-
|
|
154
|
-
3) Start the development server of your awesome Nuxt project:
|
|
155
|
-
|
|
156
|
-
<!-- tabs:start -->
|
|
157
|
-
|
|
158
|
-
#### **npm**
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
npm run dev
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
#### **yarn**
|
|
165
|
-
|
|
166
|
-
```bash
|
|
167
|
-
yarn dev
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
#### **pnpm**
|
|
171
|
-
|
|
172
|
-
```bash
|
|
173
|
-
pnpm dev
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
#### **bun**
|
|
177
|
-
|
|
178
|
-
```bash
|
|
179
|
-
bun run dev
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
<!-- tabs:end -->
|
|
183
|
-
|
|
184
|
-
### Running tests
|
|
185
|
-
|
|
186
|
-
Once installed, Vitest automatically discovers all `*.test.ts` and `*.spec.ts` files in project and becomes capable of running them.
|
|
187
|
-
|
|
188
|
-
You can use those three optional commands `package.json` file in `"scripts"` section in order to run tests easilly:
|
|
189
|
-
- `test: vitest run` - runs once and ends
|
|
190
|
-
- `test-u: vitest run -u` - runs once and updates snapshots
|
|
191
|
-
- `test-i: vitest` - runs and waits in HMR mode for test file changes
|
|
192
|
-
|
|
193
|
-
Then you can call in terminal in root of your project:
|
|
194
|
-
|
|
195
|
-
<!-- tabs:start -->
|
|
196
|
-
|
|
197
|
-
#### **npm**
|
|
198
|
-
|
|
199
|
-
```bash
|
|
200
|
-
npm run test # runs once and ends
|
|
201
|
-
npm run test-u # runs once and updates snapshots
|
|
202
|
-
npm run test-i # runs and waits in HMR mode
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
#### **yarn**
|
|
206
|
-
|
|
207
|
-
```bash
|
|
208
|
-
yarn test # runs once and ends
|
|
209
|
-
yarn test-u # runs once and updates snapshots
|
|
210
|
-
yarn test-i # runs and waits in HMR mode
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
#### **pnpm**
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
pnpm test # runs once and ends
|
|
217
|
-
pnpm test-u # runs once and updates snapshots
|
|
218
|
-
pnpm test-i # runs and waits in HMR mode
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
#### **bun**
|
|
222
|
-
|
|
223
|
-
```bash
|
|
224
|
-
bun run test # runs once and ends
|
|
225
|
-
bun run test-u # runs once and updates snapshots
|
|
226
|
-
bun run test-i # runs and waits in HMR mode
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
<!-- tabs:end -->
|
|
230
|
-
|
|
231
|
-
Or you can use the `vitest` command directly with all its parameters. See [Vitest CLI documentation](https://vitest.dev/guide/cli.html) for more info.
|
|
232
|
-
|
|
233
|
-
## Overview
|
|
234
|
-
|
|
235
|
-
**Nuxt Spec** currently contains:
|
|
236
|
-
- [vitest](https://www.npmjs.com/package/vitest) **v4** as the fundamental testing framework
|
|
237
|
-
- [@vitest/browser](https://www.npmjs.com/package/@vitest/browser) as the experimental browser runner
|
|
238
|
-
- [happy-dom](https://www.npmjs.com/package/happy-dom) as the headless browser runtime
|
|
239
|
-
- [playwright-core](https://www.npmjs.com/package/playwright-core) as the headless browser testing framework
|
|
240
|
-
- [@vue/test-utils](https://www.npmjs.com/package/@vue/test-utils) for testing Vue stuff
|
|
241
|
-
- [@nuxt/test-utils](https://www.npmjs.com/package/@nuxt/test-utils) for testing Nuxt stuff
|
|
242
|
-
|
|
243
|
-
Planned future development:
|
|
244
|
-
- reason about (not) using Vitest browser mode (or make it optional)
|
|
245
|
-
- solution for visual testing - either [backstopjs](https://www.npmjs.com/package/backstopjs) or Vitest's native (currently experimental)
|
|
246
|
-
|
|
247
|
-
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.
|
|
248
|
-
|
|
249
|
-
## Configuration
|
|
250
|
-
|
|
251
|
-
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.
|
|
252
|
-
|
|
253
|
-
To add/override your custom config, you can create (or scaffold via CLI tool) a file named `vitest.config.ts` in the root of your project with the following content:
|
|
254
|
-
|
|
255
|
-
```ts
|
|
256
|
-
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
257
|
-
|
|
258
|
-
export default loadVitestConfig({
|
|
259
|
-
// your custom config here
|
|
260
|
-
})
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
And pass whatever you want as a parameter object. It will be defu-merged with the defaults (custom config takes precedence). The object is typed to be compatible with both [Vite](https://vite.dev/config/) and [Vitest](https://vitest.dev/config/) configuration options. Used type is derived from the respective `.d.ts` files of those packages.
|
|
264
|
-
|
|
265
|
-
**NOTE**: Based on the [Vitest documentation](https://main.vitest.dev/config/), it is possible to pass in **any configuration option** valid for [Vite](https://vite.dev/config/). Configuration related directly to Vitest must be passed under the `test` key, e.g.:
|
|
266
|
-
|
|
267
|
-
```ts
|
|
268
|
-
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
269
|
-
|
|
270
|
-
export default loadVitestConfig({
|
|
271
|
-
test: {
|
|
272
|
-
// your custom config specific to Vitest here
|
|
273
|
-
}
|
|
274
|
-
})
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
By default, Nuxt Spec built-in configuration establishes 3 `projects`:
|
|
278
|
-
- `unit` - for unit tests in `test/unit/`
|
|
279
|
-
- `nuxt` - for Nuxt-related tests in `test/nuxt/`
|
|
280
|
-
- `e2e` - for end-to-end tests in `test/e2e/`
|
|
281
|
-
|
|
282
|
-
Vitest will then expects at least one test defined in one of those directories. The `test.projects` confing may be extended with others, but it cannot be easily removed due to nature of defu-merge process. If your project uses different configuration (i.e. your test reside in completely different path), you can pass `false` as a second parameter to `loadVitestConfig()` function to exclude `test.projects` key to be injected:
|
|
283
|
-
|
|
284
|
-
```ts
|
|
285
|
-
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
286
|
-
|
|
287
|
-
export default loadVitestConfig({
|
|
288
|
-
// your custom config here
|
|
289
|
-
}, false)
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
Alternatively, if you don't want to use any part of the `nuxt-spec` default configuration at all, you can override `vitest.config.ts` file completely and define your own [Vitest configuration](https://vitest.dev/config/) from scratch.
|
|
293
|
-
|
|
294
|
-
## Contact
|
|
295
|
-
|
|
296
|
-
Use GitHub issues to report bugs or suggest improvements. I will be more than happy to address them.
|
|
1
|
+
# Nuxt Spec
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
**Nuxt Spec** (aka `nuxt-spec`) is a base layer for [Nuxt](https://nuxt.com/) applications incorporating together a couple of testing libraries and packages and providing some utility functions. I created this project in early 2025 because I was unable to find a convenient "one-dependency" way to start testing my Nuxt apps and I didn't want to repeat the same steps and maintain the same set of dependencies over and over.
|
|
6
|
+
|
|
7
|
+
While Nuxt itself does have a [dedicated module for testing](https://nuxt.com/docs/getting-started/testing), to remain as versatile as possible, it has to be combined with other packages (which can be different based on your choice). I am trying to overcome this by defining "the way". This is both the strength and the weakness of this project. You were warned.
|
|
8
|
+
|
|
9
|
+
The most important client of `nuxt-spec` is my [Nuxt Ignis](https://github.com/AloisSeckar/nuxt-ignis) template starter that adds up even more ready-to-use cool stuff for your future awesome Nuxt websites.
|
|
10
|
+
|
|
11
|
+
## How to use
|
|
12
|
+
|
|
13
|
+
Aside from being "forked" and used as you seem fit, `nuxt-spec` is also available as an [NPM package](https://www.npmjs.com/package/nuxt-spec) that can be referenced as a single-import with all the features incoming.
|
|
14
|
+
|
|
15
|
+
The `nuxt-spec` package comes with a built-in CLI tool that can help you:
|
|
16
|
+
- setup the dependency in your project
|
|
17
|
+
- scaffold the default `vitest.config.ts` (see [configuration](#configuration) section)
|
|
18
|
+
- add a few test-related script shorthands into your `package.json` (see [running tests](#running-tests) section)
|
|
19
|
+
|
|
20
|
+
To use it, just run the CLI script in your terminal:
|
|
21
|
+
|
|
22
|
+
| Manager | Command |
|
|
23
|
+
|-----------------|---------|
|
|
24
|
+
| npm | `npx nuxt-spec setup` |
|
|
25
|
+
| yarn | `yarn dlx nuxt-spec setup` |
|
|
26
|
+
| pnpm | `pnpx nuxt-spec setup` |
|
|
27
|
+
| Bun | `bunx nuxt-spec setup` |
|
|
28
|
+
| Deno | `deno run --allow-run npm:npx nuxt-spec setup` |
|
|
29
|
+
|
|
30
|
+
First, the CLI tool will ask you whether you want to do the setup automatically. If you choose `y`es, it will perform all the steps for you. If you choose `n`o, it will guide you through the manual setup step-by-step (see [manual setup](#manual-setup) section).
|
|
31
|
+
|
|
32
|
+
### Manual setup
|
|
33
|
+
|
|
34
|
+
If you don't want to use the CLI tool, or you want to understand its flow better, here are the detailed steps:
|
|
35
|
+
|
|
36
|
+
1) Add following dependency into your `package.json`:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
"nuxt-spec": "0.1.17"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
2) Add following section into your `nuxt.config.ts`:
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
extends: [
|
|
46
|
+
'nuxt-spec'
|
|
47
|
+
]
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
3) Add `.npmrc` file with following content (if you don't have it yet):
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
shamefully-hoist=true
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
4) Add `vitest.config.ts` file with following content (if you don't have it yet):
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
60
|
+
|
|
61
|
+
export default loadVitestConfig({
|
|
62
|
+
// your custom config here
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
5) (Optional) Add following scripts into your `package.json`:
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
"scripts": {
|
|
70
|
+
"test": "vitest run",
|
|
71
|
+
"test-u": "vitest run -u",
|
|
72
|
+
"test-i": "vitest"
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
6) (Optional) Setup file structures for tests as follows:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
test/
|
|
80
|
+
├── e2e/
|
|
81
|
+
│ └── nuxt-e2e.test.ts
|
|
82
|
+
├── nuxt/
|
|
83
|
+
│ └── nuxt-unit.test.ts
|
|
84
|
+
└── unit/
|
|
85
|
+
└── vitest.test.ts
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You can use sample files from the [project repository](https://github.com/AloisSeckar/nuxt-spec/tree/v0.1.17/test).
|
|
89
|
+
|
|
90
|
+
### Install and execute
|
|
91
|
+
|
|
92
|
+
Whether you used the CLI tool or did the manual setup, you are ready to install and run the tests.
|
|
93
|
+
|
|
94
|
+
1) Install the dependencies:
|
|
95
|
+
|
|
96
|
+
<!-- tabs:start -->
|
|
97
|
+
|
|
98
|
+
#### **npm**
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
npm install
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### **yarn**
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
yarn install
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### **pnpm**
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
pnpm install
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### **bun**
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
bun install
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
<!-- tabs:end -->
|
|
123
|
+
|
|
124
|
+
2) If you're prompted (for the first time when installing to a new machine), install headless browser runtimes:
|
|
125
|
+
|
|
126
|
+
<!-- tabs:start -->
|
|
127
|
+
|
|
128
|
+
#### **npm**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npx playwright-core install
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
#### **yarn**
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
yarn dlx playwright-core install
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### **pnpm**
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
pnpm exec playwright-core install
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### **bun**
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
bunx playwright-core install
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
<!-- tabs:end -->
|
|
153
|
+
|
|
154
|
+
3) Start the development server of your awesome Nuxt project:
|
|
155
|
+
|
|
156
|
+
<!-- tabs:start -->
|
|
157
|
+
|
|
158
|
+
#### **npm**
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npm run dev
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### **yarn**
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
yarn dev
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
#### **pnpm**
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
pnpm dev
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### **bun**
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
bun run dev
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
<!-- tabs:end -->
|
|
183
|
+
|
|
184
|
+
### Running tests
|
|
185
|
+
|
|
186
|
+
Once installed, Vitest automatically discovers all `*.test.ts` and `*.spec.ts` files in project and becomes capable of running them.
|
|
187
|
+
|
|
188
|
+
You can use those three optional commands `package.json` file in `"scripts"` section in order to run tests easilly:
|
|
189
|
+
- `test: vitest run` - runs once and ends
|
|
190
|
+
- `test-u: vitest run -u` - runs once and updates snapshots
|
|
191
|
+
- `test-i: vitest` - runs and waits in HMR mode for test file changes
|
|
192
|
+
|
|
193
|
+
Then you can call in terminal in root of your project:
|
|
194
|
+
|
|
195
|
+
<!-- tabs:start -->
|
|
196
|
+
|
|
197
|
+
#### **npm**
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npm run test # runs once and ends
|
|
201
|
+
npm run test-u # runs once and updates snapshots
|
|
202
|
+
npm run test-i # runs and waits in HMR mode
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
#### **yarn**
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
yarn test # runs once and ends
|
|
209
|
+
yarn test-u # runs once and updates snapshots
|
|
210
|
+
yarn test-i # runs and waits in HMR mode
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### **pnpm**
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
pnpm test # runs once and ends
|
|
217
|
+
pnpm test-u # runs once and updates snapshots
|
|
218
|
+
pnpm test-i # runs and waits in HMR mode
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### **bun**
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
bun run test # runs once and ends
|
|
225
|
+
bun run test-u # runs once and updates snapshots
|
|
226
|
+
bun run test-i # runs and waits in HMR mode
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
<!-- tabs:end -->
|
|
230
|
+
|
|
231
|
+
Or you can use the `vitest` command directly with all its parameters. See [Vitest CLI documentation](https://vitest.dev/guide/cli.html) for more info.
|
|
232
|
+
|
|
233
|
+
## Overview
|
|
234
|
+
|
|
235
|
+
**Nuxt Spec** currently contains:
|
|
236
|
+
- [vitest](https://www.npmjs.com/package/vitest) **v4** as the fundamental testing framework
|
|
237
|
+
- [@vitest/browser](https://www.npmjs.com/package/@vitest/browser) as the experimental browser runner
|
|
238
|
+
- [happy-dom](https://www.npmjs.com/package/happy-dom) as the headless browser runtime
|
|
239
|
+
- [playwright-core](https://www.npmjs.com/package/playwright-core) as the headless browser testing framework
|
|
240
|
+
- [@vue/test-utils](https://www.npmjs.com/package/@vue/test-utils) for testing Vue stuff
|
|
241
|
+
- [@nuxt/test-utils](https://www.npmjs.com/package/@nuxt/test-utils) for testing Nuxt stuff
|
|
242
|
+
|
|
243
|
+
Planned future development:
|
|
244
|
+
- reason about (not) using Vitest browser mode (or make it optional)
|
|
245
|
+
- solution for visual testing - either [backstopjs](https://www.npmjs.com/package/backstopjs) or Vitest's native (currently experimental)
|
|
246
|
+
|
|
247
|
+
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.17/CHANGELOG.md) for the latest updates and features.
|
|
248
|
+
|
|
249
|
+
## Configuration
|
|
250
|
+
|
|
251
|
+
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.17/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
|
|
252
|
+
|
|
253
|
+
To add/override your custom config, you can create (or scaffold via CLI tool) a file named `vitest.config.ts` in the root of your project with the following content:
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
257
|
+
|
|
258
|
+
export default loadVitestConfig({
|
|
259
|
+
// your custom config here
|
|
260
|
+
})
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
And pass whatever you want as a parameter object. It will be defu-merged with the defaults (custom config takes precedence). The object is typed to be compatible with both [Vite](https://vite.dev/config/) and [Vitest](https://vitest.dev/config/) configuration options. Used type is derived from the respective `.d.ts` files of those packages.
|
|
264
|
+
|
|
265
|
+
**NOTE**: Based on the [Vitest documentation](https://main.vitest.dev/config/), it is possible to pass in **any configuration option** valid for [Vite](https://vite.dev/config/). Configuration related directly to Vitest must be passed under the `test` key, e.g.:
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
269
|
+
|
|
270
|
+
export default loadVitestConfig({
|
|
271
|
+
test: {
|
|
272
|
+
// your custom config specific to Vitest here
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
By default, Nuxt Spec built-in configuration establishes 3 `projects`:
|
|
278
|
+
- `unit` - for unit tests in `test/unit/`
|
|
279
|
+
- `nuxt` - for Nuxt-related tests in `test/nuxt/`
|
|
280
|
+
- `e2e` - for end-to-end tests in `test/e2e/`
|
|
281
|
+
|
|
282
|
+
Vitest will then expects at least one test defined in one of those directories. The `test.projects` confing may be extended with others, but it cannot be easily removed due to nature of defu-merge process. If your project uses different configuration (i.e. your test reside in completely different path), you can pass `false` as a second parameter to `loadVitestConfig()` function to exclude `test.projects` key to be injected:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
import { loadVitestConfig } from 'nuxt-spec/config'
|
|
286
|
+
|
|
287
|
+
export default loadVitestConfig({
|
|
288
|
+
// your custom config here
|
|
289
|
+
}, false)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Alternatively, if you don't want to use any part of the `nuxt-spec` default configuration at all, you can override `vitest.config.ts` file completely and define your own [Vitest configuration](https://vitest.dev/config/) from scratch.
|
|
293
|
+
|
|
294
|
+
## Contact
|
|
295
|
+
|
|
296
|
+
Use GitHub issues to report bugs or suggest improvements. I will be more than happy to address them.
|
package/app/app.vue
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<h1>Nuxt Spec</h1>
|
|
4
|
-
<div>
|
|
5
|
-
Test-pack layer for <a href="https://nuxt.com/">Nuxt</a> applications
|
|
6
|
-
</div>
|
|
7
|
-
<NuxtSpecTestComponent text="Test Component" />
|
|
8
|
-
</div>
|
|
9
|
-
</template>
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<h1>Nuxt Spec</h1>
|
|
4
|
+
<div>
|
|
5
|
+
Test-pack layer for <a href="https://nuxt.com/">Nuxt</a> applications
|
|
6
|
+
</div>
|
|
7
|
+
<NuxtSpecTestComponent text="Test Component" />
|
|
8
|
+
</div>
|
|
9
|
+
</template>
|