nuxt-spec 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -3
- package/bin/setup.js +51 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ If you don't want to use the CLI tool, or you want to understand its flow better
|
|
|
36
36
|
1) Add following dependency into your `package.json`:
|
|
37
37
|
|
|
38
38
|
```
|
|
39
|
-
"nuxt-spec": "0.1.
|
|
39
|
+
"nuxt-spec": "0.1.11"
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
2) Add following section into your `nuxt.config.ts`:
|
|
@@ -73,6 +73,20 @@ export default loadVitestConfig({
|
|
|
73
73
|
}
|
|
74
74
|
```
|
|
75
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.11/test).
|
|
89
|
+
|
|
76
90
|
### Install and execute
|
|
77
91
|
|
|
78
92
|
Whether you used the CLI tool or did the manual setup, you are ready to install and run the tests.
|
|
@@ -230,11 +244,11 @@ Planned future development:
|
|
|
230
244
|
- reason about (not) using Vitest browser mode (or make it optional)
|
|
231
245
|
- solution for visual testing - either [backstopjs](https://www.npmjs.com/package/backstopjs) or Vitest's native (currently experimental)
|
|
232
246
|
|
|
233
|
-
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/
|
|
247
|
+
See [CHANGELOG.md](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.11/CHANGELOG.md) for the latest updates and features.
|
|
234
248
|
|
|
235
249
|
## Configuration
|
|
236
250
|
|
|
237
|
-
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/
|
|
251
|
+
By default, `nuxt-spec` uses Vitest configuration defined in [`/config/index.mjs`](https://github.com/AloisSeckar/nuxt-spec/blob/v0.1.11/config/index.mjs). The configuration is based on [Nuxt team recommendations](https://nuxt.com/docs/4.x/getting-started/testing) and our best judgement.
|
|
238
252
|
|
|
239
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:
|
|
240
254
|
|
package/bin/setup.js
CHANGED
|
@@ -14,10 +14,11 @@ import {
|
|
|
14
14
|
* Then it:
|
|
15
15
|
* 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
|
|
16
16
|
* 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
|
|
17
|
-
* 3) creates/updates `.npmrc` file
|
|
17
|
+
* 3) creates/updates `.npmrc` file (only if pnpm is used)
|
|
18
18
|
* 4) creates default `vitest.config.ts` file
|
|
19
19
|
* 5) adds test-related scripts and pnpm approved build scripts (if using pnpm) in `package.json`
|
|
20
|
-
* 6)
|
|
20
|
+
* 6) creates sample test files
|
|
21
|
+
* 7) clear node_modules and lock file(s)
|
|
21
22
|
*
|
|
22
23
|
* @param {boolean} autoRun - Whether to run the setup automatically without any prompts (defaults to false).
|
|
23
24
|
*/
|
|
@@ -29,12 +30,14 @@ export async function specSetup(autoRun = false) {
|
|
|
29
30
|
const isAutoRun = autoRun || await promptUser('Do you want to set everything up automatically (no more prompts)?')
|
|
30
31
|
showMessage('')
|
|
31
32
|
|
|
33
|
+
const packageManager = getPackageManager()
|
|
34
|
+
|
|
32
35
|
// 1) manage dependencies in package.json
|
|
33
36
|
|
|
34
37
|
// add nuxt-spec
|
|
35
38
|
try {
|
|
36
39
|
await updateJsonFile('package.json', 'dependencies', {
|
|
37
|
-
'nuxt-spec': '0.1.
|
|
40
|
+
'nuxt-spec': '0.1.11',
|
|
38
41
|
}, isAutoRun, 'This will add \'nuxt-spec\' dependency to your \'package.json\'. Continue?')
|
|
39
42
|
} catch (error) {
|
|
40
43
|
console.error('Error adding \'nuxt-spec\' dependency:\n', error.message)
|
|
@@ -98,21 +101,23 @@ export async function specSetup(autoRun = false) {
|
|
|
98
101
|
console.error('Error updating \'nuxt.config.ts\':\n', error.message)
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
// 3) .npmrc file
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
'.npmrc',
|
|
104
|
+
// 3) .npmrc file (only if pnpm is used)
|
|
105
|
+
if (packageManager === 'pnpm') {
|
|
106
|
+
try {
|
|
107
|
+
if (pathExists('.npmrc')) {
|
|
108
|
+
await updateTextFile('.npmrc', ['shamefully-hoist=true'], isAutoRun, 'This will adjust \'.npmrc\' file in your project. Continue?')
|
|
109
|
+
} else {
|
|
110
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/.npmrc',
|
|
111
|
+
'.npmrc', isAutoRun, 'This will add \'.npmrc\' file for your project. Continue?')
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('Error setting up \'.npmrc\':\n', error.message)
|
|
108
115
|
}
|
|
109
|
-
} catch (error) {
|
|
110
|
-
console.error('Error setting up \'.npmrc\':\n', error.message)
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
// 4) create vitest.config.ts
|
|
114
119
|
try {
|
|
115
|
-
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/
|
|
120
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/config/vitest.config.ts.template',
|
|
116
121
|
'vitest.config.ts', isAutoRun, 'This will create a new \'vitest.config.ts\' file for your project. Continue?')
|
|
117
122
|
} catch (error) {
|
|
118
123
|
console.error('Error setting up \'vitest.config.ts\':\n', error.message)
|
|
@@ -132,7 +137,7 @@ export async function specSetup(autoRun = false) {
|
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
// add pnpm approved build scripts
|
|
135
|
-
if (
|
|
140
|
+
if (packageManager === 'pnpm') {
|
|
136
141
|
try {
|
|
137
142
|
await updateJsonFile('package.json', 'pnpm', {
|
|
138
143
|
onlyBuiltDependencies: [
|
|
@@ -146,7 +151,30 @@ export async function specSetup(autoRun = false) {
|
|
|
146
151
|
}
|
|
147
152
|
}
|
|
148
153
|
|
|
149
|
-
// 6)
|
|
154
|
+
// 6) create sample test files
|
|
155
|
+
const createSampleTests = isAutoRun || await promptUser('Do you want to create sample tests in \'/test\' folder?')
|
|
156
|
+
if (createSampleTests) {
|
|
157
|
+
try {
|
|
158
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/test/e2e/nuxt-e2e.test.ts',
|
|
159
|
+
'test/e2e/nuxt-e2e.test.ts', true)
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.error('Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/test/nuxt/nuxt-unit.test.ts',
|
|
165
|
+
'test/nuxt/nuxt-unit.test.ts', true)
|
|
166
|
+
} catch (error) {
|
|
167
|
+
console.error('Error setting up \'nuxt-unit.test.ts\':\n', error.message)
|
|
168
|
+
}
|
|
169
|
+
try {
|
|
170
|
+
await createFileFromWebTemplate('https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v0.1.11/test/unit/vitest.test.ts',
|
|
171
|
+
'test/unit/vitest.test.ts', true)
|
|
172
|
+
} catch (error) {
|
|
173
|
+
console.error('Error setting up \'vitest.test.ts\':\n', error.message)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 7) clear node_modules and lock file(s)
|
|
150
178
|
const prepareForReinstall = isAutoRun || await promptUser('Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?')
|
|
151
179
|
if (prepareForReinstall) {
|
|
152
180
|
if (pathExists('node_modules')) {
|
|
@@ -184,11 +212,17 @@ export async function specSetup(autoRun = false) {
|
|
|
184
212
|
console.error('Error deleting \'bun.lockb\':\n', error.message)
|
|
185
213
|
}
|
|
186
214
|
}
|
|
215
|
+
if (pathExists('deno.lock')) {
|
|
216
|
+
try {
|
|
217
|
+
await deletePath('deno.lock', true)
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error('Error deleting \'deno.lock\':\n', error.message)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
187
222
|
}
|
|
188
223
|
|
|
189
224
|
// 7) inform user
|
|
190
225
|
showMessage('')
|
|
191
226
|
showMessage('NUXT SPEC SETUP COMPLETE', 2)
|
|
192
|
-
showMessage(`Proceed with \`${
|
|
193
|
-
|
|
227
|
+
showMessage(`Proceed with \`${packageManager} install\` to get started.`)
|
|
194
228
|
}
|