nuxt-spec 0.3.4 → 0.4.0-alpha.1
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 +13 -13
- package/app/app.vue +10 -10
- package/app/components/NuxtSpecApiTestComponent.vue +24 -24
- package/app/components/NuxtSpecTestComponent.vue +9 -9
- package/app/components/index.d.ts +7 -7
- package/app/components/index.ts +2 -2
- package/app/utils/vitest-utils.ts +5 -5
- package/bin/_internal/prepublish-check.js +16 -16
- package/bin/cli.js +44 -44
- package/bin/helpers/commands.js +82 -82
- package/bin/setup.js +366 -287
- package/bin/update.js +94 -94
- package/config/index.d.ts +36 -33
- package/config/index.mjs +140 -132
- package/config/report/report-entry.html +6 -0
- package/config/report/report-head.html +34 -0
- package/{utils/screenshot/report-entry.html → config/report/report-screenshot.html} +8 -8
- package/config/report/report-tail.html +4 -0
- package/config/templates/pnpm-workspace.yaml.template +19 -19
- package/config/templates/vitest.config.ts.template +5 -5
- package/config/utils/merge.mjs +43 -43
- package/config/utils/options.d.mts +59 -0
- package/config/utils/options.mjs +116 -0
- package/config/utils/reporter.mjs +409 -0
- package/config/utils/warnings.mjs +38 -33
- package/modules/spec-options.ts +23 -0
- package/nuxt.config.ts +20 -24
- package/package.json +33 -31
- package/utils/e2e.ts +131 -131
- package/utils/helpers/check-params.ts +44 -41
- package/utils/helpers/location-hint.ts +30 -30
- package/utils/helpers/screenshot-utils.ts +27 -0
- package/utils/index.ts +12 -12
- package/utils/playwright.ts +28 -20
- package/utils/screenshot.ts +201 -172
- package/utils/screenshot/report-head.html +0 -24
- package/utils/screenshot/report-tail.html +0 -4
- package/utils/screenshot/report-utils.ts +0 -236
package/bin/setup.js
CHANGED
|
@@ -1,287 +1,366 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { execSync } from 'node:child_process'
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
showMessage(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync } from 'node:child_process'
|
|
4
|
+
import { readFileSync } from 'node:fs'
|
|
5
|
+
import {
|
|
6
|
+
createFileFromWebTemplate, deletePath,
|
|
7
|
+
pathExists, promptUser, removeFromJsonFile, showMessage,
|
|
8
|
+
updateConfigFile, updateJsonFile, updateTextFile,
|
|
9
|
+
} from 'elrh-cosca'
|
|
10
|
+
import {
|
|
11
|
+
getPlaywrightInstallCmd, getPrepareCmd,
|
|
12
|
+
} from './helpers/commands.js'
|
|
13
|
+
|
|
14
|
+
const TARGET_VERSION = '0.4.0-alpha.1'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* CLI tool to scaffold necessary adjustments in project folder.
|
|
18
|
+
*
|
|
19
|
+
* It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
|
|
20
|
+
*
|
|
21
|
+
* Then it:
|
|
22
|
+
* 1) adds `nuxt-spec` into `package.json` dependencies and removes `nuxt`, `vue` and `vue-router` if present
|
|
23
|
+
* 2) adds `extends: ['nuxt-spec']` to `nuxt.config.ts`
|
|
24
|
+
* 3) creates/updates `pnpm-workspace.yaml` file (only if pnpm is used)
|
|
25
|
+
* 4) creates default `vitest.config.ts` file
|
|
26
|
+
* 5) creates default `.nuxtrc` file
|
|
27
|
+
* 6) adds test-related scripts in `package.json`
|
|
28
|
+
* 7) creates sample test files
|
|
29
|
+
* 8) adds nuxt-spec related entries to `.gitignore`
|
|
30
|
+
* 9) clear node_modules and lock file(s)
|
|
31
|
+
* 10) run install command
|
|
32
|
+
* 11) run Nuxt prepare command to generate types and auto-imports
|
|
33
|
+
* 12) run Playwright setup command
|
|
34
|
+
*
|
|
35
|
+
* @param {boolean} autoRun - Whether to run the setup automatically without any prompts (defaults to false).
|
|
36
|
+
* @param {string} [packageManager] - Package manager to be used (`npm`, `pnpm`, `yarn`, `bun` or `deno`).
|
|
37
|
+
*/
|
|
38
|
+
export async function specSetup(autoRun = false, packageManager) {
|
|
39
|
+
showMessage({ message: 'NUXT SPEC SETUP' })
|
|
40
|
+
showMessage({ message: 'This CLI tool will help you include Nuxt Spec in your project.' })
|
|
41
|
+
showMessage({ message: 'Refer to the documentation for more information.', linesAfter: 2 })
|
|
42
|
+
|
|
43
|
+
const isAutoRun = autoRun || await promptUser({ question: '[Nuxt Spec] Do you want to set everything up automatically (no more prompts)?' })
|
|
44
|
+
showMessage({ message: '' })
|
|
45
|
+
|
|
46
|
+
// 1) manage dependencies in package.json
|
|
47
|
+
|
|
48
|
+
// add nuxt-spec
|
|
49
|
+
try {
|
|
50
|
+
await updateJsonFile({
|
|
51
|
+
targetFile: 'package.json',
|
|
52
|
+
jsonKey: 'dependencies',
|
|
53
|
+
patch: {
|
|
54
|
+
['nuxt-spec']: TARGET_VERSION,
|
|
55
|
+
},
|
|
56
|
+
force: isAutoRun,
|
|
57
|
+
prompt: `[Nuxt Spec] This will add 'nuxt-spec' dependency to your 'package.json'. Continue?`,
|
|
58
|
+
})
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error(`[Nuxt Spec] Error adding 'nuxt-spec' dependency:\n`, error.message)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// remove now obsolete nuxt, vue and vue-router
|
|
64
|
+
const removeDeps = isAutoRun || await promptUser({ question: `[Nuxt Spec] As 'nuxt-spec' provides 'nuxt', 'vue' and 'vue-router' dependencies out of the box, do you want to remove them from your 'package.json' to avoid duplications and possible version clashes?` })
|
|
65
|
+
if (removeDeps) {
|
|
66
|
+
try {
|
|
67
|
+
await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'dependencies.nuxt', force: true })
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('[Nuxt Spec] Error removing \'nuxt\' dependency:\n', error.message)
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'dependencies.vue', force: true })
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error('[Nuxt Spec] Error removing \'vue\' dependency:\n', error.message)
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'dependencies.vue-router', force: true })
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error('[Nuxt Spec] Error removing \'vue-router\' dependency:\n', error.message)
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'devDependencies.nuxt', force: true })
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('[Nuxt Spec] Error removing \'nuxt\' devDependency:\n', error.message)
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'devDependencies.vue', force: true })
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error('[Nuxt Spec] Error removing \'vue\' devDependency:\n', error.message)
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await removeFromJsonFile({ targetFile: 'package.json', jsonKey: 'devDependencies.vue-router', force: true })
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('[Nuxt Spec] Error removing \'vue-router\' devDependency:\n', error.message)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 2) modify nuxt.config.ts
|
|
99
|
+
try {
|
|
100
|
+
await updateConfigFile({
|
|
101
|
+
targetFile: 'nuxt.config.ts',
|
|
102
|
+
newConfig: {
|
|
103
|
+
extends: [
|
|
104
|
+
'nuxt-spec',
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
force: isAutoRun,
|
|
108
|
+
prompt: `[Nuxt Spec] This will add 'nuxt-spec' module to your 'nuxt.config.ts'. Continue?`,
|
|
109
|
+
})
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error('[Nuxt Spec] Error updating \'nuxt.config.ts\':\n', error.message)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 3) `pnpm-workspace.yaml` file (only if pnpm is used)
|
|
115
|
+
if (packageManager === 'pnpm') {
|
|
116
|
+
try {
|
|
117
|
+
if (pathExists({ targetPath: 'pnpm-workspace.yaml' })) {
|
|
118
|
+
await updateTextFile({
|
|
119
|
+
targetFile: 'pnpm-workspace.yaml',
|
|
120
|
+
rowsToAdd: ['shamefullyHoist: true'],
|
|
121
|
+
force: isAutoRun,
|
|
122
|
+
prompt: '[Nuxt Spec] This will adjust \'pnpm-workspace.yaml\' file in your project. Continue?',
|
|
123
|
+
})
|
|
124
|
+
} else {
|
|
125
|
+
await createFileFromWebTemplate({
|
|
126
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/config/templates/pnpm-workspace.yaml.template`,
|
|
127
|
+
targetFile: 'pnpm-workspace.yaml',
|
|
128
|
+
force: isAutoRun,
|
|
129
|
+
prompt: '[Nuxt Spec] This will add \'pnpm-workspace.yaml\' file for your project. Continue?',
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
} catch (error) {
|
|
133
|
+
console.error('[Nuxt Spec] Error setting up \'pnpm-workspace.yaml\':\n', error.message)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 4) create vitest.config.ts
|
|
138
|
+
try {
|
|
139
|
+
await createFileFromWebTemplate({
|
|
140
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/config/templates/vitest.config.ts.template`,
|
|
141
|
+
targetFile: 'vitest.config.ts',
|
|
142
|
+
force: isAutoRun,
|
|
143
|
+
prompt: '[Nuxt Spec] This will create a new \'vitest.config.ts\' file for your project. Continue?',
|
|
144
|
+
})
|
|
145
|
+
} catch (error) {
|
|
146
|
+
console.error('[Nuxt Spec] Error setting up \'vitest.config.ts\':\n', error.message)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 5) create .nuxtrc to prevent @nuxt/test-utils setup from running automatically on first start
|
|
150
|
+
if (!pathExists({ targetPath: '.nuxtrc' })) {
|
|
151
|
+
try {
|
|
152
|
+
await createFileFromWebTemplate({
|
|
153
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/.nuxtrc`,
|
|
154
|
+
targetFile: '.nuxtrc',
|
|
155
|
+
force: isAutoRun,
|
|
156
|
+
prompt: '[Nuxt Spec] This will create a \'.nuxtrc\' file to prevent @nuxt/test-utils setup from running automatically when dev server starts. Continue?',
|
|
157
|
+
})
|
|
158
|
+
} catch (error) {
|
|
159
|
+
console.error('[Nuxt Spec] Error creating \'.nuxtrc\':\n', error.message)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 6) modify package.json with test scripts
|
|
164
|
+
try {
|
|
165
|
+
await updateJsonFile({
|
|
166
|
+
targetFile: 'package.json',
|
|
167
|
+
jsonKey: 'scripts',
|
|
168
|
+
patch: {
|
|
169
|
+
'test': 'vitest run',
|
|
170
|
+
'test-u': 'vitest run -u',
|
|
171
|
+
'test-i': 'vitest',
|
|
172
|
+
},
|
|
173
|
+
force: isAutoRun,
|
|
174
|
+
prompt: '[Nuxt Spec] This will adjust the test-related commands in your \'package.json\'. Continue?',
|
|
175
|
+
})
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error('[Nuxt Spec] Error adjusting scripts in \'package.json\':\n', error.message)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 7) create sample test files
|
|
181
|
+
const createSampleTests = isAutoRun || await promptUser({ question: '[Nuxt Spec] Do you want to create sample tests in \'/test\' folder?' })
|
|
182
|
+
if (createSampleTests) {
|
|
183
|
+
try {
|
|
184
|
+
await createFileFromWebTemplate({
|
|
185
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/browser/vitest-browser.test.ts`,
|
|
186
|
+
targetFile: 'test/browser/vitest-browser.test.ts',
|
|
187
|
+
force: true,
|
|
188
|
+
})
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error('[Nuxt Spec] Error setting up \'vitest-browser.test.ts\':\n', error.message)
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
await createFileFromWebTemplate({
|
|
194
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/nuxt-e2e.test.ts`,
|
|
195
|
+
targetFile: 'test/e2e/nuxt-e2e.test.ts',
|
|
196
|
+
force: true,
|
|
197
|
+
})
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error('[Nuxt Spec] Error setting up \'nuxt-e2e.test.ts\':\n', error.message)
|
|
200
|
+
}
|
|
201
|
+
try {
|
|
202
|
+
await createFileFromWebTemplate({
|
|
203
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/nuxt-visual.test.ts`,
|
|
204
|
+
targetFile: 'test/e2e/nuxt-visual.test.ts',
|
|
205
|
+
force: true,
|
|
206
|
+
})
|
|
207
|
+
} catch (error) {
|
|
208
|
+
console.error('[Nuxt Spec] Error setting up \'nuxt-visual.test.ts\':\n', error.message)
|
|
209
|
+
}
|
|
210
|
+
// pre-existing baseline ensures the sample "wrong" visual test fails as intended
|
|
211
|
+
try {
|
|
212
|
+
await createFileFromWebTemplate({
|
|
213
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/e2e/__baseline__/wrong.png`,
|
|
214
|
+
targetFile: 'test/e2e/__baseline__/wrong.png',
|
|
215
|
+
force: true,
|
|
216
|
+
})
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error('[Nuxt Spec] Error setting up \'wrong.png\':\n', error.message)
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
await createFileFromWebTemplate({
|
|
222
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/nuxt/nuxt-unit.test.ts`,
|
|
223
|
+
targetFile: 'test/nuxt/nuxt-unit.test.ts',
|
|
224
|
+
force: true,
|
|
225
|
+
})
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error('[Nuxt Spec] Error setting up \'nuxt-unit.test.ts\':\n', error.message)
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
await createFileFromWebTemplate({
|
|
231
|
+
url: `https://raw.githubusercontent.com/AloisSeckar/nuxt-spec/refs/tags/v${TARGET_VERSION}/test/unit/vitest-unit.test.ts`,
|
|
232
|
+
targetFile: 'test/unit/vitest-unit.test.ts',
|
|
233
|
+
force: true,
|
|
234
|
+
})
|
|
235
|
+
} catch (error) {
|
|
236
|
+
console.error('[Nuxt Spec] Error setting up \'vitest-unit.test.ts\':\n', error.message)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// 8) add nuxt-spec related entries to .gitignore
|
|
241
|
+
try {
|
|
242
|
+
const gitignoreEntries = [
|
|
243
|
+
['# vitest output folder', '.vitest'],
|
|
244
|
+
['# nuxt-spec screenshots folder', '__current__'],
|
|
245
|
+
['# nuxt-spec HTML test reports folder', '__reports__'],
|
|
246
|
+
]
|
|
247
|
+
// if .gitignore exists, we rather check for duplicates
|
|
248
|
+
const gitignoreExists = pathExists({ targetPath: '.gitignore' })
|
|
249
|
+
const gitignoreRows = gitignoreExists ? readFileSync('.gitignore', 'utf8').split(/\r?\n/) : []
|
|
250
|
+
const rowsToAdd = gitignoreEntries
|
|
251
|
+
.filter(([, entry]) => !gitignoreRows.includes(entry))
|
|
252
|
+
.flatMap(([comment, entry]) => ['', comment, entry])
|
|
253
|
+
.slice(gitignoreExists ? 0 : 1)
|
|
254
|
+
//
|
|
255
|
+
if (rowsToAdd.length > 0) {
|
|
256
|
+
await updateTextFile({
|
|
257
|
+
targetFile: '.gitignore',
|
|
258
|
+
rowsToAdd,
|
|
259
|
+
allowDuplicates: true,
|
|
260
|
+
createMissing: true,
|
|
261
|
+
force: isAutoRun,
|
|
262
|
+
prompt: '[Nuxt Spec] This will add nuxt-spec related entries to your \'.gitignore\' file. Continue?',
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.error('[Nuxt Spec] Error updating \'.gitignore\':\n', error.message)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 9) clear node_modules and lock file(s)
|
|
270
|
+
const prepareForReinstall = isAutoRun || await promptUser({ question: '[Nuxt Spec] Dependencies should be re-installed now. Do you want to remove node_modules and the lock file?' })
|
|
271
|
+
if (prepareForReinstall) {
|
|
272
|
+
if (pathExists({ targetPath: 'node_modules' })) {
|
|
273
|
+
try {
|
|
274
|
+
await deletePath({ targetPath: 'node_modules', force: true })
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.error('[Nuxt Spec] Error deleting \'node_modules\':\n', error.message)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (pathExists({ targetPath: 'package-lock.json' })) {
|
|
280
|
+
try {
|
|
281
|
+
await deletePath({ targetPath: 'package-lock.json', force: true })
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.error('[Nuxt Spec] Error deleting \'package-lock.json\':\n', error.message)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (pathExists({ targetPath: 'pnpm-lock.yaml' })) {
|
|
287
|
+
try {
|
|
288
|
+
await deletePath({ targetPath: 'pnpm-lock.yaml', force: true })
|
|
289
|
+
} catch (error) {
|
|
290
|
+
console.error('[Nuxt Spec] Error deleting \'pnpm-lock.yaml\':\n', error.message)
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (pathExists({ targetPath: 'yarn.lock' })) {
|
|
294
|
+
try {
|
|
295
|
+
await deletePath({ targetPath: 'yarn.lock', force: true })
|
|
296
|
+
} catch (error) {
|
|
297
|
+
console.error('[Nuxt Spec] Error deleting \'yarn.lock\':\n', error.message)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (pathExists({ targetPath: 'bun.lockb' })) {
|
|
301
|
+
try {
|
|
302
|
+
await deletePath({ targetPath: 'bun.lockb', force: true })
|
|
303
|
+
} catch (error) {
|
|
304
|
+
console.error('[Nuxt Spec] Error deleting \'bun.lockb\':\n', error.message)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (pathExists({ targetPath: 'deno.lock' })) {
|
|
308
|
+
try {
|
|
309
|
+
await deletePath({ targetPath: 'deno.lock', force: true })
|
|
310
|
+
} catch (error) {
|
|
311
|
+
console.error('[Nuxt Spec] Error deleting \'deno.lock\':\n', error.message)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// 10) run install command
|
|
317
|
+
const runInstall = isAutoRun || await promptUser({ question: `[Nuxt Spec] Fresh \`${packageManager} install\` is required. Do you want to run it now?` })
|
|
318
|
+
if (runInstall) {
|
|
319
|
+
try {
|
|
320
|
+
showMessage({ message: `Running \`${packageManager} install\`...` })
|
|
321
|
+
execSync(`${packageManager} install`, { stdio: 'inherit' })
|
|
322
|
+
} catch (error) {
|
|
323
|
+
console.error(`[Nuxt Spec] Error running \`${packageManager} install\`:\n`, error.message)
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// 11) run Nuxt prepare command to generate types and auto-imports
|
|
328
|
+
const prepareCmd = getPrepareCmd(packageManager)
|
|
329
|
+
const runPrepare = isAutoRun || await promptUser({ question: `[Nuxt Spec] Nuxt needs to generate types and auto-imports before the project is fully usable. Do you want to run \`${prepareCmd}\` now?` })
|
|
330
|
+
if (runPrepare) {
|
|
331
|
+
try {
|
|
332
|
+
showMessage({ message: `Running \`${prepareCmd}\`...` })
|
|
333
|
+
execSync(prepareCmd, { stdio: 'inherit' })
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.error(`[Nuxt Spec] Error running \`${prepareCmd}\`:\n`, error.message)
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 12) run Playwright browser install command
|
|
340
|
+
const playwrightInstallCmd = getPlaywrightInstallCmd(packageManager)
|
|
341
|
+
const runPlaywrightInstall = isAutoRun || await promptUser({ question: `[Nuxt Spec] Playwright browser runtimes might need to be installed locally for e2e tests. Do you want to run \`${playwrightInstallCmd}\` now?` })
|
|
342
|
+
if (runPlaywrightInstall) {
|
|
343
|
+
try {
|
|
344
|
+
showMessage({ message: `Running \`${playwrightInstallCmd}\`...` })
|
|
345
|
+
execSync(playwrightInstallCmd, { stdio: 'inherit' })
|
|
346
|
+
} catch (error) {
|
|
347
|
+
console.error(`[Nuxt Spec] Error running \`${playwrightInstallCmd}\`:\n`, error.message)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// 13) inform user
|
|
352
|
+
showMessage({ message: '' })
|
|
353
|
+
showMessage({ message: 'NUXT SPEC SETUP COMPLETE', linesAfter: 2 })
|
|
354
|
+
if (!runInstall) {
|
|
355
|
+
showMessage({ message: `Proceed with \`${packageManager} install\` to install dependencies.` })
|
|
356
|
+
}
|
|
357
|
+
if (!runPrepare) {
|
|
358
|
+
showMessage({ message: `Run \`${prepareCmd}\` to generate the required Nuxt types and auto-imports.` })
|
|
359
|
+
}
|
|
360
|
+
if (!runPlaywrightInstall) {
|
|
361
|
+
showMessage({ message: `Run \`${playwrightInstallCmd}\` to setup the Playwright browser runtimes for e2e tests.` })
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// force exit to prevent #20
|
|
365
|
+
process.exit(0)
|
|
366
|
+
}
|