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.
Files changed (39) 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 +44 -44
  11. package/bin/helpers/commands.js +82 -82
  12. package/bin/setup.js +366 -287
  13. package/bin/update.js +94 -94
  14. package/config/index.d.ts +36 -33
  15. package/config/index.mjs +140 -132
  16. package/config/report/report-entry.html +6 -0
  17. package/config/report/report-head.html +34 -0
  18. package/{utils/screenshot/report-entry.html → config/report/report-screenshot.html} +8 -8
  19. package/config/report/report-tail.html +4 -0
  20. package/config/templates/pnpm-workspace.yaml.template +19 -19
  21. package/config/templates/vitest.config.ts.template +5 -5
  22. package/config/utils/merge.mjs +43 -43
  23. package/config/utils/options.d.mts +59 -0
  24. package/config/utils/options.mjs +116 -0
  25. package/config/utils/reporter.mjs +409 -0
  26. package/config/utils/warnings.mjs +38 -33
  27. package/modules/spec-options.ts +23 -0
  28. package/nuxt.config.ts +20 -24
  29. package/package.json +33 -31
  30. package/utils/e2e.ts +131 -131
  31. package/utils/helpers/check-params.ts +44 -41
  32. package/utils/helpers/location-hint.ts +30 -30
  33. package/utils/helpers/screenshot-utils.ts +27 -0
  34. package/utils/index.ts +12 -12
  35. package/utils/playwright.ts +28 -20
  36. package/utils/screenshot.ts +201 -172
  37. package/utils/screenshot/report-head.html +0 -24
  38. package/utils/screenshot/report-tail.html +0 -4
  39. package/utils/screenshot/report-utils.ts +0 -236
package/bin/update.js CHANGED
@@ -1,94 +1,94 @@
1
- #!/usr/bin/env node
2
-
3
- import { execSync } from 'node:child_process'
4
- import {
5
- hasJsonKey, promptUser, showMessage,
6
- } from 'elrh-cosca'
7
- import {
8
- getPlaywrightInstallCmd, getPrepareCmd, getUpdateCmd,
9
- } from './helpers/commands.js'
10
-
11
- const TARGET_VERSION = '0.3.4'
12
-
13
- /**
14
- * CLI tool to update existing `nuxt-spec` installation.
15
- *
16
- * It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
17
- *
18
- * Then it:
19
- * 1) verifies `nuxt-spec` is present in `package.json` (fails with a hint to run `setup` otherwise)
20
- * 2) runs the package manager's update command to bump `nuxt-spec` to the latest version
21
- * 3) run the `nuxt prepare` command to regenerate types and auto-imports
22
- * 4) run the `playwright install` command to ensure the Playwright browser runtimes are up to date
23
- *
24
- * @param {boolean} autoRun - Whether to run the update automatically without any prompts (defaults to false).
25
- * @param {string} [packageManager] - Package manager to be used (`npm`, `pnpm`, `yarn`, `bun` or `deno`).
26
- */
27
- export async function specUpdate(autoRun = false, packageManager) {
28
- showMessage('NUXT SPEC UPDATE')
29
- showMessage('This CLI tool will help you update Nuxt Spec in your project.')
30
- showMessage('Refer to the documentation for more information.', 2)
31
-
32
- // fail fast if there is nothing to update
33
- const isInstalled = hasJsonKey('package.json', `dependencies.nuxt-spec`)
34
- || hasJsonKey('package.json', `devDependencies.nuxt-spec`)
35
- if (!isInstalled) {
36
- console.error(`'nuxt-spec' was not found in your 'package.json'. Run the 'setup' command first.`)
37
- process.exit(1)
38
- }
39
-
40
- const isAutoRun = autoRun || await promptUser('Do you want to update everything automatically (no more prompts)?')
41
- showMessage('')
42
-
43
- // 1) run 'update nuxt-spec'
44
- const updateCmd = getUpdateCmd(packageManager, `nuxt-spec@${TARGET_VERSION}`)
45
- const runUpdate = isAutoRun || await promptUser(`This will bump 'nuxt-spec' to version '${TARGET_VERSION}' by running \`${updateCmd}\`. Continue?`)
46
- if (runUpdate) {
47
- try {
48
- showMessage(`Running \`${updateCmd}\`...`)
49
- execSync(updateCmd, { stdio: 'inherit' })
50
- } catch (error) {
51
- console.error(`Error running \`${updateCmd}\`:\n`, error.message)
52
- }
53
- }
54
-
55
- // 2) run 'nuxt prepare'
56
- const prepareCmd = getPrepareCmd(packageManager)
57
- const runPrepare = isAutoRun || await promptUser(`Nuxt types and auto-imports should be regenerated after the update. Do you want to run \`${prepareCmd}\` now?`)
58
- if (runPrepare) {
59
- try {
60
- showMessage(`Running \`${prepareCmd}\`...`)
61
- execSync(prepareCmd, { stdio: 'inherit' })
62
- } catch (error) {
63
- console.error(`Error running \`${prepareCmd}\`:\n`, error.message)
64
- }
65
- }
66
-
67
- // 3) run 'playwright install'
68
- const playwrightUpdateCmd = getPlaywrightInstallCmd(packageManager)
69
- const runPlaywrightUpdate = isAutoRun || await promptUser(`Playwright browser runtimes might need to be updated for e2e tests. Do you want to run \`${playwrightUpdateCmd}\` now?`)
70
- if (runPlaywrightUpdate) {
71
- try {
72
- showMessage(`Running \`${playwrightUpdateCmd}\`...`)
73
- execSync(playwrightUpdateCmd, { stdio: 'inherit' })
74
- } catch (error) {
75
- console.error(`Error running \`${playwrightUpdateCmd}\`:\n`, error.message)
76
- }
77
- }
78
-
79
- // 4) inform user
80
- showMessage('')
81
- showMessage('NUXT SPEC UPDATE COMPLETE', 2)
82
- if (!runUpdate) {
83
- showMessage(`Run \`${updateCmd}\` to update 'nuxt-spec'.`)
84
- }
85
- if (!runPrepare) {
86
- showMessage(`Run \`${prepareCmd}\` to regenerate the Nuxt types and auto-imports.`)
87
- }
88
- if (!runPlaywrightUpdate) {
89
- showMessage(`Run \`${playwrightUpdateCmd}\` to update the Playwright browser runtimes for e2e tests.`)
90
- }
91
-
92
- // force exit to prevent #20
93
- process.exit(0)
94
- }
1
+ #!/usr/bin/env node
2
+
3
+ import { execSync } from 'node:child_process'
4
+ import {
5
+ hasJsonKey, promptUser, showMessage,
6
+ } from 'elrh-cosca'
7
+ import {
8
+ getPlaywrightInstallCmd, getPrepareCmd, getUpdateCmd,
9
+ } from './helpers/commands.js'
10
+
11
+ const TARGET_VERSION = '0.4.0-alpha.1'
12
+
13
+ /**
14
+ * CLI tool to update existing `nuxt-spec` installation.
15
+ *
16
+ * It first asks whether to run in "auto" mode (no prompts, force = true) or "manual" mode (with prompts, force = false).
17
+ *
18
+ * Then it:
19
+ * 1) verifies `nuxt-spec` is present in `package.json` (fails with a hint to run `setup` otherwise)
20
+ * 2) runs the package manager's update command to bump `nuxt-spec` to the latest version
21
+ * 3) run the `nuxt prepare` command to regenerate types and auto-imports
22
+ * 4) run the `playwright install` command to ensure the Playwright browser runtimes are up to date
23
+ *
24
+ * @param {boolean} autoRun - Whether to run the update automatically without any prompts (defaults to false).
25
+ * @param {string} [packageManager] - Package manager to be used (`npm`, `pnpm`, `yarn`, `bun` or `deno`).
26
+ */
27
+ export async function specUpdate(autoRun = false, packageManager) {
28
+ showMessage({ message: 'NUXT SPEC UPDATE' })
29
+ showMessage({ message: 'This CLI tool will help you update Nuxt Spec in your project.' })
30
+ showMessage({ message: 'Refer to the documentation for more information.', linesAfter: 2 })
31
+
32
+ // fail fast if there is nothing to update
33
+ const isInstalled = hasJsonKey({ targetFile: 'package.json', jsonKey: `dependencies.nuxt-spec` })
34
+ || hasJsonKey({ targetFile: 'package.json', jsonKey: `devDependencies.nuxt-spec` })
35
+ if (!isInstalled) {
36
+ console.error(`[Nuxt Spec] 'nuxt-spec' was not found in your 'package.json'. Run the 'setup' command first.`)
37
+ process.exit(1)
38
+ }
39
+
40
+ const isAutoRun = autoRun || await promptUser({ question: '[Nuxt Spec] Do you want to update everything automatically (no more prompts)?' })
41
+ showMessage({ message: '' })
42
+
43
+ // 1) run 'update nuxt-spec'
44
+ const updateCmd = getUpdateCmd(packageManager, `nuxt-spec@${TARGET_VERSION}`)
45
+ const runUpdate = isAutoRun || await promptUser({ question: `[Nuxt Spec] This will bump 'nuxt-spec' to version '${TARGET_VERSION}' by running \`${updateCmd}\`. Continue?` })
46
+ if (runUpdate) {
47
+ try {
48
+ showMessage({ message: `Running \`${updateCmd}\`...` })
49
+ execSync(updateCmd, { stdio: 'inherit' })
50
+ } catch (error) {
51
+ console.error(`[Nuxt Spec] Error running \`${updateCmd}\`:\n`, error.message)
52
+ }
53
+ }
54
+
55
+ // 2) run 'nuxt prepare'
56
+ const prepareCmd = getPrepareCmd(packageManager)
57
+ const runPrepare = isAutoRun || await promptUser({ question: `[Nuxt Spec] Nuxt types and auto-imports should be regenerated after the update. Do you want to run \`${prepareCmd}\` now?` })
58
+ if (runPrepare) {
59
+ try {
60
+ showMessage({ message: `Running \`${prepareCmd}\`...` })
61
+ execSync(prepareCmd, { stdio: 'inherit' })
62
+ } catch (error) {
63
+ console.error(`[Nuxt Spec] Error running \`${prepareCmd}\`:\n`, error.message)
64
+ }
65
+ }
66
+
67
+ // 3) run 'playwright install'
68
+ const playwrightUpdateCmd = getPlaywrightInstallCmd(packageManager)
69
+ const runPlaywrightUpdate = isAutoRun || await promptUser({ question: `[Nuxt Spec] Playwright browser runtimes might need to be updated for e2e tests. Do you want to run \`${playwrightUpdateCmd}\` now?` })
70
+ if (runPlaywrightUpdate) {
71
+ try {
72
+ showMessage({ message: `Running \`${playwrightUpdateCmd}\`...` })
73
+ execSync(playwrightUpdateCmd, { stdio: 'inherit' })
74
+ } catch (error) {
75
+ console.error(`[Nuxt Spec] Error running \`${playwrightUpdateCmd}\`:\n`, error.message)
76
+ }
77
+ }
78
+
79
+ // 4) inform user
80
+ showMessage({ message: '' })
81
+ showMessage({ message: 'NUXT SPEC UPDATE COMPLETE', linesAfter: 2 })
82
+ if (!runUpdate) {
83
+ showMessage({ message: `Run \`${updateCmd}\` to update 'nuxt-spec'.` })
84
+ }
85
+ if (!runPrepare) {
86
+ showMessage({ message: `Run \`${prepareCmd}\` to regenerate the Nuxt types and auto-imports.` })
87
+ }
88
+ if (!runPlaywrightUpdate) {
89
+ showMessage({ message: `Run \`${playwrightUpdateCmd}\` to update the Playwright browser runtimes for e2e tests.` })
90
+ }
91
+
92
+ // force exit to prevent #20
93
+ process.exit(0)
94
+ }
package/config/index.d.ts CHANGED
@@ -1,33 +1,36 @@
1
- import type { UserConfig } from 'vite'
2
- import type { TestUserConfig } from 'vitest/config'
3
-
4
- /** Typed Vite configuration object for tests */
5
- type ExtendedUserConfig = UserConfig & {
6
- test?: TestUserConfig
7
- }
8
-
9
- /**
10
- * Allows fine-grained control over default Vitest `projects`.
11
- *
12
- * By default, everything is included.
13
- * If set to `false`, `test.projects` key is not merged at all.
14
- * If set to object, specific projects can be omitted by setting respective key to `false`.
15
- */
16
- type ProjectsConfig = boolean | {
17
- default?: boolean
18
- unit?: boolean
19
- nuxt?: boolean
20
- e2e?: boolean
21
- browser?: boolean
22
- }
23
-
24
- /**
25
- * Prepare Vitest configuration object - user config merged with nuxt-spec defaults
26
- * @param userVitestConfig - custom Vitest config passed from the user
27
- * @param projects - allows fine-grained control over default `test.projects` - see `ProjectsConfig` for details
28
- * @returns Promise resolving to defu-merged Vitest configuration
29
- */
30
- export declare function loadVitestConfig(
31
- userVitestConfig: ExtendedUserConfig,
32
- projects?: ProjectsConfig,
33
- ): Promise<ExtendedUserConfig>
1
+ import type { UserConfig } from 'vite'
2
+ import type { TestUserConfig } from 'vitest/config'
3
+
4
+ export type { HtmlReportOpenMode, NuxtSpecOptions } from './utils/options.mjs'
5
+
6
+ /** Typed Vite configuration object for tests */
7
+ type ExtendedUserConfig = UserConfig & {
8
+ test?: TestUserConfig
9
+ }
10
+
11
+ /**
12
+ * Allows fine-grained control over default Vitest `projects`.
13
+ *
14
+ * By default, everything is included.
15
+ * If set to `false`, `test.projects` key is not merged at all.
16
+ * If set to object, specific projects can be omitted by setting respective key to `false`.
17
+ */
18
+ type ProjectsConfig = boolean | {
19
+ default?: boolean
20
+ unit?: boolean
21
+ nuxt?: boolean
22
+ e2e?: boolean
23
+ browser?: boolean
24
+ }
25
+
26
+ /**
27
+ * Prepare Vitest configuration object - user config merged with nuxt-spec defaults
28
+ * (defaults are adjusted by `spec` key from nuxt.config.ts and NUXT_SPEC_* env variables)
29
+ * @param userVitestConfig - custom Vitest config passed from the user
30
+ * @param projects - allows fine-grained control over default `test.projects` - see `ProjectsConfig` for details
31
+ * @returns Promise resolving to defu-merged Vitest configuration
32
+ */
33
+ export declare function loadVitestConfig(
34
+ userVitestConfig: ExtendedUserConfig,
35
+ projects?: ProjectsConfig,
36
+ ): Promise<ExtendedUserConfig>
package/config/index.mjs CHANGED
@@ -1,132 +1,140 @@
1
- // this is the default Vitest config object
2
- // based on https://nuxt.com/docs/4.x/getting-started/testing#setup
3
- // `projects=false` can be used to suspend the default usage of "projects" in Vitest config
4
-
5
- import { availableParallelism } from 'node:os'
6
- import { fileURLToPath } from 'node:url'
7
- import { onConsoleLog } from './utils/warnings.mjs' // filter out unnecessary logs
8
- import { mergeConfig } from './utils/merge.mjs' // defu-based merge function
9
- import { defineConfig } from 'vitest/config'
10
- import { defineVitestProject } from '@nuxt/test-utils/config'
11
- import { playwright } from '@vitest/browser-playwright'
12
- import vue from '@vitejs/plugin-vue'
13
-
14
- // absolute paths so it works from within the nuxt-ignis package
15
- const screenshotReportSetup = fileURLToPath(new URL('../utils/screenshot.ts', import.meta.url))
16
- const externalPlaywrightSetup = fileURLToPath(new URL('../utils/playwright.ts', import.meta.url))
17
-
18
- // external Playwright instance (if configured)
19
- const externalPlaywright = process.env.NUXT_SPEC_EXTERNAL_PLAYWRIGHT
20
-
21
- export async function loadVitestConfig(userVitestConfig, projects = true) {
22
- const baseConfig = {
23
- test: {
24
- // filter-out unnecessary console logs coming from Vitest
25
- // when the import is resolved, unnecessary stderr logs are also filtered-out
26
- // as a side-effect
27
- onConsoleLog,
28
- // Vitest defaults to 5 which might be unnecessarily restrictive
29
- // if the host machine can support more
30
- maxConcurrency: availableParallelism() / 2,
31
- },
32
- }
33
-
34
- // add proposed projects settings
35
- // user can control the inclusion via `projects: ProjectsConfig` config object
36
- // projects are included by default unless not explicitly disabled
37
- if (projects !== false) {
38
- baseConfig.test.projects = []
39
-
40
- // default fallback to catch tests directly in /test folder
41
- if (projects.default !== false) {
42
- baseConfig.test.projects.push({
43
- extends: true,
44
- test: {
45
- name: 'default',
46
- include: ['{test,tests}/**/*.{test,spec}.ts', '!test/{browser,e2e,nuxt,unit}/**'],
47
- environment: 'node',
48
- },
49
- })
50
- }
51
-
52
- // proposed setup for Unit tests
53
- if (projects.unit !== false) {
54
- baseConfig.test.projects.push({
55
- extends: true,
56
- test: {
57
- name: 'unit',
58
- include: ['test/unit/**/*.{test,spec}.ts'],
59
- environment: 'node',
60
- },
61
- })
62
- }
63
-
64
- // proposed setup for Nuxt component tests
65
- if (projects.nuxt !== false) {
66
- baseConfig.test.projects.push(
67
- await defineVitestProject({
68
- extends: true,
69
- test: {
70
- name: 'nuxt',
71
- include: ['test/nuxt/**/*.{test,spec}.ts'],
72
- environment: 'nuxt',
73
- },
74
- }),
75
- )
76
- }
77
-
78
- // proposed setup for classic E2E tests (node-based, using @nuxt/test-utils)
79
- if (projects.e2e !== false) {
80
- baseConfig.test.projects.push({
81
- extends: true,
82
- test: {
83
- name: 'e2e',
84
- include: ['test/e2e/**/*.{test,spec}.ts'],
85
- environment: 'node',
86
- // create report file for visual regression testing
87
- globalSetup: [screenshotReportSetup],
88
- // allows connecting to an external Playwright instance,
89
- // if NUXT_SPEC_EXTERNAL_PLAYWRIGHT is set
90
- setupFiles: externalPlaywright ? [externalPlaywrightSetup] : [],
91
- },
92
- })
93
- }
94
-
95
- // proposed setup for browser component tests (with Playwright runner)
96
- if (projects.browser !== false) {
97
- // allows connecting to an external Playwright instance,
98
- // if NUXT_SPEC_EXTERNAL_PLAYWRIGHT is set
99
- const playwrightConfig = {}
100
- if (externalPlaywright) {
101
- console.log(`[Nuxt Spec - browser] Using external Playwright instance at: ${externalPlaywright}`)
102
- playwrightConfig.connectOptions = {
103
- wsEndpoint: externalPlaywright,
104
- // this allows reaching caller's localhost from within the external Playwright
105
- exposeNetwork: '<loopback>',
106
- }
107
- }
108
- baseConfig.test.projects.push({
109
- extends: true,
110
- // vue plugin is required for proper imports resolution
111
- plugins: [vue()],
112
- test: {
113
- name: 'browser',
114
- include: ['test/browser/**/*.{test,spec}.ts'],
115
- environment: 'node',
116
- // only chromium browser by default - add others manually if needed
117
- browser: {
118
- provider: playwright(playwrightConfig),
119
- enabled: true,
120
- headless: true,
121
- instances: [{
122
- browser: 'chromium',
123
- viewport: { width: 1280, height: 720 },
124
- }],
125
- },
126
- },
127
- })
128
- }
129
- }
130
-
131
- return mergeConfig(userVitestConfig, defineConfig(baseConfig))
132
- }
1
+ // this is the default Vitest config object
2
+ // based on https://nuxt.com/docs/4.x/getting-started/testing#setup
3
+ // `projects=false` can be used to suspend the default usage of "projects" in Vitest config
4
+
5
+ import { availableParallelism } from 'node:os'
6
+ import { fileURLToPath } from 'node:url'
7
+ import { addMessageFilters, onConsoleLog } from './utils/warnings.mjs' // filter out unnecessary logs
8
+ import { mergeConfig } from './utils/merge.mjs' // defu-based merge function
9
+ import { loadSpecOptions } from './utils/options.mjs' // `spec` key from nuxt.config.ts + NUXT_SPEC_* env variables
10
+ import { nuxtSpecReportPlugin } from './utils/reporter.mjs' // HTML test report
11
+ import { defineConfig } from 'vitest/config'
12
+ import { defineVitestProject } from '@nuxt/test-utils/config'
13
+ import { playwright } from '@vitest/browser-playwright'
14
+ import vue from '@vitejs/plugin-vue'
15
+
16
+ // absolute paths so it works from within the nuxt-ignis package
17
+ const externalPlaywrightSetup = fileURLToPath(new URL('../utils/playwright.ts', import.meta.url))
18
+
19
+ export async function loadVitestConfig(userVitestConfig, projects = true) {
20
+ const { externalPlaywright, htmlReport, messageFilters } = await loadSpecOptions()
21
+
22
+ // extend array of messages that will be filtered out from the output
23
+ // with values passed by the user (if any)
24
+ addMessageFilters(messageFilters)
25
+
26
+ const baseConfig = {
27
+ test: {
28
+ // filter-out unnecessary console logs coming from Vitest
29
+ // when the import is resolved, unnecessary stderr logs are also filtered-out
30
+ // as a side-effect
31
+ onConsoleLog,
32
+ // Vitest defaults to 5 which might be unnecessarily restrictive
33
+ // if the host machine can support more
34
+ maxConcurrency: availableParallelism() / 2,
35
+ },
36
+ }
37
+
38
+ // HTML test report for all projects
39
+ // report is generated unless explicitly disabled
40
+ if (htmlReport.enabled) {
41
+ baseConfig.plugins = [nuxtSpecReportPlugin({ open: htmlReport.open })]
42
+ }
43
+
44
+ // add proposed projects settings
45
+ // user can control the inclusion via `projects: ProjectsConfig` config object
46
+ // projects are included by default unless explicitly disabled
47
+ if (projects !== false) {
48
+ baseConfig.test.projects = []
49
+
50
+ // default fallback to catch tests directly in /test folder
51
+ if (projects.default !== false) {
52
+ baseConfig.test.projects.push({
53
+ extends: true,
54
+ test: {
55
+ name: 'default',
56
+ include: ['{test,tests}/**/*.{test,spec}.ts', '!test/{browser,e2e,nuxt,unit}/**'],
57
+ environment: 'node',
58
+ },
59
+ })
60
+ }
61
+
62
+ // proposed setup for Unit tests
63
+ if (projects.unit !== false) {
64
+ baseConfig.test.projects.push({
65
+ extends: true,
66
+ test: {
67
+ name: 'unit',
68
+ include: ['test/unit/**/*.{test,spec}.ts'],
69
+ environment: 'node',
70
+ },
71
+ })
72
+ }
73
+
74
+ // proposed setup for Nuxt component tests
75
+ if (projects.nuxt !== false) {
76
+ baseConfig.test.projects.push(
77
+ await defineVitestProject({
78
+ extends: true,
79
+ test: {
80
+ name: 'nuxt',
81
+ include: ['test/nuxt/**/*.{test,spec}.ts'],
82
+ environment: 'nuxt',
83
+ },
84
+ }),
85
+ )
86
+ }
87
+
88
+ // proposed setup for classic E2E tests (node-based, using @nuxt/test-utils)
89
+ if (projects.e2e !== false) {
90
+ baseConfig.test.projects.push({
91
+ extends: true,
92
+ test: {
93
+ name: 'e2e',
94
+ include: ['test/e2e/**/*.{test,spec}.ts'],
95
+ environment: 'node',
96
+ // allows connecting to an external Playwright instance (if configured)
97
+ setupFiles: externalPlaywright ? [externalPlaywrightSetup] : [],
98
+ // setup file will just read the value via `inject()`
99
+ provide: externalPlaywright ? { nuxtSpecExternalPlaywright: externalPlaywright } : {},
100
+ },
101
+ })
102
+ }
103
+
104
+ // proposed setup for browser component tests (with Playwright runner)
105
+ if (projects.browser !== false) {
106
+ // allows connecting to an external Playwright instance (if configured)
107
+ const playwrightConfig = {}
108
+ if (externalPlaywright) {
109
+ console.log(`[Nuxt Spec] Using external Playwright instance for browser tests at: ${externalPlaywright}`)
110
+ playwrightConfig.connectOptions = {
111
+ wsEndpoint: externalPlaywright,
112
+ // this allows reaching caller's localhost from within the external Playwright
113
+ exposeNetwork: '<loopback>',
114
+ }
115
+ }
116
+ baseConfig.test.projects.push({
117
+ extends: true,
118
+ // vue plugin is required for proper imports resolution
119
+ plugins: [vue()],
120
+ test: {
121
+ name: 'browser',
122
+ include: ['test/browser/**/*.{test,spec}.ts'],
123
+ environment: 'node',
124
+ // only chromium browser by default - add others manually if needed
125
+ browser: {
126
+ provider: playwright(playwrightConfig),
127
+ enabled: true,
128
+ headless: true,
129
+ instances: [{
130
+ browser: 'chromium',
131
+ viewport: { width: 1280, height: 720 },
132
+ }],
133
+ },
134
+ },
135
+ })
136
+ }
137
+ }
138
+
139
+ return mergeConfig(userVitestConfig, defineConfig(baseConfig))
140
+ }
@@ -0,0 +1,6 @@
1
+ <div class="failure">
2
+ <h2>{{TITLE}}</h2>
3
+ <p class="location">{{LOCATION}}</p>
4
+ {{ERRORS}}
5
+ {{SCREENSHOTS}}
6
+ </div>
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Nuxt Spec Test Report - {{TIMESTAMP}}</title>
6
+ <style>
7
+ body { font-family: system-ui, sans-serif; margin: 2rem; background: #f5f5f5; color: #222; }
8
+ h1 { font-size: 1.4rem; }
9
+ .summary { font-weight: 700; font-size: 18px; }
10
+ .summary.passed { color: #0b0; }
11
+ .summary.failed { color: #b00; }
12
+ .failure { background: #fff; border: 1px solid #ddd; border-radius: 8px; padding: 1rem; margin: 1rem 0; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }
13
+ .failure h2 { font-size: 1rem; margin: 0 0 .25rem; }
14
+ .failure .location { color: #666; font-size: .8rem; margin: 0 0 .75rem; }
15
+ .failure pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; margin: 0 0 .75rem; padding: .5rem; background: #fafafa; border: 1px solid #eee; border-radius: 4px; }
16
+ .failure pre.message { color: #b00; }
17
+ .failure details summary { cursor: pointer; font-size: .8rem; margin-bottom: .25rem; }
18
+ .screenshot { margin-top: .75rem; }
19
+ .screenshot h3 { font-size: .9rem; margin: 0 0 .25rem; }
20
+ .screenshot .message { color: #b00; font-size: .85rem; margin: 0 0 .75rem; }
21
+ .pair { display: flex; gap: 1rem; flex-wrap: wrap; }
22
+ .pair figure { margin: 0; flex: 1 1 0; min-width: 240px; }
23
+ .pair figcaption { font-size: .8rem; margin-bottom: .25rem; font-weight: bold; }
24
+ .pair figure:first-child figcaption { color: #0b0; }
25
+ .pair figure:last-child figcaption { color: #b00; }
26
+ .pair img { max-width: 100%; background: #fff; }
27
+ .pair figure:first-child img { border: 2px solid #0b0; }
28
+ .pair figure:last-child img { border: 2px solid #b00; }
29
+ </style>
30
+ </head>
31
+ <body>
32
+ <h1>Nuxt Spec Test Report - {{TIMESTAMP}}</h1>
33
+ <p class="summary {{STATUS}}">{{SUMMARY}}</p>
34
+ <!-- BEGIN failure entries -->
@@ -1,8 +1,8 @@
1
- <div class="failure">
2
- <h2>{{FILE_NAME}}</h2>
3
- <p class="message">{{MESSAGE}}</p>
4
- <div class="pair">
5
- <figure><figcaption>Baseline image</figcaption><img src="{{BASELINE_URI}}" alt="Baseline image for reference"></figure>
6
- <figure><figcaption>Actual screenshot</figcaption><img src="{{ACTUAL_URI}}" alt="Actual screenshot taken"></figure>
7
- </div>
8
- </div>
1
+ <div class="screenshot">
2
+ <h3>{{FILE_NAME}}</h3>
3
+ <p class="message">{{MESSAGE}}</p>
4
+ <div class="pair">
5
+ <figure><figcaption>Baseline image</figcaption><img src="{{BASELINE_URI}}" alt="Baseline image for reference"></figure>
6
+ <figure><figcaption>Actual screenshot</figcaption><img src="{{ACTUAL_URI}}" alt="Actual screenshot taken"></figure>
7
+ </div>
8
+ </div>
@@ -0,0 +1,4 @@
1
+ <!-- END failure entries -->
2
+ <div>Generated by <a href="https://github.com/AloisSeckar/nuxt-spec">Nuxt Spec</a> @ {{TIMESTAMP}}</div>
3
+ </body>
4
+ </html>
@@ -1,19 +1,19 @@
1
- # settings for Nuxt & pnpm
2
-
3
- # https://pnpm.io/settings/node-modules#shamefullyhoist
4
- # required to handle transitive dependencies
5
- # without having to explicitly declare them
6
- shamefullyHoist: true
7
-
8
- # https://pnpm.io/settings/build#allowbuilds
9
- # pnpm naturally blocks all post-install scripts
10
- # some are required for development, others are not relevant
11
- allowBuilds:
12
- # provides fallback repair of platform-specific Rust native engine
13
- 'unrs-resolver': true
14
- # allows node-gyp build of associated native binaries from local sources
15
- # disabled because it would require an explicit opt-in
16
- '@parcel/watcher': false
17
- # optimization for CLI usage of 'esbuild'
18
- # disabled because its runtime resolves native binaries itself
19
- 'esbuild': false
1
+ # settings for Nuxt & pnpm
2
+
3
+ # https://pnpm.io/settings/node-modules#shamefullyhoist
4
+ # required to handle transitive dependencies
5
+ # without having to explicitly declare them
6
+ shamefullyHoist: true
7
+
8
+ # https://pnpm.io/settings/build#allowbuilds
9
+ # pnpm naturally blocks all post-install scripts
10
+ # some are required for development, others are not relevant
11
+ allowBuilds:
12
+ # provides fallback repair of platform-specific Rust native engine
13
+ 'unrs-resolver': true
14
+ # allows node-gyp build of associated native binaries from local sources
15
+ # disabled because it would require an explicit opt-in
16
+ '@parcel/watcher': false
17
+ # optimization for CLI usage of 'esbuild'
18
+ # disabled because its runtime resolves native binaries itself
19
+ 'esbuild': false