nuxt-spec 0.3.4 → 0.4.0-alpha.2

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.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +13 -13
  3. package/app/app.vue +10 -10
  4. package/app/components/NuxtSpecApiTestComponent.vue +24 -24
  5. package/app/components/NuxtSpecTestComponent.vue +9 -9
  6. package/app/components/index.d.ts +7 -7
  7. package/app/components/index.ts +2 -2
  8. package/app/utils/vitest-utils.ts +5 -5
  9. package/bin/_internal/prepublish-check.js +16 -16
  10. package/bin/cli.js +53 -44
  11. package/bin/commands/ci.js +124 -0
  12. package/bin/commands/setup.js +367 -0
  13. package/bin/commands/update.js +126 -0
  14. package/bin/helpers/commands.js +82 -82
  15. package/bin/helpers/constants.js +8 -0
  16. package/bin/helpers/git.js +73 -0
  17. package/config/index.d.ts +36 -33
  18. package/config/index.mjs +147 -132
  19. package/config/report/report-entry.html +6 -0
  20. package/config/report/report-head.html +34 -0
  21. package/{utils/screenshot/report-entry.html → config/report/report-screenshot.html} +8 -8
  22. package/config/report/report-tail.html +4 -0
  23. package/config/templates/.github/workflows/ci-test-update.yml.template +105 -0
  24. package/config/templates/.github/workflows/ci-test-verify.yml.template +68 -0
  25. package/config/templates/.gitlab/ci/ci-test-update.yml.template +69 -0
  26. package/config/templates/.gitlab/ci/ci-test-verify.yml.template +41 -0
  27. package/config/templates/.gitlab-ci.yml.template +6 -0
  28. package/config/templates/pnpm-workspace.yaml.template +19 -19
  29. package/config/templates/vitest.config.ts.template +5 -5
  30. package/config/utils/merge.mjs +43 -43
  31. package/config/utils/options.d.mts +59 -0
  32. package/config/utils/options.mjs +116 -0
  33. package/config/utils/reporter.mjs +409 -0
  34. package/config/utils/warnings.mjs +38 -33
  35. package/modules/spec-options.ts +23 -0
  36. package/nuxt.config.ts +20 -24
  37. package/package.json +37 -31
  38. package/utils/e2e.ts +131 -131
  39. package/utils/helpers/check-params.ts +44 -41
  40. package/utils/helpers/location-hint.ts +30 -30
  41. package/utils/helpers/screenshot-utils.ts +27 -0
  42. package/utils/index.ts +12 -12
  43. package/utils/playwright.ts +28 -20
  44. package/utils/screenshot.ts +201 -172
  45. package/bin/setup.js +0 -287
  46. package/bin/update.js +0 -94
  47. package/utils/screenshot/report-head.html +0 -24
  48. package/utils/screenshot/report-tail.html +0 -4
  49. package/utils/screenshot/report-utils.ts +0 -236
@@ -0,0 +1,409 @@
1
+ // HTML test report for Nuxt Spec
2
+ // - `NuxtSpecHtmlReporter` is a Vitest reporter that renders a self-contained HTML file
3
+ // into `<root>/test/__reports__/report-YYYYMMDDHHMMSS.html` after each test run
4
+ // - `nuxtSpecReportPlugin` is a Vite plugin that appends the reporter to whatever reporters
5
+ // are in effect (CLI `--reporter`, user config or Vitest defaults)
6
+ // - `open` option (always|failed|never) controls opening the report in browser
7
+
8
+ import { exec } from 'node:child_process'
9
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
10
+ import { platform } from 'node:os'
11
+ import { relative, resolve } from 'node:path'
12
+ import { fileURLToPath, pathToFileURL } from 'node:url'
13
+
14
+ /** Artifact type recorded by `compareScreenshot` on mismatch */
15
+ export const SCREENSHOT_ARTIFACT_TYPE = 'nuxt-spec:screenshot'
16
+
17
+ /** Relative path (from Vitest root) where report files are stored */
18
+ export const REPORT_DIR = 'test/__reports__'
19
+
20
+ const OPEN_MODES = ['always', 'failed', 'never']
21
+
22
+ // marker used to identify the reporter instance even if this module is loaded more than once
23
+ const REPORTER_MARK = Symbol.for('nuxt-spec:html-reporter')
24
+
25
+ const templatesDir = fileURLToPath(new URL('../report/', import.meta.url))
26
+ const loadTemplate = name => readFileSync(resolve(templatesDir, name), 'utf-8')
27
+
28
+ /**
29
+ * Vite plugin that registers `NuxtSpecHtmlReporter`.
30
+ * The `configureVitest` hook runs after Vitest merged CLI and config reporters,
31
+ * but before reporters are instantiated, so the HTML reporter is always appended.
32
+ * @param {ReporterOptions} [options] - reporter options
33
+ */
34
+ export function nuxtSpecReportPlugin(options = {}) {
35
+ return {
36
+ name: 'nuxt-spec:html-report',
37
+ configureVitest({ vitest }) {
38
+ addReporter(vitest.config, options)
39
+ },
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Append the Nuxt Spec HTML reporter into resolved Vitest config.
45
+ * The hook is called once per project, so duplicates must be avoided.
46
+ * @param {{ reporters?: unknown[] }} config - resolved Vitest config
47
+ * @param {ReporterOptions} [options] - reporter options
48
+ */
49
+ export function addReporter(config, options = {}) {
50
+ config.reporters ??= []
51
+ if (config.reporters.some(r => r?.[REPORTER_MARK])) return
52
+ config.reporters.push(new NuxtSpecHtmlReporter(options))
53
+ }
54
+
55
+ /**
56
+ * @typedef {{ open?: string }} ReporterOptions
57
+ */
58
+
59
+ export class NuxtSpecHtmlReporter {
60
+ [REPORTER_MARK] = true
61
+
62
+ /** @param {ReporterOptions} [options] */
63
+ constructor({ open } = {}) {
64
+ this.open = open
65
+ }
66
+
67
+ onInit(vitest) {
68
+ this.vitest = vitest
69
+ }
70
+
71
+ onTestRunStart() {
72
+ this.startedAt = new Date()
73
+ }
74
+
75
+ onTestRunEnd(testModules, unhandledErrors, reason) {
76
+ const startedAt = this.startedAt ?? new Date()
77
+ const root = this.vitest?.config?.root ?? process.cwd()
78
+ const watch = !!this.vitest?.config?.watch
79
+ const log = (msg) => {
80
+ if (this.vitest?.logger) this.vitest.logger.log(msg)
81
+ else console.log(msg)
82
+ }
83
+
84
+ const data = collectReportData(testModules, unhandledErrors, reason, root)
85
+ const html = renderReport(data, reportTimestamp(startedAt, true), new Date().toISOString())
86
+
87
+ const reportDir = resolve(root, REPORT_DIR)
88
+ const reportPath = resolve(reportDir, `report-${reportTimestamp(startedAt)}.html`)
89
+ try {
90
+ mkdirSync(reportDir, { recursive: true })
91
+ writeFileSync(reportPath, html)
92
+ } catch (error) {
93
+ log(`\n[Nuxt Spec] Failed to write HTML report: ${error?.message ?? error}`)
94
+ return
95
+ }
96
+
97
+ log(`\n[Nuxt Spec] Test report available at:\n${pathToFileURL(reportPath).href}`)
98
+
99
+ const shouldOpen = shouldOpenReport({
100
+ mode: this.open,
101
+ hasFailure: data.hasFailure,
102
+ ci: !!process.env.CI,
103
+ watch,
104
+ })
105
+ if (shouldOpen) {
106
+ log('[Nuxt Spec] Opening report in default browser...')
107
+ openInBrowser(reportPath, () => log('[Nuxt Spec] Failed to automatically open report'))
108
+ }
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Decide whether the report should be opened in the default browser.
114
+ * Never opens in CI or watch mode. Invalid `mode` falls back to `failed`.
115
+ * @param {{ mode?: string, hasFailure: boolean, ci: boolean, watch: boolean }} options
116
+ */
117
+ export function shouldOpenReport({ mode, hasFailure, ci, watch }) {
118
+ if (ci || watch) return false
119
+ const normalized = mode?.trim().toLowerCase() || 'failed'
120
+ const effective = OPEN_MODES.includes(normalized) ? normalized : 'failed'
121
+ if (effective === 'always') return true
122
+ if (effective === 'never') return false
123
+ return hasFailure
124
+ }
125
+
126
+ /**
127
+ * @typedef {{ message: string, diff?: string, stack?: string }} ReportError
128
+ * @typedef {{ fileName: string, message: string, baselineUri?: string, actualUri?: string }} ReportScreenshot
129
+ * @typedef {{ project: string, file: string, name: string, errors: ReportError[], screenshots: ReportScreenshot[] }} ReportFailure
130
+ * @typedef {{ project: string, file: string, suite: string, errors: ReportError[] }} ReportModuleError
131
+ * @typedef {{
132
+ * total: number,
133
+ * passed: number,
134
+ * failed: number,
135
+ * skipped: number,
136
+ * reason: 'passed' | 'failed' | 'interrupted',
137
+ * failures: ReportFailure[],
138
+ * moduleErrors: ReportModuleError[],
139
+ * unhandledErrors: ReportError[],
140
+ * hasFailure: boolean,
141
+ * }} ReportData
142
+ */
143
+
144
+ /**
145
+ * Transform Vitest reported entities into plain report data.
146
+ * @param {ReadonlyArray<any>} testModules - `TestModule` instances from `onTestRunEnd`
147
+ * @param {ReadonlyArray<any>} unhandledErrors - serialized unhandled errors
148
+ * @param {'passed' | 'failed' | 'interrupted'} reason - run end reason
149
+ * @param {string} root - project root used to compute relative paths
150
+ * @returns {ReportData}
151
+ */
152
+ export function collectReportData(testModules, unhandledErrors, reason, root) {
153
+ /** @type {ReportData} */
154
+ const data = {
155
+ total: 0,
156
+ passed: 0,
157
+ failed: 0,
158
+ skipped: 0,
159
+ reason,
160
+ failures: [],
161
+ moduleErrors: [],
162
+ unhandledErrors: (unhandledErrors ?? []).map(toErrorData),
163
+ hasFailure: false,
164
+ }
165
+
166
+ for (const testModule of testModules ?? []) {
167
+ const project = testModule.project?.name || ''
168
+ const file = toRelative(root, testModule.moduleId)
169
+
170
+ // errors outside of tests - module collection errors or failed `beforeAll`/`afterAll` hooks
171
+ const moduleErrors = testModule.errors?.() ?? []
172
+ if (moduleErrors.length > 0) {
173
+ data.moduleErrors.push({ project, file, suite: '', errors: moduleErrors.map(toErrorData) })
174
+ }
175
+ for (const testSuite of testModule.children?.allSuites() ?? []) {
176
+ const suiteErrors = testSuite.errors?.() ?? []
177
+ if (suiteErrors.length > 0) {
178
+ data.moduleErrors.push({ project, file, suite: testSuite.fullName ?? testSuite.name, errors: suiteErrors.map(toErrorData) })
179
+ }
180
+ }
181
+
182
+ for (const testCase of testModule.children?.allTests() ?? []) {
183
+ const result = testCase.result()
184
+ if (result.state === 'skipped') {
185
+ data.skipped++
186
+ continue
187
+ }
188
+ data.total++
189
+ if (result.state === 'passed') {
190
+ data.passed++
191
+ } else if (result.state === 'failed') {
192
+ data.failed++
193
+ data.failures.push({
194
+ project,
195
+ file,
196
+ name: testCase.fullName ?? testCase.name,
197
+ errors: (result.errors ?? []).map(toErrorData),
198
+ screenshots: (testCase.artifacts?.() ?? [])
199
+ .filter(a => a?.type === SCREENSHOT_ARTIFACT_TYPE)
200
+ .map(toScreenshotData),
201
+ })
202
+ }
203
+ }
204
+ }
205
+
206
+ data.hasFailure = data.failed > 0
207
+ || data.moduleErrors.length > 0
208
+ || data.unhandledErrors.length > 0
209
+ || reason !== 'passed'
210
+
211
+ return data
212
+ }
213
+
214
+ /**
215
+ * Render report data (see `collectReportData`) into a self-contained HTML document.
216
+ * @param {ReportData} data
217
+ * @param {string} titleTimestamp - timestamp displayed in the report title
218
+ * @param {string} footerTimestamp - timestamp displayed in the report footer
219
+ */
220
+ export function renderReport(data, titleTimestamp, footerTimestamp) {
221
+ const entries = []
222
+
223
+ for (const failure of data.failures) {
224
+ entries.push(renderEntry({
225
+ title: failure.name,
226
+ location: formatLocation(failure.project, failure.file),
227
+ errors: failure.errors,
228
+ screenshots: failure.screenshots,
229
+ }))
230
+ }
231
+
232
+ for (const moduleError of data.moduleErrors) {
233
+ entries.push(renderEntry({
234
+ title: moduleError.suite ? `Error in suite: ${moduleError.suite}` : 'Error in test module',
235
+ location: formatLocation(moduleError.project, moduleError.file),
236
+ errors: moduleError.errors,
237
+ }))
238
+ }
239
+
240
+ for (const error of data.unhandledErrors) {
241
+ entries.push(renderEntry({
242
+ title: 'Unhandled error',
243
+ location: 'Error was thrown outside of a test',
244
+ errors: [error],
245
+ }))
246
+ }
247
+
248
+ const head = fillTemplate(loadTemplate('report-head.html'), {
249
+ TIMESTAMP: escapeHtml(titleTimestamp),
250
+ STATUS: data.hasFailure ? 'failed' : 'passed',
251
+ SUMMARY: escapeHtml(formatSummary(data)),
252
+ })
253
+ const tail = fillTemplate(loadTemplate('report-tail.html'), {
254
+ TIMESTAMP: escapeHtml(footerTimestamp),
255
+ })
256
+
257
+ return head + entries.join('') + tail
258
+ }
259
+
260
+ /**
261
+ * Build the one-line summary, e.g. `5/5 tests passed` or `3/5 tests passed, 2 failed`.
262
+ * @param {ReportData} data
263
+ */
264
+ export function formatSummary(data) {
265
+ const parts = [`${data.passed}/${data.total} tests passed`]
266
+ if (data.failed > 0) parts.push(`${data.failed} failed`)
267
+ if (data.skipped > 0) parts.push(`${data.skipped} skipped`)
268
+ if (data.moduleErrors.length > 0) parts.push(`${data.moduleErrors.length} module/suite error(s)`)
269
+ if (data.unhandledErrors.length > 0) parts.push(`${data.unhandledErrors.length} unhandled error(s)`)
270
+ let summary = parts.join(', ')
271
+ if (data.reason === 'interrupted') summary += ' (test run was interrupted)'
272
+ else if (data.hasFailure && data.failed === 0 && data.moduleErrors.length === 0 && data.unhandledErrors.length === 0) {
273
+ summary += ' (test run failed)'
274
+ }
275
+ return summary
276
+ }
277
+
278
+ function renderEntry({ title, location, errors, screenshots = [] }) {
279
+ return fillTemplate(loadTemplate('report-entry.html'), {
280
+ TITLE: escapeHtml(title),
281
+ LOCATION: escapeHtml(location),
282
+ ERRORS: errors.map(renderError).join('\n'),
283
+ SCREENSHOTS: screenshots.map(renderScreenshot).join('\n'),
284
+ })
285
+ }
286
+
287
+ function renderError(error) {
288
+ let html = `<pre class="message">${escapeHtml(error.message)}</pre>`
289
+ if (error.diff) {
290
+ html += `<details open><summary>Diff</summary><pre class="diff">${escapeHtml(error.diff)}</pre></details>`
291
+ }
292
+ if (error.stack) {
293
+ html += `<details><summary>Stack trace</summary><pre class="stack">${escapeHtml(error.stack)}</pre></details>`
294
+ }
295
+ return html
296
+ }
297
+
298
+ function renderScreenshot(screenshot) {
299
+ // attachments may be missing (e.g. stripped by Vitest), show at least the message
300
+ if (!screenshot.baselineUri || !screenshot.actualUri) {
301
+ return `<div class="screenshot"><h3>${escapeHtml(screenshot.fileName)}</h3><p class="message">${escapeHtml(screenshot.message)}</p></div>`
302
+ }
303
+ return fillTemplate(loadTemplate('report-screenshot.html'), {
304
+ FILE_NAME: escapeHtml(screenshot.fileName),
305
+ MESSAGE: escapeHtml(screenshot.message),
306
+ BASELINE_URI: screenshot.baselineUri,
307
+ ACTUAL_URI: screenshot.actualUri,
308
+ })
309
+ }
310
+
311
+ function toErrorData(error) {
312
+ const name = error?.name && error.name !== 'Error' ? `${error.name}: ` : ''
313
+ return {
314
+ message: stripAnsi(`${name}${error?.message ?? String(error)}`),
315
+ diff: error?.diff ? stripAnsi(error.diff) : undefined,
316
+ stack: error?.stack ? stripAnsi(error.stack) : undefined,
317
+ }
318
+ }
319
+
320
+ function toScreenshotData(artifact) {
321
+ const attachments = artifact.attachments ?? []
322
+ const findUri = (name) => {
323
+ const attachment = attachments.find(a => a?.name === name)
324
+ if (!attachment?.body || typeof attachment.body !== 'string') return undefined
325
+ if (attachment.bodyEncoding === 'utf-8') return undefined
326
+ // only accept valid base64 payload and an image MIME type to keep the `src` attribute safe
327
+ if (!BASE64_REGEX.test(attachment.body)) return undefined
328
+ const contentType = IMAGE_MIME_REGEX.test(attachment.contentType ?? '') ? attachment.contentType : 'image/png'
329
+ return `data:${contentType};base64,${attachment.body}`
330
+ }
331
+ return {
332
+ fileName: artifact.fileName ?? '',
333
+ message: artifact.message ?? '',
334
+ baselineUri: findUri('baseline'),
335
+ actualUri: findUri('actual'),
336
+ }
337
+ }
338
+
339
+ function formatLocation(project, file) {
340
+ return project ? `[${project}] ${file}` : file
341
+ }
342
+
343
+ function toRelative(root, path) {
344
+ if (!path) return ''
345
+ const rel = relative(root, path)
346
+ return rel && !rel.startsWith('..') ? rel.replaceAll('\\', '/') : path
347
+ }
348
+
349
+ function openInBrowser(path, onError) {
350
+ const openCmd
351
+ = platform() === 'darwin'
352
+ ? `open "${path}"`
353
+ : platform() === 'win32'
354
+ ? `start "" "${path}"`
355
+ : `xdg-open "${path}"`
356
+ exec(openCmd, (err) => {
357
+ if (err) onError()
358
+ })
359
+ }
360
+
361
+ // replace `{{KEY}}` placeholders
362
+ // function replacer avoids special `$` patterns of String.replace
363
+ function fillTemplate(template, values) {
364
+ return template.replace(/\{\{(\w+)\}\}/g, (match, key) => key in values ? values[key] : match)
365
+ }
366
+
367
+ // timestamp string
368
+ // separators=false produces YYYYMMDDHHMMSS for report file name
369
+ // separators=true produces YYYY-MM-DD HH:MM:SS for report title
370
+ export function reportTimestamp(date, separators = false) {
371
+ const pad2 = n => String(n).padStart(2, '0')
372
+ const dateSeparator = separators ? '-' : ''
373
+ const midSeparator = separators ? ' ' : ''
374
+ const timeSeparator = separators ? ':' : ''
375
+ return [
376
+ date.getFullYear(),
377
+ dateSeparator,
378
+ pad2(date.getMonth() + 1),
379
+ dateSeparator,
380
+ pad2(date.getDate()),
381
+ midSeparator,
382
+ pad2(date.getHours()),
383
+ timeSeparator,
384
+ pad2(date.getMinutes()),
385
+ timeSeparator,
386
+ pad2(date.getSeconds()),
387
+ ].join('')
388
+ }
389
+
390
+ const BASE64_REGEX = /^[A-Za-z0-9+/]+={0,2}$/
391
+ const IMAGE_MIME_REGEX = /^image\/[a-z0-9.+-]+$/i
392
+
393
+ // eslint-disable-next-line no-control-regex
394
+ const ANSI_REGEX = /\u001B\[[0-9;?]*[ -/]*[@-~]/g
395
+
396
+ function stripAnsi(value) {
397
+ return String(value).replace(ANSI_REGEX, '')
398
+ }
399
+
400
+ // helper to escape a string for safe interpolation into the HTML report
401
+ function escapeHtml(value) {
402
+ return String(value ?? '').replace(/[&<>"']/g, char => ({
403
+ '&': '&amp;',
404
+ '<': '&lt;',
405
+ '>': '&gt;',
406
+ '"': '&quot;',
407
+ '\'': '&#39;',
408
+ }[char] ?? char))
409
+ }
@@ -1,33 +1,38 @@
1
- const messageFilters = [
2
- // Node+Windows false positive
3
- // https://github.com/nuxt/icon/issues/140
4
- 'Use of deprecated trailing slash pattern mapping',
5
- // remove once Vue stops considering <Suspense> experimental
6
- '<Suspense> is an experimental feature',
7
- // merge defaults with user-defined filters from NUXT_SPEC_MESSAGE_FILTERS env variable
8
- ...(process.env.NUXT_SPEC_MESSAGE_FILTERS
9
- ? process.env.NUXT_SPEC_MESSAGE_FILTERS.split(',')
10
- : []),
11
- ]
12
-
13
- // 1) filter-out unnecessary stderr/stdout logs coming from Vitest
14
- // (applied as side-effect on import)
15
-
16
- const _stderrWrite = process.stderr.write.bind(process.stderr)
17
- process.stderr.write = (chunk, ...args) => {
18
- if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
19
- return _stderrWrite(chunk, ...args)
20
- }
21
-
22
- const _stdoutWrite = process.stdout.write.bind(process.stdout)
23
- process.stdout.write = (chunk, ...args) => {
24
- if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
25
- return _stdoutWrite(chunk, ...args)
26
- }
27
-
28
- // 2) filter-out unnecessary console logs coming from Vitest
29
- // (used as Vitest onConsoleLog hook)
30
-
31
- export function onConsoleLog(log) {
32
- if (messageFilters.some(f => log.includes(f))) return false
33
- }
1
+ const messageFilters = [
2
+ // Node+Windows false positive
3
+ // https://github.com/nuxt/icon/issues/140
4
+ 'Use of deprecated trailing slash pattern mapping',
5
+ // remove once Vue stops considering <Suspense> experimental
6
+ '<Suspense> is an experimental feature',
7
+ ]
8
+
9
+ // merge user-defined filters (`spec.messageFilters` / NUXT_SPEC_MESSAGE_FILTERS) with defaults
10
+ export function addMessageFilters(filters) {
11
+ for (const filter of filters) {
12
+ if (filter && !messageFilters.includes(filter)) {
13
+ messageFilters.push(filter)
14
+ }
15
+ }
16
+ }
17
+
18
+ // 1) filter-out unnecessary stderr/stdout logs coming from Vitest
19
+ // (applied as side-effect on import)
20
+
21
+ const _stderrWrite = process.stderr.write.bind(process.stderr)
22
+ process.stderr.write = (chunk, ...args) => {
23
+ if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
24
+ return _stderrWrite(chunk, ...args)
25
+ }
26
+
27
+ const _stdoutWrite = process.stdout.write.bind(process.stdout)
28
+ process.stdout.write = (chunk, ...args) => {
29
+ if (typeof chunk === 'string' && messageFilters.some(f => chunk.includes(f))) return true
30
+ return _stdoutWrite(chunk, ...args)
31
+ }
32
+
33
+ // 2) filter-out unnecessary console logs coming from Vitest
34
+ // (used as Vitest onConsoleLog hook)
35
+
36
+ export function onConsoleLog(log) {
37
+ if (messageFilters.some(f => log.includes(f))) return false
38
+ }
@@ -0,0 +1,23 @@
1
+ import { defineNuxtModule } from 'nuxt/kit'
2
+ import type { ModuleDependencies, NuxtModule } from 'nuxt/schema'
3
+ import { resolveSpecOptions } from '../config/utils/options.mjs'
4
+ import type { NuxtSpecOptions } from '../config/utils/options.mjs'
5
+
6
+ // registers typed `spec` key for nuxt.config.ts and applies its Nuxt-related options
7
+ // options related to Vitest are resolved in `loadVitestConfig` (config/index.mjs)
8
+ // (explicit types break circular reference with module types generated by Nuxt)
9
+ const specOptionsModule: NuxtModule<NuxtSpecOptions> = defineNuxtModule<NuxtSpecOptions>({
10
+ meta: {
11
+ name: 'nuxt-spec',
12
+ configKey: 'spec',
13
+ // used as `@see` link in generated types (fallback would be a broken npm URL)
14
+ docs: 'https://nuxt-spec.netlify.app/2-1-configuration.html#nuxt-spec-options',
15
+ },
16
+ moduleDependencies: (nuxt): ModuleDependencies => {
17
+ // `spec` is typed only after Nuxt generates module types
18
+ const { spec } = nuxt.options as unknown as { spec?: NuxtSpecOptions | false }
19
+ return resolveSpecOptions(spec).hints ? { '@nuxt/hints': {} } : {}
20
+ },
21
+ })
22
+
23
+ export default specOptionsModule
package/nuxt.config.ts CHANGED
@@ -1,24 +1,20 @@
1
- // @nuxt/hints module is included by default
2
- // set NUXT_SPEC_HINTS_ENABLED=false to exclude it
3
- const hintsEnabled = process.env.NUXT_SPEC_HINTS_ENABLED !== 'false'
4
-
5
- export default defineNuxtConfig({
6
- modules: [
7
- '@nuxt/eslint',
8
- '@nuxt/test-utils/module',
9
- ...(hintsEnabled ? ['@nuxt/hints'] : []),
10
- ],
11
-
12
- // exclude file used for explicit exports (nuxt-spec/components) from Nuxt resolution
13
- components: {
14
- dirs: [{ path: '~/components', ignore: ['index.ts'] }],
15
- },
16
-
17
- compatibilityDate: '2026-08-08',
18
-
19
- eslint: {
20
- config: {
21
- stylistic: true,
22
- },
23
- },
24
- })
1
+ export default defineNuxtConfig({
2
+ modules: [
3
+ '@nuxt/eslint',
4
+ '@nuxt/test-utils/module',
5
+ // @nuxt/hints module is handled in `modules/spec-options.ts`
6
+ ],
7
+
8
+ // exclude file used for explicit exports (nuxt-spec/components) from Nuxt resolution
9
+ components: {
10
+ dirs: [{ path: '~/components', ignore: ['index.ts'] }],
11
+ },
12
+
13
+ compatibilityDate: '2026-10-13',
14
+
15
+ eslint: {
16
+ config: {
17
+ stylistic: true,
18
+ },
19
+ },
20
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-spec",
3
- "version": "0.3.4",
3
+ "version": "0.4.0-alpha.2",
4
4
  "description": "Test-pack layer for Nuxt Applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,6 +9,21 @@
9
9
  "license": "MIT",
10
10
  "type": "module",
11
11
  "main": "./nuxt.config.ts",
12
+ "scripts": {
13
+ "analyze": "nuxt analyze",
14
+ "eslint": "eslint .",
15
+ "typecheck": "nuxi typecheck",
16
+ "build": "nuxt build",
17
+ "dev": "nuxt dev",
18
+ "generate": "nuxt generate",
19
+ "prepublishOnly": "node bin/_internal/prepublish-check.js",
20
+ "preview": "nuxt preview",
21
+ "start": "nuxt start",
22
+ "test": "vitest run",
23
+ "test-u": "vitest run -u",
24
+ "test-c": "vitest run --coverage",
25
+ "test-i": "vitest"
26
+ },
12
27
  "bin": {
13
28
  "nuxt-spec": "bin/cli.js"
14
29
  },
@@ -33,45 +48,36 @@
33
48
  "app",
34
49
  "bin",
35
50
  "config",
51
+ "modules",
36
52
  "public",
37
53
  "utils",
38
54
  "nuxt.config.ts"
39
55
  ],
40
56
  "dependencies": {
57
+ "@nuxt/devtools": "4.0.0-beta.4",
41
58
  "@nuxt/eslint": "~1.17.0",
42
59
  "@nuxt/hints": "1.1.4",
43
- "@nuxt/test-utils": "4.2.0",
44
- "@vitejs/plugin-vue": "~6.0.8",
45
- "@vitest/browser": "4.1.11",
46
- "@vitest/browser-playwright": "4.1.11",
47
- "@vitest/ui": "4.1.11",
48
- "@vue/test-utils": "2.5.0",
49
- "elrh-cosca": "0.3.6",
60
+ "@nuxt/test-utils": "4.3.3",
61
+ "@vitejs/plugin-vue": "~6.0.9",
62
+ "@vitest/browser": "5.0.3",
63
+ "@vitest/browser-playwright": "5.0.3",
64
+ "@vitest/coverage-istanbul": "5.0.3",
65
+ "@vitest/coverage-v8": "5.0.3",
66
+ "@vitest/ui": "5.0.3",
67
+ "@vue/test-utils": "2.5.1",
68
+ "elrh-cosca": "0.4.3",
50
69
  "fast-png": "~8.0.0",
51
- "h3-next": "npm:h3@~2.0.1-rc.31",
52
- "happy-dom": "~20.14.0",
53
- "nuxt": "4.5.2",
70
+ "happy-dom": "~20.14.5",
71
+ "nuxt": "4.6.1",
54
72
  "pixelmatch": "~7.2.0",
55
- "playwright": "~1.62.1",
56
- "playwright-core": "~1.62.1",
73
+ "playwright": "~1.64.0",
74
+ "playwright-core": "~1.64.0",
57
75
  "typescript": "~6.0.3",
58
- "vitest": "4.1.11",
59
- "vitest-browser-vue": "2.1.0",
60
- "vue": "~3.5.42",
76
+ "vitest": "5.0.3",
77
+ "vitest-browser-vue": "3.1.0",
78
+ "vue": "~3.5.43",
61
79
  "vue-router": "~5.3.1",
62
- "vue-tsc": "~3.3.11"
80
+ "vue-tsc": "~3.3.12"
63
81
  },
64
- "scripts": {
65
- "analyze": "nuxt analyze",
66
- "eslint": "eslint .",
67
- "typecheck": "nuxi typecheck",
68
- "build": "nuxt build",
69
- "dev": "nuxt dev",
70
- "generate": "nuxt generate",
71
- "preview": "nuxt preview",
72
- "start": "nuxt start",
73
- "test": "vitest run",
74
- "test-u": "vitest run -u",
75
- "test-i": "vitest"
76
- }
77
- }
82
+ "packageManager": "pnpm@12.11.2"
83
+ }